cvs-cvs
[Top][All Lists]
Advanced

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

[Cvs-cvs] ccvs/src ChangeLog gpg.c [signed-commits3]


From: Derek Robert Price
Subject: [Cvs-cvs] ccvs/src ChangeLog gpg.c [signed-commits3]
Date: Fri, 30 Dec 2005 16:07:31 +0000

CVSROOT:        /cvsroot/cvs
Module name:    ccvs
Branch:         signed-commits3
Changes by:     Derek Robert Price <address@hidden>     05/12/30 16:07:31

Modified files:
        src            : ChangeLog gpg.c 

Log message:
        * gpg.c: Include <stdint.h>.
        (parse_header): New function factored from...
        (read_signature): ...here.
        (struct openpgp_signature): New decl.
        (parse_signature): New function.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/src/ChangeLog.diff?only_with_tag=signed-commits3&tr1=1.3328.2.2&tr2=1.3328.2.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/src/gpg.c.diff?only_with_tag=signed-commits3&tr1=1.1.6.2&tr2=1.1.6.3&r1=text&r2=text

Patches:
Index: ccvs/src/ChangeLog
diff -u ccvs/src/ChangeLog:1.3328.2.2 ccvs/src/ChangeLog:1.3328.2.3
--- ccvs/src/ChangeLog:1.3328.2.2       Tue Dec 27 20:43:35 2005
+++ ccvs/src/ChangeLog  Fri Dec 30 16:07:31 2005
@@ -1,3 +1,11 @@
+2005-12-30  Derek Price  <address@hidden>
+
+       * gpg.c: Include <stdint.h>.
+       (parse_header): New function factored from...
+       (read_signature): ...here.
+       (struct openpgp_signature): New decl.
+       (parse_signature): New function.
+
 2005-12-27  Derek Price  <address@hidden>
 
        * gpg.c (read_u32): New function.
Index: ccvs/src/gpg.c
diff -u ccvs/src/gpg.c:1.1.6.2 ccvs/src/gpg.c:1.1.6.3
--- ccvs/src/gpg.c:1.1.6.2      Tue Dec 27 20:43:35 2005
+++ ccvs/src/gpg.c      Fri Dec 30 16:07:31 2005
@@ -27,9 +27,12 @@
 /* Verify interface.  */
 #include "gpg.h"
 
+/* ANSI C Headers.  */
 #include <assert.h>
+#include <stdint.h>
 #include <string.h>
 
+/* GNULIB Headers.  */
 #include "error.h"
 
 
@@ -198,29 +201,27 @@
 
 
 
-/* Read a single signature packet from BPIN, copying it to BPOUT.
+/* Read a single signature packet header from BPIN.
  *
  * RETURNS
  *   0         On success.
  *   -1                If EOF is encountered before a full packet is read.
  *   -2                On memory allocation errors from buf_read_data().
  *
- * ERRORS
- *   Aside from the error returns above, buf_output() can call its memory
- *   failure function on memory allocation failures, which could exit.
  */
 int
-read_signature (struct buffer *bpin, struct buffer *bpout)
+parse_header (struct buffer *bpin, int *pkttype, unsigned long *pktlen,
+             int *partial, unsigned char *header, int *header_len)
 {
-  int ctb, pkttype;
-  unsigned long pktlen = 0;
-  int partial = 0;
-  unsigned char header[20];
+  int ctb;
   int header_idx = 0;
   int lenbytes;
   int rc;
   unsigned char c;
-  
+
+  *pktlen = 0;
+  *partial = 0;
+
   if ((rc = read_u8 (bpin, &c)))
     return rc;
 
@@ -236,7 +237,7 @@
   if ( (ctb & 0x40) )
     {
       /* new CTB */
-      pkttype =  (ctb & 0x3f);
+      *pkttype =  (ctb & 0x3f);
 
       if ((rc = read_u8 (bpin, &c)))
        return rc;
@@ -244,58 +245,134 @@
       header[header_idx++] = c;
 
       if ( c < 192 )
-        pktlen = c;
+        *pktlen = c;
       else if ( c < 224 )
         {
-          pktlen = (c - 192) * 256;
+          *pktlen = (c - 192) * 256;
          if ((rc = read_u8 (bpin, &c)))
            return rc;
           header[header_idx++] = c;
-          pktlen += c + 192;
+          *pktlen += c + 192;
        }
       else if ( c == 255 ) 
         {
-         if ((rc = read_u32 (bpin, &pktlen)))
+         if ((rc = read_u32 (bpin, pktlen)))
            return rc;
-          header[header_idx++] = pktlen >> 24;
-          header[header_idx++] = pktlen >> 16;
-          header[header_idx++] = pktlen >> 8;
-          header[header_idx++] = pktlen; 
+          header[header_idx++] = *pktlen >> 24;
+          header[header_idx++] = *pktlen >> 16;
+          header[header_idx++] = *pktlen >> 8;
+          header[header_idx++] = *pktlen; 
        }
       else
         { /* partial body length */
-          pktlen = c;
-          partial = 1;
+          *pktlen = c;
+          *partial = 1;
        }
     }
   else
     {
-      pkttype = (ctb>>2)&0xf;
+      *pkttype = (ctb>>2)&0xf;
 
       lenbytes = ((ctb&3)==3)? 0 : (1<<(ctb & 3));
       if (!lenbytes )
        {
-         pktlen = 0; /* don't know the value */
-         partial = 2; /* the old GnuPG partial length encoding */
+         *pktlen = 0; /* don't know the value */
+         *partial = 2; /* the old GnuPG partial length encoding */
        }
       else
        {
          for (; lenbytes; lenbytes--) 
            {
-             pktlen <<= 8;
+             *pktlen <<= 8;
              if ((rc = read_u8 (bpin, &c)))
                return rc;
              header[header_idx++] = c;
              
-             pktlen |= c;
+             *pktlen |= c;
            }
        }
     }
 
+  *header_len = header_idx;
+  return 0;
+}
+
+
+
+/* Read a single signature packet from BPIN, copying it to BPOUT.
+ *
+ * RETURNS
+ *   0         On success.
+ *   -1                If EOF is encountered before a full packet is read.
+ *   -2                On memory allocation errors from buf_read_data().
+ *
+ * ERRORS
+ *   Aside from the error returns above, buf_output() can call its memory
+ *   failure function on memory allocation failures, which could exit.
+ */
+int
+read_signature (struct buffer *bpin, struct buffer *bpout)
+{
+  int pkttype;
+  unsigned long pktlen;
+  int partial;
+  unsigned char header[20];
+  int header_len = sizeof header;
+  int rc;
+
+  if ((rc = parse_header (bpin, &pkttype, &pktlen, &partial, header,
+                         &header_len)))
+    return rc;
+
   if (pkttype != PKT_SIGNATURE)
     error (1, 0, "Inavlid OpenPGP packet type (%s)",
           pkttype_to_string (pkttype));
 
   return write_part (bpin, bpout, pktlen, pkttype, partial,
-                     header, header_idx);
+                     header, header_len);
+}
+
+
+
+struct openpgp_signature
+{
+  uint64_t sigid;
+};
+
+
+
+/* Parse a single signature packet from BPIN, copying it to BPOUT.
+ *
+ * RETURNS
+ *   0         On success.
+ *   -1                If EOF is encountered before a full packet is read.
+ *   -2                On memory allocation errors from buf_read_data().
+ *
+ * ERRORS
+ *   Aside from the error returns above, buf_output() can call its memory
+ *   failure function on memory allocation failures, which could exit.
+ */
+int
+parse_signature (struct buffer *bpin, struct openpgp_signature *sout)
+{
+  int pkttype;
+  unsigned long pktlen;
+  int partial;
+  unsigned char header[20];
+  int header_len = sizeof header;
+  int rc;
+  unsigned char c;
+
+  if ((rc = parse_header (bpin, &pkttype, &pktlen, &partial, header,
+                         &header_len)))
+    return rc;
+
+  if (pkttype != PKT_SIGNATURE)
+    error (1, 0, "Inavlid OpenPGP packet type (%s)",
+          pkttype_to_string (pkttype));
+
+  if ((rc = read_u8 (bpin, &c)))
+    return rc;
+
+  return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]