[seahorse] pgp: Define default key length for each algorithm



commit b6a37957bd2b12dc243d7cc4070342f5c96e6b31
Author: nobled <nobled dreamwidth org>
Date:   Mon Feb 22 03:01:30 2010 +0000

    pgp: Define default key length for each algorithm
    
    Avoid hardcoding 2048 bits as the default, since defaults for
    key algorithms can change and new algorithms can be added.
    
    Closes: bgo#605497.

 pgp/seahorse-gpgme-add-subkey.c |    6 +++---
 pgp/seahorse-gpgme-generate.c   |   31 ++++++++++++++++---------------
 pgp/seahorse-gpgme-key-op.h     |    4 +++-
 3 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/pgp/seahorse-gpgme-add-subkey.c b/pgp/seahorse-gpgme-add-subkey.c
index de7f090..614a82d 100644
--- a/pgp/seahorse-gpgme-add-subkey.c
+++ b/pgp/seahorse-gpgme-add-subkey.c
@@ -59,17 +59,17 @@ hanlder_gpgme_add_subkey_type_changed (GtkComboBox *combo, SeahorseWidget *swidg
 		/* DSA */
 		case 0:
 			gtk_spin_button_set_range (length, DSA_MIN, DSA_MAX);
-			gtk_spin_button_set_value (length, DSA_MAX);
+			gtk_spin_button_set_value (length, LENGTH_DEFAULT < DSA_MAX ? LENGTH_DEFAULT : DSA_MAX);
 			break;
 		/* ElGamal */
 		case 1:
 			gtk_spin_button_set_range (length, ELGAMAL_MIN, LENGTH_MAX);
-			gtk_spin_button_set_value (length, LENGTH_MAX / 2);
+			gtk_spin_button_set_value (length, LENGTH_DEFAULT);
 			break;
 		/* RSA */
 		default:
 			gtk_spin_button_set_range (length, RSA_MIN, LENGTH_MAX);
-			gtk_spin_button_set_value (length, LENGTH_MAX / 2);
+			gtk_spin_button_set_value (length, LENGTH_DEFAULT);
 			break;
 	}
 }
diff --git a/pgp/seahorse-gpgme-generate.c b/pgp/seahorse-gpgme-generate.c
index 0dc8e76..88693b2 100644
--- a/pgp/seahorse-gpgme-generate.c
+++ b/pgp/seahorse-gpgme-generate.c
@@ -109,13 +109,14 @@ typedef struct _AlgorithmDesc {
     guint type;
     guint min;
     guint max;
+    guint def;
 } AlgorithmDesc;
 
 static AlgorithmDesc available_algorithms[] = {
-    { N_("RSA"),             RSA_RSA,     RSA_MIN,     LENGTH_MAX  },
-    { N_("DSA Elgamal"),     DSA_ELGAMAL, ELGAMAL_MIN, LENGTH_MAX  },
-    { N_("DSA (sign only)"), DSA,         DSA_MIN,     DSA_MAX     },
-    { N_("RSA (sign only)"), RSA_SIGN,    RSA_MIN,     LENGTH_MAX  }
+    { N_("RSA"),             RSA_RSA,     RSA_MIN,     LENGTH_MAX, LENGTH_DEFAULT  },
+    { N_("DSA Elgamal"),     DSA_ELGAMAL, ELGAMAL_MIN, LENGTH_MAX, LENGTH_DEFAULT  },
+    { N_("DSA (sign only)"), DSA,         DSA_MIN,     DSA_MAX,    LENGTH_DEFAULT  },
+    { N_("RSA (sign only)"), RSA_SIGN,    RSA_MIN,     LENGTH_MAX, LENGTH_DEFAULT  }
 };
 
 /**
@@ -276,9 +277,9 @@ on_gpgme_generate_response (GtkDialog *dialog, guint response, SeahorseWidget *s
     widget = seahorse_widget_get_widget (swidget, "bits-entry");
     g_return_if_fail (widget != NULL);
     bits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
-    if (bits < 512 || bits > 8192) {
-        g_message ("invalid key size: %s defaulting to 2048", available_algorithms[sel].desc);
-        bits = 2048;
+    if (bits < available_algorithms[sel].min || bits > available_algorithms[sel].max) {
+        bits = available_algorithms[sel].def;
+        g_message ("invalid key size: %s defaulting to %u", available_algorithms[sel].desc, bits);
     }
     
     /* The expiry */
@@ -362,23 +363,23 @@ G_MODULE_EXPORT void
 on_gpgme_generate_algorithm_changed (GtkComboBox *combo, SeahorseWidget *swidget)
 {
     GtkWidget *widget;
-    gint idx;
+    gint sel;
     
-    idx = gtk_combo_box_get_active (combo);
-    g_assert (idx < (int)G_N_ELEMENTS (available_algorithms));
+    sel = gtk_combo_box_get_active (combo);
+    g_assert (sel < (int)G_N_ELEMENTS (available_algorithms));
     
     widget = seahorse_widget_get_widget (swidget, "bits-entry");
     g_return_if_fail (widget != NULL);
     
     gtk_spin_button_set_range (GTK_SPIN_BUTTON (widget), 
-                               available_algorithms[idx].min, 
-                               available_algorithms[idx].max);
+                               available_algorithms[sel].min,
+                               available_algorithms[sel].max);
 
     /* Set sane default key length */
-    if (2048 > available_algorithms[idx].max)
-        gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), available_algorithms[idx].max);
+    if (available_algorithms[sel].def > available_algorithms[sel].max)
+        gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), available_algorithms[sel].max);
     else
-        gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), 2048);
+        gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), available_algorithms[sel].def);
 }
 
 /**
diff --git a/pgp/seahorse-gpgme-key-op.h b/pgp/seahorse-gpgme-key-op.h
index ad83f9b..8b791a3 100644
--- a/pgp/seahorse-gpgme-key-op.h
+++ b/pgp/seahorse-gpgme-key-op.h
@@ -101,7 +101,9 @@ typedef enum {
 	 */
 	RSA_MIN = 1024,
 	/* Maximum length for #ELGAMAL, #RSA_SIGN, and #RSA_ENCRYPT. */
-	LENGTH_MAX = 4096
+	LENGTH_MAX = 4096,
+	/* Default length for #ELGAMAL, #RSA_SIGN, #RSA_ENCRYPT, and #DSA. */
+	LENGTH_DEFAULT = 2048
 } SeahorseKeyLength;
 
 typedef enum {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]