summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/examples
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp-ffi/examples')
-rw-r--r--openpgp-ffi/examples/.gitignore1
-rw-r--r--openpgp-ffi/examples/Makefile2
-rw-r--r--openpgp-ffi/examples/type-safety-demo.c28
3 files changed, 30 insertions, 1 deletions
diff --git a/openpgp-ffi/examples/.gitignore b/openpgp-ffi/examples/.gitignore
index 6a47c497..c1833f90 100644
--- a/openpgp-ffi/examples/.gitignore
+++ b/openpgp-ffi/examples/.gitignore
@@ -3,3 +3,4 @@ encrypt-for
example
parser
reader
+type-safety-demo
diff --git a/openpgp-ffi/examples/Makefile b/openpgp-ffi/examples/Makefile
index 29408634..d935ea52 100644
--- a/openpgp-ffi/examples/Makefile
+++ b/openpgp-ffi/examples/Makefile
@@ -5,7 +5,7 @@ CARGO_TARGET_DIR ?= $(shell pwd)/../../target
# We currently only support absolute paths.
CARGO_TARGET_DIR := $(abspath $(CARGO_TARGET_DIR))
-TARGETS = example reader parser encrypt-for armor
+TARGETS = example reader parser encrypt-for armor type-safety-demo
CFLAGS = -I../include -O0 -g -Wall -Werror
LDFLAGS = -L$(CARGO_TARGET_DIR)/debug -lsequoia_openpgp_ffi
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;
+}