summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2010-11-04 14:56:17 +0000
committerWerner Koch <wk@gnupg.org>2010-11-04 14:56:17 +0000
commit915570db198f2cf15db5c034096a444a8a79476e (patch)
tree6f37097f23505deba7a384cb5f946350b4409231
parentf34e11b10099371e861fa417c8336d26c24ad578 (diff)
downloadlibgcrypt-915570db198f2cf15db5c034096a444a8a79476e.tar.gz
Doc fixes.
Started some work on dumpsexp.
-rw-r--r--cipher/pubkey.c4
-rw-r--r--random/random.c4
-rw-r--r--src/dumpsexp.c174
-rw-r--r--src/global.c2
4 files changed, 154 insertions, 30 deletions
diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index a6b917b7..86693e8e 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -2503,8 +2503,8 @@ gcry_pk_ctl (int cmd, void *buffer, size_t buflen)
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.
diff --git a/random/random.c b/random/random.c
index 84683378..8465abbd 100644
--- a/random/random.c
+++ b/random/random.c
@@ -92,14 +92,14 @@ _gcry_random_dump_stats (void)
}
-/* 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 ();
}
diff --git a/src/dumpsexp.c b/src/dumpsexp.c
index 920c0485..d93cd676 100644
--- a/src/dumpsexp.c
+++ b/src/dumpsexp.c
@@ -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 @@ print_version (int with_help)
"\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 @@ printerr (const char *text)
static void
printctl (const char *text)
{
- if (verbose)
+ if (verbose && !advanced)
{
printcursor (0);
printf ("%s\n", text);
@@ -268,18 +270,124 @@ printctl (const char *text)
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
@@ -346,17 +454,20 @@ parse_and_print (FILE *fp)
{
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 @@ parse_and_print (FILE *fp)
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 @@ parse_and_print (FILE *fp)
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 @@ parse_and_print (FILE *fp)
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 @@ parse_and_print (FILE *fp)
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 @@ parse_and_print (FILE *fp)
case IN_HEXFMT:
if (hexdigit_p (c))
{
- printchr (c);
+ push_data (c);
hexcount++;
}
else if (c == '#')
@@ -543,6 +660,7 @@ parse_and_print (FILE *fp)
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 @@ parse_and_print (FILE *fp)
if (c == '|')
{
printctl ("endbase64");
+ flush_data ();
state = INIT_STATE;
}
else
- printchr (c);
+ push_data (c);
break;
default:
@@ -610,6 +729,11 @@ main (int argc, char **argv)
argc--; argv++;
assume_hex = 1;
}
+ else if (!strcmp (*argv, "--advanced"))
+ {
+ argc--; argv++;
+ advanced = 1;
+ }
else
print_usage ();
}
diff --git a/src/global.c b/src/global.c
index c457b1e4..2944b2c5 100644
--- a/src/global.c
+++ b/src/global.c
@@ -501,7 +501,7 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr)
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)
{