1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

common: Rename external symbols in name-value.c.

* common/name-value.c, common/name-value.h: Rename symbol prefixes
from "pkc_" to "nvc_" and from "pke_" to "nve_".  Change all callers.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-06-23 12:12:50 +02:00
parent b841a883a2
commit d74d23d860
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 158 additions and 158 deletions

View File

@ -57,12 +57,12 @@ write_extended_private_key (char *fname, estream_t fp,
const void *buf, size_t len) const void *buf, size_t len)
{ {
gpg_error_t err; gpg_error_t err;
pkc_t pk = NULL; nvc_t pk = NULL;
gcry_sexp_t key = NULL; gcry_sexp_t key = NULL;
int remove = 0; int remove = 0;
int line; int line;
err = pkc_parse (&pk, &line, fp); err = nvc_parse (&pk, &line, fp);
if (err) if (err)
{ {
log_error ("error parsing '%s' line %d: %s\n", log_error ("error parsing '%s' line %d: %s\n",
@ -74,7 +74,7 @@ write_extended_private_key (char *fname, estream_t fp,
if (err) if (err)
goto leave; goto leave;
err = pkc_set_private_key (pk, key); err = nvc_set_private_key (pk, key);
if (err) if (err)
goto leave; goto leave;
@ -82,7 +82,7 @@ write_extended_private_key (char *fname, estream_t fp,
if (err) if (err)
goto leave; goto leave;
err = pkc_write (pk, fp); err = nvc_write (pk, fp);
if (err) if (err)
{ {
log_error ("error writing '%s': %s\n", fname, gpg_strerror (err)); log_error ("error writing '%s': %s\n", fname, gpg_strerror (err));
@ -117,7 +117,7 @@ write_extended_private_key (char *fname, estream_t fp,
gnupg_remove (fname); gnupg_remove (fname);
xfree (fname); xfree (fname);
gcry_sexp_release (key); gcry_sexp_release (key);
pkc_release (pk); nvc_release (pk);
return err; return err;
} }
@ -687,10 +687,10 @@ read_key_file (const unsigned char *grip, gcry_sexp_t *result)
if (first != '(') if (first != '(')
{ {
/* Key is in extended format. */ /* Key is in extended format. */
pkc_t pk; nvc_t pk;
int line; int line;
rc = pkc_parse (&pk, &line, fp); rc = nvc_parse (&pk, &line, fp);
es_fclose (fp); es_fclose (fp);
if (rc) if (rc)
@ -698,8 +698,8 @@ read_key_file (const unsigned char *grip, gcry_sexp_t *result)
fname, line, gpg_strerror (rc)); fname, line, gpg_strerror (rc));
else else
{ {
rc = pkc_get_private_key (pk, result); rc = nvc_get_private_key (pk, result);
pkc_release (pk); nvc_release (pk);
if (rc) if (rc)
log_error ("error getting private key from '%s': %s\n", log_error ("error getting private key from '%s': %s\n",
fname, gpg_strerror (rc)); fname, gpg_strerror (rc));

View File

@ -43,17 +43,17 @@
#include "util.h" #include "util.h"
#include "name-value.h" #include "name-value.h"
struct private_key_container struct name_value_container
{ {
struct private_key_entry *first; struct name_value_entry *first;
struct private_key_entry *last; struct name_value_entry *last;
}; };
struct private_key_entry struct name_value_entry
{ {
struct private_key_entry *prev; struct name_value_entry *prev;
struct private_key_entry *next; struct name_value_entry *next;
/* The name. Comments and blank lines have NAME set to NULL. */ /* The name. Comments and blank lines have NAME set to NULL. */
char *name; char *name;
@ -80,15 +80,15 @@ my_error_from_syserror (void)
/* Allocation and deallocation. */ /* Allocation and deallocation. */
/* Allocate a private key container structure. */ /* Allocate a private key container structure. */
pkc_t nvc_t
pkc_new (void) nvc_new (void)
{ {
return xtrycalloc (1, sizeof (struct private_key_container)); return xtrycalloc (1, sizeof (struct name_value_container));
} }
static void static void
pke_release (pke_t entry) nve_release (nve_t entry)
{ {
if (entry == NULL) if (entry == NULL)
return; return;
@ -104,9 +104,9 @@ pke_release (pke_t entry)
/* Release a private key container structure. */ /* Release a private key container structure. */
void void
pkc_release (pkc_t pk) nvc_release (nvc_t pk)
{ {
pke_t e, next; nve_t e, next;
if (pk == NULL) if (pk == NULL)
return; return;
@ -114,7 +114,7 @@ pkc_release (pkc_t pk)
for (e = pk->first; e; e = next) for (e = pk->first; e; e = next)
{ {
next = e->next; next = e->next;
pke_release (e); nve_release (e);
} }
xfree (pk); xfree (pk);
@ -145,7 +145,7 @@ valid_name (const char *name)
/* Makes sure that ENTRY has a RAW_VALUE. */ /* Makes sure that ENTRY has a RAW_VALUE. */
static gpg_error_t static gpg_error_t
assert_raw_value (pke_t entry) assert_raw_value (nve_t entry)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
size_t len, offset; size_t len, offset;
@ -261,7 +261,7 @@ continuation_length (const char *s, int *swallow_ws, const char **start)
/* Makes sure that ENTRY has a VALUE. */ /* Makes sure that ENTRY has a VALUE. */
static gpg_error_t static gpg_error_t
assert_value (pke_t entry) assert_value (nve_t entry)
{ {
size_t len; size_t len;
int swallow_ws; int swallow_ws;
@ -302,7 +302,7 @@ assert_value (pke_t entry)
/* Get the name. */ /* Get the name. */
char * char *
pke_name (pke_t pke) nve_name (nve_t pke)
{ {
return pke->name; return pke->name;
} }
@ -310,7 +310,7 @@ pke_name (pke_t pke)
/* Get the value. */ /* Get the value. */
char * char *
pke_value (pke_t pke) nve_value (nve_t pke)
{ {
if (assert_value (pke)) if (assert_value (pke))
return NULL; return NULL;
@ -326,11 +326,11 @@ pke_value (pke_t pke)
given. If PRESERVE_ORDER is not given, entries with the same name given. If PRESERVE_ORDER is not given, entries with the same name
are grouped. NAME, VALUE and RAW_VALUE is consumed. */ are grouped. NAME, VALUE and RAW_VALUE is consumed. */
static gpg_error_t static gpg_error_t
_pkc_add (pkc_t pk, char *name, char *value, strlist_t raw_value, _nvc_add (nvc_t pk, char *name, char *value, strlist_t raw_value,
int preserve_order) int preserve_order)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
pke_t e; nve_t e;
assert (value || raw_value); assert (value || raw_value);
@ -340,7 +340,7 @@ _pkc_add (pkc_t pk, char *name, char *value, strlist_t raw_value,
goto leave; goto leave;
} }
if (name && ascii_strcasecmp (name, "Key:") == 0 && pkc_lookup (pk, "Key:")) if (name && ascii_strcasecmp (name, "Key:") == 0 && nvc_lookup (pk, "Key:"))
{ {
err = gpg_error (GPG_ERR_INV_NAME); err = gpg_error (GPG_ERR_INV_NAME);
goto leave; goto leave;
@ -359,21 +359,21 @@ _pkc_add (pkc_t pk, char *name, char *value, strlist_t raw_value,
if (pk->first) if (pk->first)
{ {
pke_t last; nve_t last;
if (preserve_order || name == NULL) if (preserve_order || name == NULL)
last = pk->last; last = pk->last;
else else
{ {
/* See if there is already an entry with NAME. */ /* See if there is already an entry with NAME. */
last = pkc_lookup (pk, name); last = nvc_lookup (pk, name);
/* If so, find the last in that block. */ /* If so, find the last in that block. */
if (last) if (last)
{ {
while (last->next) while (last->next)
{ {
pke_t next = last->next; nve_t next = last->next;
if (next->name && ascii_strcasecmp (next->name, name) == 0) if (next->name && ascii_strcasecmp (next->name, name) == 0)
last = next; last = next;
@ -419,7 +419,7 @@ _pkc_add (pkc_t pk, char *name, char *value, strlist_t raw_value,
/* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it /* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it
is not updated but the new entry is appended. */ is not updated but the new entry is appended. */
gpg_error_t gpg_error_t
pkc_add (pkc_t pk, const char *name, const char *value) nvc_add (nvc_t pk, const char *name, const char *value)
{ {
char *k, *v; char *k, *v;
@ -434,7 +434,7 @@ pkc_add (pkc_t pk, const char *name, const char *value)
return my_error_from_syserror (); return my_error_from_syserror ();
} }
return _pkc_add (pk, k, v, NULL, 0); return _nvc_add (pk, k, v, NULL, 0);
} }
@ -442,14 +442,14 @@ pkc_add (pkc_t pk, const char *name, const char *value)
is updated with VALUE. If multiple entries with NAME exist, the is updated with VALUE. If multiple entries with NAME exist, the
first entry is updated. */ first entry is updated. */
gpg_error_t gpg_error_t
pkc_set (pkc_t pk, const char *name, const char *value) nvc_set (nvc_t pk, const char *name, const char *value)
{ {
pke_t e; nve_t e;
if (! valid_name (name)) if (! valid_name (name))
return GPG_ERR_INV_NAME; return GPG_ERR_INV_NAME;
e = pkc_lookup (pk, name); e = nvc_lookup (pk, name);
if (e) if (e)
{ {
char *v; char *v;
@ -468,13 +468,13 @@ pkc_set (pkc_t pk, const char *name, const char *value)
return 0; return 0;
} }
else else
return pkc_add (pk, name, value); return nvc_add (pk, name, value);
} }
/* Delete the given entry from PK. */ /* Delete the given entry from PK. */
void void
pkc_delete (pkc_t pk, pke_t entry) nvc_delete (nvc_t pk, nve_t entry)
{ {
if (entry->prev) if (entry->prev)
entry->prev->next = entry->next; entry->prev->next = entry->next;
@ -486,7 +486,7 @@ pkc_delete (pkc_t pk, pke_t entry)
else else
pk->last = entry->prev; pk->last = entry->prev;
pke_release (entry); nve_release (entry);
} }
@ -494,10 +494,10 @@ pkc_delete (pkc_t pk, pke_t entry)
/* Lookup and iteration. */ /* Lookup and iteration. */
/* Get the first non-comment entry. */ /* Get the first non-comment entry. */
pke_t nve_t
pkc_first (pkc_t pk) nvc_first (nvc_t pk)
{ {
pke_t entry; nve_t entry;
for (entry = pk->first; entry; entry = entry->next) for (entry = pk->first; entry; entry = entry->next)
if (entry->name) if (entry->name)
return entry; return entry;
@ -506,10 +506,10 @@ pkc_first (pkc_t pk)
/* Get the first entry with the given name. */ /* Get the first entry with the given name. */
pke_t nve_t
pkc_lookup (pkc_t pk, const char *name) nvc_lookup (nvc_t pk, const char *name)
{ {
pke_t entry; nve_t entry;
for (entry = pk->first; entry; entry = entry->next) for (entry = pk->first; entry; entry = entry->next)
if (entry->name && ascii_strcasecmp (entry->name, name) == 0) if (entry->name && ascii_strcasecmp (entry->name, name) == 0)
return entry; return entry;
@ -518,8 +518,8 @@ pkc_lookup (pkc_t pk, const char *name)
/* Get the next non-comment entry. */ /* Get the next non-comment entry. */
pke_t nve_t
pke_next (pke_t entry) nve_next (nve_t entry)
{ {
for (entry = entry->next; entry; entry = entry->next) for (entry = entry->next; entry; entry = entry->next)
if (entry->name) if (entry->name)
@ -529,8 +529,8 @@ pke_next (pke_t entry)
/* Get the next entry with the given name. */ /* Get the next entry with the given name. */
pke_t nve_t
pke_next_value (pke_t entry, const char *name) nve_next_value (nve_t entry, const char *name)
{ {
for (entry = entry->next; entry; entry = entry->next) for (entry = entry->next; entry; entry = entry->next)
if (entry->name && ascii_strcasecmp (entry->name, name) == 0) if (entry->name && ascii_strcasecmp (entry->name, name) == 0)
@ -544,12 +544,12 @@ pke_next_value (pke_t entry, const char *name)
/* Get the private key. */ /* Get the private key. */
gpg_error_t gpg_error_t
pkc_get_private_key (pkc_t pk, gcry_sexp_t *retsexp) nvc_get_private_key (nvc_t pk, gcry_sexp_t *retsexp)
{ {
gpg_error_t err; gpg_error_t err;
pke_t e; nve_t e;
e = pkc_lookup (pk, "Key:"); e = nvc_lookup (pk, "Key:");
if (e == NULL) if (e == NULL)
return gpg_error (GPG_ERR_MISSING_KEY); return gpg_error (GPG_ERR_MISSING_KEY);
@ -563,7 +563,7 @@ pkc_get_private_key (pkc_t pk, gcry_sexp_t *retsexp)
/* Set the private key. */ /* Set the private key. */
gpg_error_t gpg_error_t
pkc_set_private_key (pkc_t pk, gcry_sexp_t sexp) nvc_set_private_key (nvc_t pk, gcry_sexp_t sexp)
{ {
gpg_error_t err; gpg_error_t err;
char *raw, *clean, *p; char *raw, *clean, *p;
@ -610,7 +610,7 @@ pkc_set_private_key (pkc_t pk, gcry_sexp_t sexp)
} }
*p = 0; *p = 0;
err = pkc_set (pk, "Key:", clean); err = nvc_set (pk, "Key:", clean);
xfree (raw); xfree (raw);
xfree (clean); xfree (clean);
return err; return err;
@ -624,7 +624,7 @@ pkc_set_private_key (pkc_t pk, gcry_sexp_t sexp)
structure in RESULT. If ERRLINEP is given, the line number the structure in RESULT. If ERRLINEP is given, the line number the
parser was last considering is stored there. */ parser was last considering is stored there. */
gpg_error_t gpg_error_t
pkc_parse (pkc_t *result, int *errlinep, estream_t stream) nvc_parse (nvc_t *result, int *errlinep, estream_t stream)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
gpgrt_ssize_t len; gpgrt_ssize_t len;
@ -634,7 +634,7 @@ pkc_parse (pkc_t *result, int *errlinep, estream_t stream)
strlist_t raw_value = NULL; strlist_t raw_value = NULL;
*result = pkc_new (); *result = nvc_new ();
if (*result == NULL) if (*result == NULL)
return my_error_from_syserror (); return my_error_from_syserror ();
@ -664,7 +664,7 @@ pkc_parse (pkc_t *result, int *errlinep, estream_t stream)
/* No continuation. Add the current entry if any. */ /* No continuation. Add the current entry if any. */
if (raw_value) if (raw_value)
{ {
err = _pkc_add (*result, name, NULL, raw_value, 1); err = _nvc_add (*result, name, NULL, raw_value, 1);
if (err) if (err)
goto leave; goto leave;
} }
@ -713,13 +713,13 @@ pkc_parse (pkc_t *result, int *errlinep, estream_t stream)
/* Add the final entry. */ /* Add the final entry. */
if (raw_value) if (raw_value)
err = _pkc_add (*result, name, NULL, raw_value, 1); err = _nvc_add (*result, name, NULL, raw_value, 1);
leave: leave:
gpgrt_free (buf); gpgrt_free (buf);
if (err) if (err)
{ {
pkc_release (*result); nvc_release (*result);
*result = NULL; *result = NULL;
} }
@ -729,10 +729,10 @@ pkc_parse (pkc_t *result, int *errlinep, estream_t stream)
/* Write a representation of PK to STREAM. */ /* Write a representation of PK to STREAM. */
gpg_error_t gpg_error_t
pkc_write (pkc_t pk, estream_t stream) nvc_write (nvc_t pk, estream_t stream)
{ {
gpg_error_t err; gpg_error_t err;
pke_t entry; nve_t entry;
strlist_t s; strlist_t s;
for (entry = pk->first; entry; entry = entry->next) for (entry = pk->first; entry; entry = entry->next)

View File

@ -30,43 +30,43 @@
#ifndef GNUPG_COMMON_NAME_VALUE_H #ifndef GNUPG_COMMON_NAME_VALUE_H
#define GNUPG_COMMON_NAME_VALUE_H #define GNUPG_COMMON_NAME_VALUE_H
struct private_key_container; struct name_value_container;
typedef struct private_key_container *pkc_t; typedef struct name_value_container *nvc_t;
struct private_key_entry; struct name_value_entry;
typedef struct private_key_entry *pke_t; typedef struct name_value_entry *nve_t;
/* Memory management, and dealing with entries. */ /* Memory management, and dealing with entries. */
/* Allocate a private key container structure. */ /* Allocate a private key container structure. */
pkc_t pkc_new (void); nvc_t nvc_new (void);
/* Release a private key container structure. */ /* Release a private key container structure. */
void pkc_release (pkc_t pk); void nvc_release (nvc_t pk);
/* Get the name. */ /* Get the name. */
char *pke_name (pke_t pke); char *nve_name (nve_t pke);
/* Get the value. */ /* Get the value. */
char *pke_value (pke_t pke); char *nve_value (nve_t pke);
/* Lookup and iteration. */ /* Lookup and iteration. */
/* Get the first non-comment entry. */ /* Get the first non-comment entry. */
pke_t pkc_first (pkc_t pk); nve_t nvc_first (nvc_t pk);
/* Get the first entry with the given name. */ /* Get the first entry with the given name. */
pke_t pkc_lookup (pkc_t pk, const char *name); nve_t nvc_lookup (nvc_t pk, const char *name);
/* Get the next non-comment entry. */ /* Get the next non-comment entry. */
pke_t pke_next (pke_t entry); nve_t nve_next (nve_t entry);
/* Get the next entry with the given name. */ /* Get the next entry with the given name. */
pke_t pke_next_value (pke_t entry, const char *name); nve_t nve_next_value (nve_t entry, const char *name);
@ -74,25 +74,25 @@ pke_t pke_next_value (pke_t entry, const char *name);
/* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it /* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it
is not updated but the new entry is appended. */ is not updated but the new entry is appended. */
gpg_error_t pkc_add (pkc_t pk, const char *name, const char *value); gpg_error_t nvc_add (nvc_t pk, const char *name, const char *value);
/* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it /* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it
is updated with VALUE. If multiple entries with NAME exist, the is updated with VALUE. If multiple entries with NAME exist, the
first entry is updated. */ first entry is updated. */
gpg_error_t pkc_set (pkc_t pk, const char *name, const char *value); gpg_error_t nvc_set (nvc_t pk, const char *name, const char *value);
/* Delete the given entry from PK. */ /* Delete the given entry from PK. */
void pkc_delete (pkc_t pk, pke_t pke); void nvc_delete (nvc_t pk, nve_t pke);
/* Private key handling. */ /* Private key handling. */
/* Get the private key. */ /* Get the private key. */
gpg_error_t pkc_get_private_key (pkc_t pk, gcry_sexp_t *retsexp); gpg_error_t nvc_get_private_key (nvc_t pk, gcry_sexp_t *retsexp);
/* Set the private key. */ /* Set the private key. */
gpg_error_t pkc_set_private_key (pkc_t pk, gcry_sexp_t sexp); gpg_error_t nvc_set_private_key (nvc_t pk, gcry_sexp_t sexp);
@ -101,9 +101,9 @@ gpg_error_t pkc_set_private_key (pkc_t pk, gcry_sexp_t sexp);
/* Parse STREAM and return a newly allocated private key container /* Parse STREAM and return a newly allocated private key container
structure in RESULT. If ERRLINEP is given, the line number the structure in RESULT. If ERRLINEP is given, the line number the
parser was last considering is stored there. */ parser was last considering is stored there. */
gpg_error_t pkc_parse (pkc_t *result, int *errlinep, estream_t stream); gpg_error_t nvc_parse (nvc_t *result, int *errlinep, estream_t stream);
/* Write a representation of PK to STREAM. */ /* Write a representation of PK to STREAM. */
gpg_error_t pkc_write (pkc_t pk, estream_t stream); gpg_error_t nvc_write (nvc_t pk, estream_t stream);
#endif /* GNUPG_COMMON_NAME_VALUE_H */ #endif /* GNUPG_COMMON_NAME_VALUE_H */

View File

@ -31,31 +31,31 @@
static int verbose; static int verbose;
void void
test_getting_values (pkc_t pk) test_getting_values (nvc_t pk)
{ {
pke_t e; nve_t e;
e = pkc_lookup (pk, "Comment:"); e = nvc_lookup (pk, "Comment:");
assert (e); assert (e);
/* Names are case-insensitive. */ /* Names are case-insensitive. */
e = pkc_lookup (pk, "comment:"); e = nvc_lookup (pk, "comment:");
assert (e); assert (e);
e = pkc_lookup (pk, "COMMENT:"); e = nvc_lookup (pk, "COMMENT:");
assert (e); assert (e);
e = pkc_lookup (pk, "SomeOtherName:"); e = nvc_lookup (pk, "SomeOtherName:");
assert (e); assert (e);
} }
void void
test_key_extraction (pkc_t pk) test_key_extraction (nvc_t pk)
{ {
gpg_error_t err; gpg_error_t err;
gcry_sexp_t key; gcry_sexp_t key;
err = pkc_get_private_key (pk, &key); err = nvc_get_private_key (pk, &key);
assert (err == 0); assert (err == 0);
assert (key); assert (key);
@ -67,41 +67,41 @@ test_key_extraction (pkc_t pk)
void void
test_iteration (pkc_t pk) test_iteration (nvc_t pk)
{ {
int i; int i;
pke_t e; nve_t e;
i = 0; i = 0;
for (e = pkc_first (pk); e; e = pke_next (e)) for (e = nvc_first (pk); e; e = nve_next (e))
i++; i++;
assert (i == 4); assert (i == 4);
i = 0; i = 0;
for (e = pkc_lookup (pk, "Comment:"); for (e = nvc_lookup (pk, "Comment:");
e; e;
e = pke_next_value (e, "Comment:")) e = nve_next_value (e, "Comment:"))
i++; i++;
assert (i == 3); assert (i == 3);
} }
void void
test_whitespace (pkc_t pk) test_whitespace (nvc_t pk)
{ {
pke_t e; nve_t e;
e = pkc_lookup (pk, "One:"); e = nvc_lookup (pk, "One:");
assert (e); assert (e);
assert (strcmp (pke_value (e), "WithoutWhitespace") == 0); assert (strcmp (nve_value (e), "WithoutWhitespace") == 0);
e = pkc_lookup (pk, "Two:"); e = nvc_lookup (pk, "Two:");
assert (e); assert (e);
assert (strcmp (pke_value (e), "With Whitespace") == 0); assert (strcmp (nve_value (e), "With Whitespace") == 0);
e = pkc_lookup (pk, "Three:"); e = nvc_lookup (pk, "Three:");
assert (e); assert (e);
assert (strcmp (pke_value (e), assert (strcmp (nve_value (e),
"Blank lines in continuations encode newlines.\n" "Blank lines in continuations encode newlines.\n"
"Next paragraph.") == 0); "Next paragraph.") == 0);
} }
@ -110,7 +110,7 @@ test_whitespace (pkc_t pk)
struct struct
{ {
char *value; char *value;
void (*test_func) (pkc_t); void (*test_func) (nvc_t);
} tests[] = } tests[] =
{ {
{ {
@ -193,7 +193,7 @@ struct
static char * static char *
pkc_to_string (pkc_t pk) nvc_to_string (nvc_t pk)
{ {
gpg_error_t err; gpg_error_t err;
char *buf; char *buf;
@ -203,7 +203,7 @@ pkc_to_string (pkc_t pk)
sink = es_fopenmem (0, "rw"); sink = es_fopenmem (0, "rw");
assert (sink); assert (sink);
err = pkc_write (pk, sink); err = nvc_write (pk, sink);
assert (err == 0); assert (err == 0);
len = es_ftell (sink); len = es_ftell (sink);
@ -226,7 +226,7 @@ void
run_tests (void) run_tests (void)
{ {
gpg_error_t err; gpg_error_t err;
pkc_t pk; nvc_t pk;
int i; int i;
for (i = 0; i < DIM (tests); i++) for (i = 0; i < DIM (tests); i++)
@ -240,17 +240,17 @@ run_tests (void)
0, dummy_realloc, dummy_free, "r"); 0, dummy_realloc, dummy_free, "r");
assert (source); assert (source);
err = pkc_parse (&pk, NULL, source); err = nvc_parse (&pk, NULL, source);
assert (err == 0); assert (err == 0);
assert (pk); assert (pk);
if (verbose) if (verbose)
{ {
err = pkc_write (pk, es_stderr); err = nvc_write (pk, es_stderr);
assert (err == 0); assert (err == 0);
} }
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (memcmp (tests[i].value, buf, len) == 0); assert (memcmp (tests[i].value, buf, len) == 0);
es_fclose (source); es_fclose (source);
@ -259,7 +259,7 @@ run_tests (void)
if (tests[i].test_func) if (tests[i].test_func)
tests[i].test_func (pk); tests[i].test_func (pk);
pkc_release (pk); nvc_release (pk);
} }
} }
@ -268,106 +268,106 @@ void
run_modification_tests (void) run_modification_tests (void)
{ {
gpg_error_t err; gpg_error_t err;
pkc_t pk; nvc_t pk;
gcry_sexp_t key; gcry_sexp_t key;
char *buf; char *buf;
pk = pkc_new (); pk = nvc_new ();
assert (pk); assert (pk);
pkc_set (pk, "Foo:", "Bar"); nvc_set (pk, "Foo:", "Bar");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Bar\n") == 0); assert (strcmp (buf, "Foo: Bar\n") == 0);
xfree (buf); xfree (buf);
pkc_set (pk, "Foo:", "Baz"); nvc_set (pk, "Foo:", "Baz");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Baz\n") == 0); assert (strcmp (buf, "Foo: Baz\n") == 0);
xfree (buf); xfree (buf);
pkc_set (pk, "Bar:", "Bazzel"); nvc_set (pk, "Bar:", "Bazzel");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Baz\nBar: Bazzel\n") == 0); assert (strcmp (buf, "Foo: Baz\nBar: Bazzel\n") == 0);
xfree (buf); xfree (buf);
pkc_add (pk, "Foo:", "Bar"); nvc_add (pk, "Foo:", "Bar");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Baz\nFoo: Bar\nBar: Bazzel\n") == 0); assert (strcmp (buf, "Foo: Baz\nFoo: Bar\nBar: Bazzel\n") == 0);
xfree (buf); xfree (buf);
pkc_add (pk, "DontExistYet:", "Bar"); nvc_add (pk, "DontExistYet:", "Bar");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Baz\nFoo: Bar\nBar: Bazzel\nDontExistYet: Bar\n") assert (strcmp (buf, "Foo: Baz\nFoo: Bar\nBar: Bazzel\nDontExistYet: Bar\n")
== 0); == 0);
xfree (buf); xfree (buf);
pkc_delete (pk, pkc_lookup (pk, "DontExistYet:")); nvc_delete (pk, nvc_lookup (pk, "DontExistYet:"));
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Baz\nFoo: Bar\nBar: Bazzel\n") == 0); assert (strcmp (buf, "Foo: Baz\nFoo: Bar\nBar: Bazzel\n") == 0);
xfree (buf); xfree (buf);
pkc_delete (pk, pke_next_value (pkc_lookup (pk, "Foo:"), "Foo:")); nvc_delete (pk, nve_next_value (nvc_lookup (pk, "Foo:"), "Foo:"));
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Baz\nBar: Bazzel\n") == 0); assert (strcmp (buf, "Foo: Baz\nBar: Bazzel\n") == 0);
xfree (buf); xfree (buf);
pkc_delete (pk, pkc_lookup (pk, "Foo:")); nvc_delete (pk, nvc_lookup (pk, "Foo:"));
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Bar: Bazzel\n") == 0); assert (strcmp (buf, "Bar: Bazzel\n") == 0);
xfree (buf); xfree (buf);
pkc_delete (pk, pkc_first (pk)); nvc_delete (pk, nvc_first (pk));
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "") == 0); assert (strcmp (buf, "") == 0);
xfree (buf); xfree (buf);
pkc_set (pk, "Foo:", "A really long value spanning across multiple lines" nvc_set (pk, "Foo:", "A really long value spanning across multiple lines"
" that has to be wrapped at a convenient space."); " that has to be wrapped at a convenient space.");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: A really long value spanning across multiple" assert (strcmp (buf, "Foo: A really long value spanning across multiple"
" lines that has to be\n wrapped at a convenient space.\n") " lines that has to be\n wrapped at a convenient space.\n")
== 0); == 0);
xfree (buf); xfree (buf);
pkc_set (pk, "Foo:", "XA really long value spanning across multiple lines" nvc_set (pk, "Foo:", "XA really long value spanning across multiple lines"
" that has to be wrapped at a convenient space."); " that has to be wrapped at a convenient space.");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: XA really long value spanning across multiple" assert (strcmp (buf, "Foo: XA really long value spanning across multiple"
" lines that has to\n be wrapped at a convenient space.\n") " lines that has to\n be wrapped at a convenient space.\n")
== 0); == 0);
xfree (buf); xfree (buf);
pkc_set (pk, "Foo:", "XXXXA really long value spanning across multiple lines" nvc_set (pk, "Foo:", "XXXXA really long value spanning across multiple lines"
" that has to be wrapped at a convenient space."); " that has to be wrapped at a convenient space.");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: XXXXA really long value spanning across multiple" assert (strcmp (buf, "Foo: XXXXA really long value spanning across multiple"
" lines that has\n to be wrapped at a convenient space.\n") " lines that has\n to be wrapped at a convenient space.\n")
== 0); == 0);
xfree (buf); xfree (buf);
pkc_set (pk, "Foo:", "Areallylongvaluespanningacrossmultiplelines" nvc_set (pk, "Foo:", "Areallylongvaluespanningacrossmultiplelines"
"thathastobewrappedataconvenientspacethatisnotthere."); "thathastobewrappedataconvenientspacethatisnotthere.");
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Foo: Areallylongvaluespanningacrossmultiplelinesthat" assert (strcmp (buf, "Foo: Areallylongvaluespanningacrossmultiplelinesthat"
"hastobewrappedataco\n nvenientspacethatisnotthere.\n") "hastobewrappedataco\n nvenientspacethatisnotthere.\n")
== 0); == 0);
xfree (buf); xfree (buf);
pkc_release (pk); nvc_release (pk);
pk = pkc_new (); pk = nvc_new ();
assert (pk); assert (pk);
err = gcry_sexp_build (&key, NULL, "(hello world)"); err = gcry_sexp_build (&key, NULL, "(hello world)");
assert (err == 0); assert (err == 0);
assert (key); assert (key);
err = pkc_set_private_key (pk, key); err = nvc_set_private_key (pk, key);
gcry_sexp_release (key); gcry_sexp_release (key);
assert (err == 0); assert (err == 0);
buf = pkc_to_string (pk); buf = nvc_to_string (pk);
assert (strcmp (buf, "Key: (hello world)\n") == 0); assert (strcmp (buf, "Key: (hello world)\n") == 0);
xfree (buf); xfree (buf);
pkc_release (pk); nvc_release (pk);
} }
@ -380,7 +380,7 @@ convert (const char *fname)
char *buf; char *buf;
size_t buflen; size_t buflen;
struct stat st; struct stat st;
pkc_t pk; nvc_t pk;
source = es_fopen (fname, "rb"); source = es_fopen (fname, "rb");
if (source == NULL) if (source == NULL)
@ -403,13 +403,13 @@ convert (const char *fname)
exit (1); exit (1);
} }
pk = pkc_new (); pk = nvc_new ();
assert (pk); assert (pk);
err = pkc_set_private_key (pk, key); err = nvc_set_private_key (pk, key);
assert (err == 0); assert (err == 0);
err = pkc_write (pk, es_stdout); err = nvc_write (pk, es_stdout);
assert (err == 0); assert (err == 0);
return; return;
@ -426,8 +426,8 @@ parse (const char *fname)
gpg_error_t err; gpg_error_t err;
estream_t source; estream_t source;
char *buf; char *buf;
pkc_t pk_a, pk_b; nvc_t pk_a, pk_b;
pke_t e; nve_t e;
int line; int line;
source = es_fopen (fname, "rb"); source = es_fopen (fname, "rb");
@ -437,7 +437,7 @@ parse (const char *fname)
exit (1); exit (1);
} }
err = pkc_parse (&pk_a, &line, source); err = nvc_parse (&pk_a, &line, source);
if (err) if (err)
{ {
fprintf (stderr, "failed to parse %s line %d: %s\n", fprintf (stderr, "failed to parse %s line %d: %s\n",
@ -445,36 +445,36 @@ parse (const char *fname)
exit (1); exit (1);
} }
buf = pkc_to_string (pk_a); buf = nvc_to_string (pk_a);
xfree (buf); xfree (buf);
pk_b = pkc_new (); pk_b = nvc_new ();
assert (pk_b); assert (pk_b);
for (e = pkc_first (pk_a); e; e = pke_next (e)) for (e = nvc_first (pk_a); e; e = nve_next (e))
{ {
gcry_sexp_t key = NULL; gcry_sexp_t key = NULL;
if (strcasecmp (pke_name (e), "Key:") == 0) if (strcasecmp (nve_name (e), "Key:") == 0)
{ {
err = pkc_get_private_key (pk_a, &key); err = nvc_get_private_key (pk_a, &key);
if (err) if (err)
key = NULL; key = NULL;
} }
if (key) if (key)
{ {
err = pkc_set_private_key (pk_b, key); err = nvc_set_private_key (pk_b, key);
assert (err == 0); assert (err == 0);
} }
else else
{ {
err = pkc_add (pk_b, pke_name (e), pke_value (e)); err = nvc_add (pk_b, nve_name (e), nve_value (e));
assert (err == 0); assert (err == 0);
} }
} }
buf = pkc_to_string (pk_b); buf = nvc_to_string (pk_b);
if (verbose) if (verbose)
fprintf (stdout, "%s", buf); fprintf (stdout, "%s", buf);
xfree (buf); xfree (buf);