[svn] gcry - r1448 - in trunk: cipher random src

svn author wk cvs at cvs.gnupg.org
Thu Nov 4 15:56:18 CET 2010


Author: wk
Date: 2010-11-04 15:56:17 +0100 (Thu, 04 Nov 2010)
New Revision: 1448

Modified:
   trunk/cipher/pubkey.c
   trunk/random/random.c
   trunk/src/dumpsexp.c
   trunk/src/global.c
Log:
Doc fixes.
Started some work on dumpsexp.


Modified: trunk/cipher/pubkey.c
===================================================================
--- trunk/cipher/pubkey.c	2010-10-18 10:12:23 UTC (rev 1447)
+++ trunk/cipher/pubkey.c	2010-11-04 14:56:17 UTC (rev 1448)
@@ -2503,8 +2503,8 @@
         care or a combination of the GCRY_PK_USAGE_xxx flags;
 
     GCRYCTL_GET_ALGO_USAGE:
-        Return the usage glafs for the give algo.  An invalid alog
-        does return 0.  Disabled algos are ignored here because we
+        Return the usage flags for the given algo.  An invalid algo
+        returns 0.  Disabled algos are ignored here because we
         only want to know whether the algo is at all capable of
         the usage.
   

Modified: trunk/random/random.c
===================================================================
--- trunk/random/random.c	2010-10-18 10:12:23 UTC (rev 1447)
+++ trunk/random/random.c	2010-11-04 14:56:17 UTC (rev 1448)
@@ -92,14 +92,14 @@
 }
 
 
-/* This function should be called during initialization and beore
+/* This function should be called during initialization and before
    initialization of this module to place the random pools into secure
    memory.  */
 void
 _gcry_secure_random_alloc (void)
 {
   if (fips_mode ())
-    ;  /* Not used; the fips rng is allows in secure mode.  */
+    ;  /* Not used; the FIPS RNG is always in secure mode.  */
   else
     _gcry_rngcsprng_secure_alloc ();
 }

Modified: trunk/src/dumpsexp.c
===================================================================
--- trunk/src/dumpsexp.c	2010-10-18 10:12:23 UTC (rev 1447)
+++ trunk/src/dumpsexp.c	2010-11-04 14:56:17 UTC (rev 1448)
@@ -1,12 +1,12 @@
 /* dumpsexp.c - Dump S-expressions.
- * Copyright (C) 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2007, 2010 Free Software Foundation, Inc.
  *
- * Getrandom is free software; you can redistribute it and/or modify
+ * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
+ * by the Free Software Foundation; either version 3 of the License,
  * or (at your option) any later version.
  *
- * Getrandom is distributed in the hope that it will be useful, but
+ * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
@@ -36,14 +36,15 @@
 static int verbose;  /* Verbose mode.  */
 static int decimal;  /* Print addresses in decimal.  */
 static int assume_hex;  /* Assume input is hexencoded.  */
+static int advanced; /* Advanced format output.  */
 
 static void
 print_version (int with_help)
 {
   fputs (MYVERSION_LINE "\n"
-         "Copyright (C) 2007 Free Software Foundation, Inc.\n"
-         "License GPLv2+: GNU GPL version 2 or later "
-         "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
+         "Copyright (C) 2010 Free Software Foundation, Inc.\n"
+         "License GPLv3+: GNU GPL version 3 or later "
+         "<http://gnu.org/licenses/gpl.html>\n"
          "This is free software: you are free to change and redistribute it.\n"
          "There is NO WARRANTY, to the extent permitted by law.\n",
          stdout);
@@ -55,6 +56,7 @@
            "\n"
            "  --decimal     Print offsets using decimal notation\n"
            "  --assume-hex  Assume input is a hex dump\n"
+           "  --advanced    Print file in advanced format\n"
            "  --verbose     Show what we are doing\n"
            "  --version     Print version of the program and exit\n"
            "  --help        Display this help and exit\n"
@@ -258,7 +260,7 @@
 static void 
 printctl (const char *text)
 {
-  if (verbose)
+  if (verbose && !advanced)
     {
       printcursor (0);
       printf ("%s\n", text);
@@ -268,19 +270,125 @@
 static void 
 printchr (int c)
 {
-  (void)c;
+  putchar (c);
 }
 
 static void
 printhex (int c)
 {
-  (void)c;
+  printf ("\\x%02x", c);
 }
 
 
+#if 0
+/****************
+ * Print SEXP to buffer using the MODE.  Returns the length of the
+ * SEXP in buffer or 0 if the buffer is too short (We have at least an
+ * empty list consisting of 2 bytes).  If a buffer of NULL is provided,
+ * the required length is returned.
+ */
+size_t
+gcry_sexp_sprint (const gcry_sexp_t list,
+                  void *buffer, size_t maxlength )
+{
+  static unsigned char empty[3] = { ST_OPEN, ST_CLOSE, ST_STOP };
+  const unsigned char *s;
+  char *d;
+  DATALEN n;
+  char numbuf[20];
+  int i, indent = 0;
+  
+  s = list? list->d : empty;
+  d = buffer;
+  while ( *s != ST_STOP )
+    {
+      switch ( *s )
+        {
+        case ST_OPEN:
+          s++;
+          if (indent)
+            putchar ('\n'); 
+          for (i=0; i < indent; i++)
+            putchar (' ');
+          putchar ('(');
+          indent++;
+          break;
+        case ST_CLOSE:
+          s++;
+          putchar (')');
+          indent--;
+          if (*s != ST_OPEN && *s != ST_STOP)
+            {
+              putchar ('\n');
+              for (i=0; i < indent; i++)
+                putchar (' ');
+            }
+          break;
+        case ST_DATA:
+          s++;
+          memcpy (&n, s, sizeof n);
+          s += sizeof n;
+          {
+            int type;
+            size_t nn;
+            
+            switch ( (type=suitable_encoding (s, n)))
+              {
+              case 1: nn = convert_to_string (s, n, NULL); break;
+              case 2: nn = convert_to_token (s, n, NULL); break;
+              default: nn = convert_to_hex (s, n, NULL); break;
+              }
+            switch (type)
+              {
+              case 1: convert_to_string (s, n, d); break;
+              case 2: convert_to_token (s, n, d); break;
+              default: convert_to_hex (s, n, d); break;
+              }
+            d += nn;
+            if (s[n] != ST_CLOSE)
+              putchar (' ');
+          }
+          else
+            {
+              snprintf (numbuf, sizeof numbuf,  "%u:", (unsigned int)n );
+              d = stpcpy (d, numbuf);
+              memcpy (d, s, n);
+              d += n;
+            }
+          s += n;
+          break;
+        default:
+          BUG ();
+	}
+    }
+  putchar ('\n'); 
+  return len;
+}
+#endif
 
 
+/* Prepare for saving a chunk of data.  */
+static void
+init_data (void)
+{
 
+}
+
+/* Push C on the current data chunk.  */
+static void
+push_data (int c)
+{
+
+}
+
+/* Flush and thus print the current data chunk.  */
+static void
+flush_data (void)
+{
+
+}
+
+
 /* Returns 0 on success.  */
 static int
 parse_and_print (FILE *fp)
@@ -346,17 +454,20 @@
             {
               state = IN_STRING;
               printctl ("beginstring");
+              init_data ();
             }
           else if (c == '#')
             {
               state = IN_HEXFMT;
               hexcount = 0;
               printctl ("beginhex");
+              init_data ();
             }
           else if (c == '|')
             {
               state = IN_BASE64;
               printctl ("beginbase64");
+              init_data ();
             }
           else if (c == '[')
             {
@@ -434,16 +545,18 @@
         case PRE_DATA:
           state = IN_DATA;
           printctl ("begindata");
+          init_data ();
         case IN_DATA:
           if (datalen)
             {
-              printhex (c);
+              push_data (c);
               datalen--;
             }
           if (!datalen)
             {
               state = INIT_STATE;
               printctl ("enddata");
+              flush_data ();
             }
           break;
 
@@ -451,22 +564,27 @@
           if (c == '\"')
             {
               printctl ("endstring");
+              flush_data ();
               state = INIT_STATE;
             } 
           else if (c == '\\')
             state = IN_ESCAPE;
           else
-            printchr (c);
+            push_data (c);
           break;
 
         case IN_ESCAPE:
           switch (c)
             {
-            case 'b': case 't': case 'v': case 'n': case 'f':
-            case 'r': case '"': case '\'': case '\\':
-              printhex (c);
-              state = IN_STRING;
-              break;
+            case 'b':  push_data ('\b'); state = IN_STRING; break;
+            case 't':  push_data ('\t'); state = IN_STRING; break;
+            case 'v':  push_data ('\v'); state = IN_STRING; break;
+            case 'n':  push_data ('\n'); state = IN_STRING; break;
+            case 'f':  push_data ('\f'); state = IN_STRING; break;
+            case 'r':  push_data ('\r'); state = IN_STRING; break;
+            case '"':  push_data ('"');  state = IN_STRING; break;
+            case '\'': push_data ('\''); state = IN_STRING; break;
+            case '\\': push_data ('\\'); state = IN_STRING; break;
               
             case '0': case '1': case '2': case '3': case '4':
             case '5': case '6': case '7':
@@ -501,9 +619,9 @@
               quote_buf[quote_idx++] = c; 
               if (quote_idx == 3)
                 {
-                  printchr ((unsigned int)quote_buf[0] * 8 * 8
-                            + (unsigned int)quote_buf[1] * 8
-                            + (unsigned int)quote_buf[2]);
+                  push_data ((unsigned int)quote_buf[0] * 8 * 8
+                             + (unsigned int)quote_buf[1] * 8
+                             + (unsigned int)quote_buf[2]);
                   state = IN_STRING;
                 }
             }
@@ -516,9 +634,8 @@
               quote_buf[quote_idx++] = c; 
               if (quote_idx == 2)
                 {
-                  printchr (xtoi_1 (quote_buf[0]) * 16
-                            + xtoi_1 (quote_buf[1]));
-
+                  push_data (xtoi_1 (quote_buf[0]) * 16
+                             + xtoi_1 (quote_buf[1]));
                   state = IN_STRING;
                 }
             }
@@ -535,7 +652,7 @@
         case IN_HEXFMT:
           if (hexdigit_p (c))
             {
-              printchr (c);
+              push_data (c);
               hexcount++;
             }
           else if (c == '#')
@@ -543,6 +660,7 @@
               if ((hexcount & 1))
                 printerr ("odd number of hex digits");
               printctl ("endhex");
+              flush_data ();
               state = INIT_STATE;
             }
           else if (!whitespace_p (c))
@@ -553,10 +671,11 @@
           if (c == '|')
             {
               printctl ("endbase64");
+              flush_data ();
               state = INIT_STATE;
             }
           else
-            printchr (c);
+            push_data (c);
           break;
 
         default:
@@ -610,6 +729,11 @@
           argc--; argv++;
           assume_hex = 1;
         }
+      else if (!strcmp (*argv, "--advanced"))
+        {
+          argc--; argv++;
+          advanced = 1;
+        }
       else
         print_usage ();
     }          

Modified: trunk/src/global.c
===================================================================
--- trunk/src/global.c	2010-10-18 10:12:23 UTC (rev 1447)
+++ trunk/src/global.c	2010-11-04 14:56:17 UTC (rev 1448)
@@ -501,7 +501,7 @@
     case GCRYCTL_FORCE_FIPS_MODE:
       /* Performing this command puts the library into fips mode.  If
          the library has already been initialized into fips mode, a
-         selftest is triggered.  it is not possible to put the libraty
+         selftest is triggered.  It is not possible to put the libraty
          into fips mode after having passed the initialization. */
       if (!any_init_done)
         {





More information about the Gnupg-commits mailing list