Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/agc-netpgp-standalone]: src/crypto/external/bsd/netpgp/dist/src implemen...



details:   https://anonhg.NetBSD.org/src/rev/33e77e3ffaf5
branches:  agc-netpgp-standalone
changeset: 777813:33e77e3ffaf5
user:      agc <agc%NetBSD.org@localhost>
date:      Sat Oct 20 05:55:42 2012 +0000

description:
implement a new pgpv_get_verified() exported function, which returns the
data and its size to the caller.

implement pgpv_verify_print() in terms of pgpv_get_verified()

diffstat:

 crypto/external/bsd/netpgp/dist/src/libverify/libverify.c |  30 +++++++-------
 crypto/external/bsd/netpgp/dist/src/libverify/verify.h    |   3 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/main.c   |  12 ++++--
 3 files changed, 25 insertions(+), 20 deletions(-)

diffs (112 lines):

diff -r 6ffc9fede7f9 -r 33e77e3ffaf5 crypto/external/bsd/netpgp/dist/src/libverify/libverify.c
--- a/crypto/external/bsd/netpgp/dist/src/libverify/libverify.c Sat Oct 20 04:59:52 2012 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libverify/libverify.c Sat Oct 20 05:55:42 2012 +0000
@@ -2023,6 +2023,7 @@
                if (key_expired(pubkey, cursor->why, sizeof(cursor->why))) {
                        return 0;
                }
+               ARRAY_APPEND(cursor->datacookies, pkt);
                ARRAY_APPEND(cursor->found, primary);
                return 1;
        }
@@ -2040,29 +2041,28 @@
        return read_binary_file(pgp, "pubring", "%s/%s", getenv("HOME"), ".gnupg/pubring.gpg");
 }
 
-/* print verified data to stdout */
-int
-pgpv_verify_print(pgpv_cursor_t *cursor)
+/* get verified data as a string, return its size */
+size_t
+pgpv_get_verified(pgpv_cursor_t *cursor, unsigned ent, char **ret)
 {
        pgpv_litdata_t          *litdata;
        uint8_t                 *data;
-       ssize_t                  wc;
        size_t                   size;
        size_t                   pkt;
-       size_t                   cc;
 
-       /* datastart was setup at the start of pgpv_verify */
-       if ((pkt = find_onepass(cursor, ARRAY_LAST(cursor->pgp->datastarts))) == 0) {
+       *ret = NULL;
+       if (cursor == NULL || ent >= ARRAY_COUNT(cursor->datacookies)) {
                return 0;
        }
-       pkt -= 1;
-       litdata = &ARRAY_ELEMENT(cursor->pgp->pkts, pkt + 1).u.litdata;
+       pkt = ARRAY_ELEMENT(cursor->datacookies, ent);
+       if ((pkt = find_onepass(cursor, pkt)) == 0) {
+               return 0;
+       }
+       litdata = &ARRAY_ELEMENT(cursor->pgp->pkts, pkt).u.litdata;
        data = get_literal_data(cursor, litdata, &size);
-       for (cc = 0 ; cc < size ; cc += (size_t)wc) {
-               if ((wc = write(STDOUT_FILENO, &data[cc], size - cc)) < 0) {
-                       printf("short write\n");
-                       return 0;
-               }
+       if ((*ret = calloc(1, size)) == NULL) {
+               return 0;
        }
-       return 1;
+       memcpy(*ret, data, size);
+       return size;
 }
diff -r 6ffc9fede7f9 -r 33e77e3ffaf5 crypto/external/bsd/netpgp/dist/src/libverify/verify.h
--- a/crypto/external/bsd/netpgp/dist/src/libverify/verify.h    Sat Oct 20 04:59:52 2012 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libverify/verify.h    Sat Oct 20 05:55:42 2012 +0000
@@ -247,6 +247,7 @@
        char                    *value;                 /* value we're searching for */
        void                    *ptr;                   /* for regexps etc */
        PGPV_ARRAY(uint32_t,     found);                /* array of matched subscripts */
+       PGPV_ARRAY(uint32_t,     datacookies);          /* cookies to retrieve matched data */
        int64_t                  sigtime;               /* time of signature */
        char                     why[128];              /* reason for bad signature */
 } pgpv_cursor_t;
@@ -266,7 +267,7 @@
 int pgpv_read_pubring(pgpv_t */*pgp*/, const char */*keyring*/);
 
 int pgpv_verify(pgpv_cursor_t */*cursor*/, pgpv_t */*pgp*/, const void */*mem/file*/, ssize_t /*size*/);
-int pgpv_verify_print(pgpv_cursor_t */*cursor*/);
+size_t pgpv_get_verified(pgpv_cursor_t */*cursor*/, unsigned /*ent*/, char **/*ret*/);
 
 size_t pgpv_get_entry(pgpv_t */*pgp*/, unsigned /*ent*/, char **/*ret*/);
 
diff -r 6ffc9fede7f9 -r 33e77e3ffaf5 crypto/external/bsd/netpgp/dist/src/netpgpverify/main.c
--- a/crypto/external/bsd/netpgp/dist/src/netpgpverify/main.c   Sat Oct 20 04:59:52 2012 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/netpgpverify/main.c   Sat Oct 20 05:55:42 2012 +0000
@@ -87,14 +87,18 @@
 
 /* verify memory or file */
 static int
-verify_data(pgpv_t *pgp, const char *cmd, const char *inname, char *in, size_t cc)
+verify_data(pgpv_t *pgp, const char *cmd, const char *inname, char *in, size_t cc, unsigned n)
 {
        pgpv_cursor_t    cursor;
+       size_t           size;
+       char            *data;
 
        memset(&cursor, 0x0, sizeof(cursor));
        if (strcasecmp(cmd, "cat") == 0) {
                if (pgpv_verify(&cursor, pgp, in, cc)) {
-                       pgpv_verify_print(&cursor);
+                       if ((size = pgpv_get_verified(&cursor, ARRAY_ELEMENT(cursor.datacookies, n), &data)) > 0) {
+                               printf("%.*s", (int)size, data);
+                       }
                        return 1;
                }
        } else if (strcasecmp(cmd, "verify") == 0) {
@@ -147,10 +151,10 @@
        }
        if (optind == argc) {
                in = getstdin(&cc, &size);
-               ok = verify_data(&pgp, cmd, "[stdin]", in, cc);
+               ok = verify_data(&pgp, cmd, "[stdin]", in, cc, 0);
        } else {
                for (ok = 1, i = optind ; i < argc ; i++) {
-                       if (!verify_data(&pgp, cmd, argv[i], argv[i], -1)) {
+                       if (!verify_data(&pgp, cmd, argv[i], argv[i], -1, i)) {
                                ok = 0;
                        }
                }



Home | Main Index | Thread Index | Old Index