[gcr/ecc: 5/10] WIP move key size calculation to subject public key
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr/ecc: 5/10] WIP move key size calculation to subject public key
- Date: Thu, 17 Apr 2014 06:52:19 +0000 (UTC)
commit d32fd8c4a002ffb5a761c9e3bf960123e5ea71cb
Author: Stef Walter <stefw redhat com>
Date: Thu Apr 17 07:14:00 2014 +0200
WIP move key size calculation to subject public key
gcr/gcr-subject-public-key.c | 55 ++++++++++++++++++++++++++++++++++++
gcr/gcr-subject-public-key.h | 2 +
ui/gcr-key-renderer.c | 64 ++++++-----------------------------------
3 files changed, 67 insertions(+), 54 deletions(-)
---
diff --git a/gcr/gcr-subject-public-key.c b/gcr/gcr-subject-public-key.c
index 5b7dc28..359307c 100644
--- a/gcr/gcr-subject-public-key.c
+++ b/gcr/gcr-subject-public-key.c
@@ -786,6 +786,24 @@ calculate_rsa_key_size (GBytes *data)
}
static guint
+attributes_rsa_key_size (GckAttributes *attrs)
+{
+ const GckAttribute *attr;
+ gulong bits;
+
+ attr = gck_attributes_find (attrs, CKA_MODULUS);
+
+ /* Calculate the bit length, and remove the complement */
+ if (attr != NULL)
+ return (attr->length / 2) * 2 * 8;
+
+ if (gck_attributes_find_ulong (attrs, CKA_MODULUS_BITS, &bits))
+ return (gint)bits;
+
+ return 0;
+}
+
+static guint
calculate_dsa_params_size (GNode *params)
{
GNode *asn;
@@ -808,6 +826,24 @@ calculate_dsa_params_size (GNode *params)
return key_size;
}
+static guint
+attributes_dsa_key_size (GckAttributes *attrs)
+{
+ const GckAttribute *attr;
+ gulong bits;
+
+ attr = gck_attributes_find (attrs, CKA_PRIME);
+
+ /* Calculate the bit length, and remove the complement */
+ if (attr != NULL)
+ return (attr->length / 2) * 2 * 8;
+
+ if (gck_attributes_find_ulong (attrs, CKA_PRIME_BITS, &bits))
+ return (gint)bits;
+
+ return 0;
+}
+
guint
_gcr_subject_public_key_calculate_size (GNode *subject_public_key)
{
@@ -840,3 +876,22 @@ _gcr_subject_public_key_calculate_size (GNode *subject_public_key)
return key_size;
}
+
+guint
+_gcr_subject_public_key_attributes_size (GckAttributes *attrs)
+{
+ gulong key_type;
+
+ if (!gck_attributes_find_ulong (attrs, CKA_KEY_TYPE, &key_type))
+ return 0;
+
+ switch (key_type) {
+ case CKK_RSA:
+ return attributes_rsa_key_size (attrs);
+ case CKK_DSA:
+ return attributes_dsa_key_size (attrs);
+ default:
+ g_message ("unsupported key algorithm: %lu", key_type);
+ return 0;
+ }
+}
diff --git a/gcr/gcr-subject-public-key.h b/gcr/gcr-subject-public-key.h
index 4a45bd0..9e7c1d9 100644
--- a/gcr/gcr-subject-public-key.h
+++ b/gcr/gcr-subject-public-key.h
@@ -48,6 +48,8 @@ GNode * _gcr_subject_public_key_load_finish (GAsyncResult *result,
guint _gcr_subject_public_key_calculate_size (GNode *subject_public_key);
+guint _gcr_subject_public_key_attributes_size (GckAttributes *attributes);
+
G_END_DECLS
#endif /* GCR_CERTIFICATE_H */
diff --git a/ui/gcr-key-renderer.c b/ui/gcr-key-renderer.c
index a4dbdb9..517395f 100644
--- a/ui/gcr-key-renderer.c
+++ b/ui/gcr-key-renderer.c
@@ -114,53 +114,6 @@ calculate_fingerprint (GcrKeyRenderer *self,
return gcr_fingerprint_from_attributes (attrs, algorithm, n_fingerprint);
}
-static gint
-calculate_rsa_key_size (GckAttributes *attrs)
-{
- const GckAttribute *attr;
- gulong bits;
-
- attr = gck_attributes_find (attrs, CKA_MODULUS);
-
- /* Calculate the bit length, and remove the complement */
- if (attr != NULL)
- return (attr->length / 2) * 2 * 8;
-
- if (gck_attributes_find_ulong (attrs, CKA_MODULUS_BITS, &bits))
- return (gint)bits;
-
- return -1;
-}
-
-static guint
-calculate_dsa_key_size (GckAttributes *attrs)
-{
- const GckAttribute *attr;
- gulong bits;
-
- attr = gck_attributes_find (attrs, CKA_PRIME);
-
- /* Calculate the bit length, and remove the complement */
- if (attr != NULL)
- return (attr->length / 2) * 2 * 8;
-
- if (gck_attributes_find_ulong (attrs, CKA_PRIME_BITS, &bits))
- return (gint)bits;
-
- return -1;
-}
-
-static gint
-calculate_key_size (GckAttributes *attrs, gulong key_type)
-{
- if (key_type == CKK_RSA)
- return calculate_rsa_key_size (attrs);
- else if (key_type == CKK_DSA)
- return calculate_dsa_key_size (attrs);
- else
- return -1;
-}
-
static void
on_subject_public_key (GObject *source,
GAsyncResult *result,
@@ -362,7 +315,7 @@ gcr_key_renderer_real_render (GcrRenderer *renderer, GcrViewer *viewer)
gchar *display;
gulong klass;
gulong key_type;
- gint size;
+ guint size;
self = GCR_KEY_RENDERER (renderer);
@@ -409,15 +362,17 @@ gcr_key_renderer_real_render (GcrRenderer *renderer, GcrViewer *viewer)
text = _("Public DSA Key");
else if (key_type == CKK_DSA)
text = _("Public DSA Key");
+ else if (key_type == CKK_ECDSA)
+ text = _("Public ECDSA Key");
else
text = _("Public Key");
}
_gcr_display_view_append_content (view, renderer, text, NULL);
- size = calculate_key_size (attrs, key_type);
- if (size >= 0) {
- display = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d bit", "%d bits", size), size);
+ size = _gcr_subject_public_key_attributes_size (attrs);
+ if (size > 0) {
+ display = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%u bit", "%u bits", size), size);
_gcr_display_view_append_content (view, renderer, _("Strength"), display);
g_free (display);
}
@@ -428,15 +383,16 @@ gcr_key_renderer_real_render (GcrRenderer *renderer, GcrViewer *viewer)
text = _("RSA");
else if (key_type == CKK_DSA)
text = _("DSA");
+ else if (key_type == CKK_ECDSA)
+ text = _("ECDSA");
else
text = _("Unknown");
_gcr_display_view_append_value (view, renderer, _("Algorithm"), text, FALSE);
- size = calculate_key_size (attrs, key_type);
- if (size < 0)
+ if (size == 0)
display = g_strdup (_("Unknown"));
else
- display = g_strdup_printf ("%d", size);
+ display = g_strdup_printf ("%u", size);
_gcr_display_view_append_value (view, renderer, _("Size"), display, FALSE);
g_free (display);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]