1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-28 22:49:59 +01:00

* keygen.c (set_one_pref, keygen_set_std_prefs): Allow using the full

algorithm name (CAST5, SHA1) rather than the short form (S3, H2).

* main.h, keygen.c (keygen_get_std_prefs), keyedit.c (keyedit_menu):
Return and use a fake uid packet rather than a string since we already
have a nice parser/printer in keyedit.c:show_prefs.

* main.h, misc.c (string_to_compress_algo): New.
This commit is contained in:
David Shaw 2002-11-03 00:00:42 +00:00
parent d6693c144c
commit 39e659312e
5 changed files with 129 additions and 84 deletions

View File

@ -1,3 +1,16 @@
2002-11-02 David Shaw <dshaw@jabberwocky.com>
* keygen.c (set_one_pref, keygen_set_std_prefs): Allow using the
full algorithm name (CAST5, SHA1) rather than the short form (S3,
H2).
* main.h, keygen.c (keygen_get_std_prefs), keyedit.c
(keyedit_menu): Return and use a fake uid packet rather than a
string since we already have a nice parser/printer in
keyedit.c:show_prefs.
* main.h, misc.c (string_to_compress_algo): New.
2002-11-01 David Shaw <dshaw@jabberwocky.com> 2002-11-01 David Shaw <dshaw@jabberwocky.com>
* g10.c (main): Add --no-throw-keyid. * g10.c (main): Add --no-throw-keyid.

View File

@ -1347,9 +1347,10 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
case cmdUPDPREF: case cmdUPDPREF:
{ {
p = keygen_get_std_prefs (); PKT_user_id *temp=keygen_get_std_prefs();
tty_printf (("Current preference list: %s\n"), p); tty_printf(_("Current preference list:\n"));
m_free (p); show_prefs(temp,1);
m_free(temp);
} }
if (cpr_get_answer_is_yes ("keyedit.updpref.okay", if (cpr_get_answer_is_yes ("keyedit.updpref.okay",
count_selected_uids (keyblock)? count_selected_uids (keyblock)?

View File

@ -174,46 +174,49 @@ keygen_add_key_flags_and_expire (PKT_signature *sig, void *opaque)
} }
static int static int
set_one_pref (ulong val, int type, int (*cf)(int), byte *buf, int *nbuf) set_one_pref (int val, int type, const char *item, byte *buf, int *nbuf)
{ {
int i; int i;
if (cf (val)) { for (i=0; i < *nbuf; i++ )
log_info (_("preference %c%lu is not valid\n"), type, val); if (buf[i] == val)
if(type=='S' && val==CIPHER_ALGO_IDEA) {
idea_cipher_warn(1); log_info (_("preference `%s' duplicated\n"), item);
return -1; return -1;
}
for (i=0; i < *nbuf; i++ ) {
if (buf[i] == val) {
log_info (_("preference %c%lu duplicated\n"), type, val);
return -1;
} }
}
if (*nbuf >= MAX_PREFS) { if (*nbuf >= MAX_PREFS)
log_info (_("too many `%c' preferences\n"), type); {
if(type==1)
log_info(_("too many cipher preferences\n"));
else if(type==2)
log_info(_("too many digest preferences\n"));
else if(type==3)
log_info(_("too many compression preferences\n"));
else
BUG();
return -1; return -1;
} }
buf[(*nbuf)++] = val; buf[(*nbuf)++] = val;
return 0; return 0;
} }
/* /*
* Parse the supplied string and use it to set the standard preferences. * Parse the supplied string and use it to set the standard
* The String is expected to be in a forma like the one printed by "prefs", * preferences. The string may be in a form like the one printed by
* something like: "S10 S3 H3 H2 Z2 Z1". Use NULL to set the default * "pref" (something like: "S10 S3 H3 H2 Z2 Z1") or the actual
* preferences. * cipher/hash/compress names. Use NULL to set the default
* Returns: 0 = okay * preferences. Returns: 0 = okay
*/ */
int int
keygen_set_std_prefs (const char *string,int personal) keygen_set_std_prefs (const char *string,int personal)
{ {
byte sym[MAX_PREFS], hash[MAX_PREFS], zip[MAX_PREFS]; byte sym[MAX_PREFS], hash[MAX_PREFS], zip[MAX_PREFS];
int nsym=0, nhash=0, nzip=0, mdc=1; /* mdc defaults on */ int nsym=0, nhash=0, nzip=0, mdc=1; /* mdc defaults on */
ulong val; char *tok,*prefstring;
const char *s, *s2; int val,rc = 0;
int rc = 0;
if (!string || !ascii_strcasecmp (string, "default")) { if (!string || !ascii_strcasecmp (string, "default")) {
if (opt.def_preference_list) if (opt.def_preference_list)
@ -234,39 +237,39 @@ keygen_set_std_prefs (const char *string,int personal)
else if (!ascii_strcasecmp (string, "none")) else if (!ascii_strcasecmp (string, "none"))
string = ""; string = "";
for (s=string; *s; s = s2) { prefstring=m_strdup(string); /* need a writable string! */
if ((*s=='s' || *s == 'S') && isdigit(s[1]) ) {
val = strtoul (++s, (char**)&s2, 10);
if (set_one_pref (val, 'S', check_cipher_algo, sym, &nsym))
rc = -1;
}
else if ((*s=='h' || *s == 'H') && isdigit(s[1]) ) {
val = strtoul (++s, (char**)&s2, 10);
if (set_one_pref (val, 'H', check_digest_algo, hash, &nhash))
rc = -1;
}
else if ((*s=='z' || *s == 'Z') && isdigit(s[1]) ) {
val = strtoul (++s, (char**)&s2, 10);
if (set_one_pref (val, 'Z', check_compress_algo, zip, &nzip))
rc = -1;
}
else if (ascii_strcasecmp(s,"mdc")==0) {
mdc=1;
s2=s+3;
}
else if (ascii_strcasecmp(s,"no-mdc")==0) {
mdc=0;
s2=s+6;
}
else if (isspace (*s))
s2 = s+1;
else {
log_info (_("invalid character in preference string\n"));
return -1;
}
}
if (!rc) while((tok=strsep(&prefstring," ,")))
{
if((val=string_to_cipher_algo(tok)))
{
if(set_one_pref(val,1,tok,sym,&nsym))
rc=-1;
}
else if((val=string_to_digest_algo(tok)))
{
if(set_one_pref(val,2,tok,hash,&nhash))
rc=-1;
}
else if((val=string_to_compress_algo(tok))>-1)
{
if(set_one_pref(val,3,tok,zip,&nzip))
rc=-1;
}
else if (ascii_strcasecmp(tok,"mdc")==0)
mdc=1;
else if (ascii_strcasecmp(tok,"no-mdc")==0)
mdc=0;
else
{
log_info (_("invalid item `%s' in preference string\n"),tok);
rc=-1;
}
}
m_free(prefstring);
if(!rc)
{ {
if(personal) if(personal)
{ {
@ -353,37 +356,45 @@ keygen_set_std_prefs (const char *string,int personal)
return rc; return rc;
} }
/* Return a fake user ID containing the preferences. Caller must
/* free. */
* Return a printable list of preferences. Caller must free. PKT_user_id *keygen_get_std_prefs(void)
*/
char *
keygen_get_std_prefs ()
{ {
char *buf; int i,j=0;
int i; PKT_user_id *uid=m_alloc_clear(sizeof(PKT_user_id));
if (!prefs_initialized) if(!prefs_initialized)
keygen_set_std_prefs (NULL,0); keygen_set_std_prefs(NULL,0);
buf = m_alloc ( MAX_PREFS*3*5 + 5 + 1); uid->prefs=m_alloc((sizeof(prefitem_t *)*
*buf = 0; (nsym_prefs+nhash_prefs+nzip_prefs+1)));
for (i=0; i < nsym_prefs; i++ )
sprintf (buf+strlen(buf), "S%d ", sym_prefs[i]);
for (i=0; i < nhash_prefs; i++ )
sprintf (buf+strlen(buf), "H%d ", hash_prefs[i]);
for (i=0; i < nzip_prefs; i++ )
sprintf (buf+strlen(buf), "Z%d ", zip_prefs[i]);
if(mdc_available) for(i=0;i<nsym_prefs;i++,j++)
sprintf(buf+strlen(buf),"[mdc]"); {
else if (*buf) /* trim the trailing space */ uid->prefs[j].type=PREFTYPE_SYM;
buf[strlen(buf)-1] = 0; uid->prefs[j].value=sym_prefs[i];
}
return buf; for(i=0;i<nhash_prefs;i++,j++)
{
uid->prefs[j].type=PREFTYPE_HASH;
uid->prefs[j].value=hash_prefs[i];
}
for(i=0;i<nzip_prefs;i++,j++)
{
uid->prefs[j].type=PREFTYPE_ZIP;
uid->prefs[j].value=zip_prefs[i];
}
uid->prefs[j].type=PREFTYPE_NONE;
uid->prefs[j].value=0;
uid->mdc_feature=mdc_available;
return uid;
} }
static void static void
add_feature_mdc (PKT_signature *sig,int enabled) add_feature_mdc (PKT_signature *sig,int enabled)
{ {

View File

@ -84,6 +84,7 @@ int hextobyte( const char *s );
void deprecated_warning(const char *configname,unsigned int configlineno, void deprecated_warning(const char *configname,unsigned int configlineno,
const char *option,const char *repl1,const char *repl2); const char *option,const char *repl1,const char *repl2);
const char *compress_algo_to_string(int algo); const char *compress_algo_to_string(int algo);
int string_to_compress_algo(const char *string);
int check_compress_algo(int algo); int check_compress_algo(int algo);
/*-- helptext.c --*/ /*-- helptext.c --*/
@ -124,7 +125,7 @@ u32 ask_expire_interval(int object);
u32 ask_expiredate(void); u32 ask_expiredate(void);
void generate_keypair( const char *fname ); void generate_keypair( const char *fname );
int keygen_set_std_prefs (const char *string,int personal); int keygen_set_std_prefs (const char *string,int personal);
char *keygen_get_std_prefs (void); PKT_user_id *keygen_get_std_prefs (void);
int keygen_add_key_expire( PKT_signature *sig, void *opaque ); int keygen_add_key_expire( PKT_signature *sig, void *opaque );
int keygen_add_std_prefs( PKT_signature *sig, void *opaque ); int keygen_add_std_prefs( PKT_signature *sig, void *opaque );
int keygen_upd_std_prefs( PKT_signature *sig, void *opaque ); int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );

View File

@ -538,6 +538,25 @@ compress_algo_to_string(int algo)
return s; return s;
} }
int
string_to_compress_algo(const char *string)
{
if(ascii_strcasecmp(string,"uncompressed")==0)
return 0;
else if(ascii_strcasecmp(string,"zip")==0)
return 1;
else if(ascii_strcasecmp(string,"zlib")==0)
return 2;
else if(ascii_strcasecmp(string,"z0")==0)
return 0;
else if(ascii_strcasecmp(string,"z1")==0)
return 1;
else if(ascii_strcasecmp(string,"z2")==0)
return 2;
else
return -1;
}
int int
check_compress_algo(int algo) check_compress_algo(int algo)
{ {