summary history branches tags files
commit:6b023ebf15db769e06c7df0f4eedd1600dbd2107
author:mrmekon
committer:mrmekon
date:Sun Nov 13 20:02:23 2011 -0500
parents:0b88f4bbc7dbd93f754f1817b568c6765f23658f, 8d618add238f2f93d28a7b2ab4b5110d1fcad7cd
Documentation for public API
diff --git a/Makefile.am b/Makefile.am
line changes: +5/-0
index 8b94d94..a909d26
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,11 @@
+SUBDIRS = examples/01_decrypt
+
 pkglib_LTLIBRARIES = libsimplepgp.la
 pkginclude_HEADERS = src/simplepgp.h
 
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = simplepgp.pc
+
 libsimplepgp_la_LDFLAGS = -version-info 0:1:0
 libsimplepgp_la_SOURCES = \
 	src/packet.c \

diff --git a/configure.ac b/configure.ac
line changes: +1/-1
index ecdc723..6bd23d6
--- a/configure.ac
+++ b/configure.ac
@@ -8,7 +8,7 @@ AC_COPYRIGHT(Trevor Bentley 2011)
 
 AC_CONFIG_SRCDIR([src/packet.c])
 AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile simplepgp.pc])
 
 AM_INIT_AUTOMAKE([subdir-objects foreign])
 AC_PROG_LIBTOOL

diff --git a/examples/01_decrypt/Makefile b/examples/01_decrypt/Makefile
line changes: +9/-0
index 0000000..46899cc
--- /dev/null
+++ b/examples/01_decrypt/Makefile
@@ -0,0 +1,9 @@
+LDFLAGS=`pkg-config --libs simplepgp`
+CFLAGS=`pkg-config --cflags simplepgp`
+
+EXEC=decrypt
+OBJS=decrypt.c
+
+default: $(EXEC)
+
+all: default 
\ No newline at end of file

diff --git a/examples/01_decrypt/ciphertext.pgp b/examples/01_decrypt/ciphertext.pgp
line changes: +0/-0
index 0000000..0c764d6
--- /dev/null
+++ b/examples/01_decrypt/ciphertext.pgp

diff --git a/examples/01_decrypt/decrypt.c b/examples/01_decrypt/decrypt.c
line changes: +62/-0
index 0000000..f78b0f6
--- /dev/null
+++ b/examples/01_decrypt/decrypt.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include <simplepgp.h>
+
+#define SECKEY_BUF 2048
+#define CTEXT_BUF 1024
+
+#define KEY_PASS "test"
+
+int main(int argc, char **argv) {
+  char seckey[SECKEY_BUF];
+  char ctext[CTEXT_BUF];
+  int fd;
+  int seckey_len, ctext_len;
+  spgp_packet_t *pkt;
+
+  printf("simplepgp decrypt example.\n");
+
+  fd = open("test1_sec.pgp", O_RDONLY);
+  if (fd < 0) { perror("seckey open"); return 1; }
+  if ((seckey_len = read(fd, seckey, SECKEY_BUF)) < 0) {
+    perror("seckey read"); return 1;
+  }
+  close(fd);
+
+  fd = open("ciphertext.pgp", O_RDONLY);
+  if (fd < 0) { perror("cipher open"); return 1; }
+  if ((ctext_len = read(fd, ctext, CTEXT_BUF)) < 0) {
+    perror("cipher read"); return 1;
+  }
+  close(fd);
+
+  if (spgp_init() != 0) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  spgp_debug_log_set(1);
+
+  pkt = spgp_decode_message(seckey, seckey_len);
+  if (NULL == pkt) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  if (spgp_decrypt_all_secret_keys(pkt, KEY_PASS, strlen(KEY_PASS)) != 0) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  pkt = spgp_decode_message(ctext, ctext_len);
+  if (NULL == pkt) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  spgp_close();
+
+  return 0;
+}

diff --git a/examples/01_decrypt/test1_sec.pgp b/examples/01_decrypt/test1_sec.pgp
line changes: +0/-0
index 0000000..524a4e4
--- /dev/null
+++ b/examples/01_decrypt/test1_sec.pgp

diff --git a/simplepgp.pc.in b/simplepgp.pc.in
line changes: +13/-0
index 0000000..1a31a99
--- /dev/null
+++ b/simplepgp.pc.in
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libsimplepgp
+Description: Simple implementation of OpenPGP
+Requires.private: zlib
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir}/simplepgp -lsimplepgp
+Libs.private: `libgcrypt-config --libs` `gpg-error-config --libs`
+Cflags: -I${includedir}/simplepgp
+Cflags.private: `libgcrypt-config --cflags` `gpg-error-config --cflags`