mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-24 22:09:57 +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:
parent
d6693c144c
commit
39e659312e
@ -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>
|
||||
|
||||
* g10.c (main): Add --no-throw-keyid.
|
||||
|
@ -1347,9 +1347,10 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
|
||||
|
||||
case cmdUPDPREF:
|
||||
{
|
||||
p = keygen_get_std_prefs ();
|
||||
tty_printf (("Current preference list: %s\n"), p);
|
||||
m_free (p);
|
||||
PKT_user_id *temp=keygen_get_std_prefs();
|
||||
tty_printf(_("Current preference list:\n"));
|
||||
show_prefs(temp,1);
|
||||
m_free(temp);
|
||||
}
|
||||
if (cpr_get_answer_is_yes ("keyedit.updpref.okay",
|
||||
count_selected_uids (keyblock)?
|
||||
|
171
g10/keygen.c
171
g10/keygen.c
@ -174,46 +174,49 @@ keygen_add_key_flags_and_expire (PKT_signature *sig, void *opaque)
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (cf (val)) {
|
||||
log_info (_("preference %c%lu is not valid\n"), type, val);
|
||||
if(type=='S' && val==CIPHER_ALGO_IDEA)
|
||||
idea_cipher_warn(1);
|
||||
return -1;
|
||||
}
|
||||
for (i=0; i < *nbuf; i++ ) {
|
||||
if (buf[i] == val) {
|
||||
log_info (_("preference %c%lu duplicated\n"), type, val);
|
||||
return -1;
|
||||
for (i=0; i < *nbuf; i++ )
|
||||
if (buf[i] == val)
|
||||
{
|
||||
log_info (_("preference `%s' duplicated\n"), item);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (*nbuf >= MAX_PREFS) {
|
||||
log_info (_("too many `%c' preferences\n"), type);
|
||||
|
||||
if (*nbuf >= MAX_PREFS)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
buf[(*nbuf)++] = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parse the supplied string and use it to set the standard preferences.
|
||||
* The String is expected to be in a forma like the one printed by "prefs",
|
||||
* something like: "S10 S3 H3 H2 Z2 Z1". Use NULL to set the default
|
||||
* preferences.
|
||||
* Returns: 0 = okay
|
||||
* Parse the supplied string and use it to set the standard
|
||||
* preferences. The string may be in a form like the one printed by
|
||||
* "pref" (something like: "S10 S3 H3 H2 Z2 Z1") or the actual
|
||||
* cipher/hash/compress names. Use NULL to set the default
|
||||
* preferences. Returns: 0 = okay
|
||||
*/
|
||||
int
|
||||
keygen_set_std_prefs (const char *string,int personal)
|
||||
{
|
||||
byte sym[MAX_PREFS], hash[MAX_PREFS], zip[MAX_PREFS];
|
||||
int nsym=0, nhash=0, nzip=0, mdc=1; /* mdc defaults on */
|
||||
ulong val;
|
||||
const char *s, *s2;
|
||||
int rc = 0;
|
||||
char *tok,*prefstring;
|
||||
int val,rc = 0;
|
||||
|
||||
if (!string || !ascii_strcasecmp (string, "default")) {
|
||||
if (opt.def_preference_list)
|
||||
@ -234,39 +237,39 @@ keygen_set_std_prefs (const char *string,int personal)
|
||||
else if (!ascii_strcasecmp (string, "none"))
|
||||
string = "";
|
||||
|
||||
for (s=string; *s; s = s2) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
prefstring=m_strdup(string); /* need a writable string! */
|
||||
|
||||
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)
|
||||
{
|
||||
@ -353,37 +356,45 @@ keygen_set_std_prefs (const char *string,int personal)
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return a printable list of preferences. Caller must free.
|
||||
*/
|
||||
char *
|
||||
keygen_get_std_prefs ()
|
||||
/* Return a fake user ID containing the preferences. Caller must
|
||||
free. */
|
||||
PKT_user_id *keygen_get_std_prefs(void)
|
||||
{
|
||||
char *buf;
|
||||
int i;
|
||||
int i,j=0;
|
||||
PKT_user_id *uid=m_alloc_clear(sizeof(PKT_user_id));
|
||||
|
||||
if (!prefs_initialized)
|
||||
keygen_set_std_prefs (NULL,0);
|
||||
if(!prefs_initialized)
|
||||
keygen_set_std_prefs(NULL,0);
|
||||
|
||||
buf = m_alloc ( MAX_PREFS*3*5 + 5 + 1);
|
||||
*buf = 0;
|
||||
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]);
|
||||
uid->prefs=m_alloc((sizeof(prefitem_t *)*
|
||||
(nsym_prefs+nhash_prefs+nzip_prefs+1)));
|
||||
|
||||
if(mdc_available)
|
||||
sprintf(buf+strlen(buf),"[mdc]");
|
||||
else if (*buf) /* trim the trailing space */
|
||||
buf[strlen(buf)-1] = 0;
|
||||
for(i=0;i<nsym_prefs;i++,j++)
|
||||
{
|
||||
uid->prefs[j].type=PREFTYPE_SYM;
|
||||
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
|
||||
add_feature_mdc (PKT_signature *sig,int enabled)
|
||||
{
|
||||
|
@ -84,6 +84,7 @@ int hextobyte( const char *s );
|
||||
void deprecated_warning(const char *configname,unsigned int configlineno,
|
||||
const char *option,const char *repl1,const char *repl2);
|
||||
const char *compress_algo_to_string(int algo);
|
||||
int string_to_compress_algo(const char *string);
|
||||
int check_compress_algo(int algo);
|
||||
|
||||
/*-- helptext.c --*/
|
||||
@ -124,7 +125,7 @@ u32 ask_expire_interval(int object);
|
||||
u32 ask_expiredate(void);
|
||||
void generate_keypair( const char *fname );
|
||||
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_std_prefs( PKT_signature *sig, void *opaque );
|
||||
int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );
|
||||
|
19
g10/misc.c
19
g10/misc.c
@ -538,6 +538,25 @@ compress_algo_to_string(int algo)
|
||||
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
|
||||
check_compress_algo(int algo)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user