summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/examples/type-safety-demo.c
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-22 17:54:48 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-25 14:04:26 +0100
commit118a86b0302b4bb35b1f1bbef50b2a042f239384 (patch)
treeb447470674dc3aea5bf6c6d32a17ca62d438e125 /openpgp-ffi/examples/type-safety-demo.c
parent64a7fa27f669b0dd31319a5ebee6ffd0de410336 (diff)
ffi-macros: Check wrapper types at runtime.
- This change adds a tag to the derived wrapper types that identify the type of the wrapped value. - At runtime, we can verify that references to wrapper objects indeed carry the right tag. - Fixes #166.
Diffstat (limited to 'openpgp-ffi/examples/type-safety-demo.c')
-rw-r--r--openpgp-ffi/examples/type-safety-demo.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/openpgp-ffi/examples/type-safety-demo.c b/openpgp-ffi/examples/type-safety-demo.c
new file mode 100644
index 00000000..ad4870e2
--- /dev/null
+++ b/openpgp-ffi/examples/type-safety-demo.c
@@ -0,0 +1,28 @@
+#define _GNU_SOURCE
+#include <errno.h>
+#include <error.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sequoia/openpgp.h>
+
+int
+main (int argc, char **argv)
+{
+ pgp_keyid_t keyid = pgp_keyid_from_hex ("BBBBBBBBBBBBBBBB");
+
+ // Let's violate The Rules and forge a reference!
+ pgp_fingerprint_t fingerprint = (pgp_fingerprint_t) keyid;
+
+ // And use it!
+ printf ("%s", pgp_fingerprint_to_string (fingerprint));
+
+ // Always clean up though.
+ pgp_keyid_free (keyid);
+ return 0;
+}