[glib] gtlscertificate: Add certificate-bytes and private-key-bytes props
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gtlscertificate: Add certificate-bytes and private-key-bytes props
- Date: Mon, 6 Aug 2012 20:29:53 +0000 (UTC)
commit 541c985869fe9f2c0a858c0a91b4eb60f99d19f0
Author: Stef Walter <stefw gnome org>
Date: Mon Aug 6 18:20:48 2012 +0200
gtlscertificate: Add certificate-bytes and private-key-bytes props
* These properties contain the same data as certificate and
private-key, but as GBytes
https://bugzilla.gnome.org/show_bug.cgi?id=681319
gio/gdummytlsbackend.c | 4 +++
gio/gtlscertificate.c | 59 +++++++++++++++++++++++++++++++++++--------
gio/tests/gtesttlsbackend.c | 6 ++++
3 files changed, 58 insertions(+), 11 deletions(-)
---
diff --git a/gio/gdummytlsbackend.c b/gio/gdummytlsbackend.c
index 5a2463b..1abab7e 100644
--- a/gio/gdummytlsbackend.c
+++ b/gio/gdummytlsbackend.c
@@ -105,8 +105,10 @@ enum
PROP_CERTIFICATE_0,
PROP_CERT_CERTIFICATE,
+ PROP_CERT_CERTIFICATE_BYTES,
PROP_CERT_CERTIFICATE_PEM,
PROP_CERT_PRIVATE_KEY,
+ PROP_CERT_PRIVATE_KEY_BYTES,
PROP_CERT_PRIVATE_KEY_PEM,
PROP_CERT_ISSUER
};
@@ -148,8 +150,10 @@ g_dummy_tls_certificate_class_init (GDummyTlsCertificateClass *certificate_class
gobject_class->set_property = g_dummy_tls_certificate_set_property;
g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE, "certificate");
+ g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_BYTES, "certificate-bytes");
g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_PEM, "certificate-pem");
g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY, "private-key");
+ g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_BYTES, "private-key-bytes");
g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_PEM, "private-key-pem");
g_object_class_override_property (gobject_class, PROP_CERT_ISSUER, "issuer");
}
diff --git a/gio/gtlscertificate.c b/gio/gtlscertificate.c
index ea5f1df..cc5d2ee 100644
--- a/gio/gtlscertificate.c
+++ b/gio/gtlscertificate.c
@@ -58,8 +58,10 @@ enum
PROP_0,
PROP_CERTIFICATE,
+ PROP_CERTIFICATE_BYTES,
PROP_CERTIFICATE_PEM,
PROP_PRIVATE_KEY,
+ PROP_PRIVATE_KEY_BYTES,
PROP_PRIVATE_KEY_PEM,
PROP_ISSUER
};
@@ -99,8 +101,9 @@ g_tls_certificate_class_init (GTlsCertificateClass *class)
* GTlsCertificate:certificate:
*
* The DER (binary) encoded representation of the certificate.
- * This property and the #GTlsCertificate:certificate-pem property
- * represent the same data, just in different forms.
+ * This property and the #GTlsCertificate:certificate-bytes contain
+ * the same data. The #GTlsCertificate:certificate-pem property
+ * represents the same data, just in different forms.
*
* Since: 2.28
*/
@@ -113,11 +116,29 @@ g_tls_certificate_class_init (GTlsCertificateClass *class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
+ * GTlsCertificate:certificate-bytes:
+ *
+ * The DER (binary) encoded representation of the certificate as
+ * a #GBytes. The #GTlsCertificate:certificate property contains
+ * the same data. The #GTlsCertificate:certificate-pem property
+ * contains the same data as this property in a different form.
+ *
+ * Since: 2.34
+ */
+ g_object_class_install_property (gobject_class, PROP_CERTIFICATE_BYTES,
+ g_param_spec_boxed ("certificate-bytes",
+ P_("Certificate Bytes"),
+ P_("The DER representation of the certificate"),
+ G_TYPE_BYTES,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ /**
* GTlsCertificate:certificate-pem:
*
* The PEM (ASCII) encoded representation of the certificate.
- * This property and the #GTlsCertificate:certificate
- * property represent the same data, just in different forms.
+ * The #GTlsCertificate:certificate and #GTlsCertificate:certificate-bytes
+ * properties represent the same data, just in a different form.
*
* Since: 2.28
*/
@@ -153,6 +174,23 @@ g_tls_certificate_class_init (GTlsCertificateClass *class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
+ * GTlsCertificate:private-key-bytes:
+ *
+ * The DER (binary) encoded representation of the certificate's
+ * private key. This property and the #GtlsCertificate:private-key
+ * property contain the same data.
+ *
+ * Since: 2.34
+ */
+ g_object_class_install_property (gobject_class, PROP_PRIVATE_KEY_BYTES,
+ g_param_spec_boxed ("private-key-bytes",
+ P_("Private key bytes"),
+ P_("The DER representation of the certificate's private key"),
+ G_TYPE_BYTES,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ /**
* GTlsCertificate:private-key-pem:
*
* The PEM (ASCII) encoded representation of the certificate's
@@ -579,20 +617,19 @@ gboolean
g_tls_certificate_is_same (GTlsCertificate *cert_one,
GTlsCertificate *cert_two)
{
- GByteArray *b1, *b2;
+ GBytes *b1, *b2;
gboolean equal;
g_return_val_if_fail (G_IS_TLS_CERTIFICATE (cert_one), FALSE);
g_return_val_if_fail (G_IS_TLS_CERTIFICATE (cert_two), FALSE);
- g_object_get (cert_one, "certificate", &b1, NULL);
- g_object_get (cert_two, "certificate", &b2, NULL);
+ g_object_get (cert_one, "certificate-bytes", &b1, NULL);
+ g_object_get (cert_two, "certificate-bytes", &b2, NULL);
- equal = (b1->len == b2->len &&
- memcmp (b1->data, b2->data, b1->len) == 0);
+ equal = g_bytes_equal (b1, b2);
- g_byte_array_unref (b1);
- g_byte_array_unref (b2);
+ g_bytes_unref (b1);
+ g_bytes_unref (b2);
return equal;
}
diff --git a/gio/tests/gtesttlsbackend.c b/gio/tests/gtesttlsbackend.c
index d951bdf..e39f3c5 100644
--- a/gio/tests/gtesttlsbackend.c
+++ b/gio/tests/gtesttlsbackend.c
@@ -81,8 +81,10 @@ enum
PROP_CERTIFICATE_0,
PROP_CERT_CERTIFICATE,
+ PROP_CERT_CERTIFICATE_BYTES,
PROP_CERT_CERTIFICATE_PEM,
PROP_CERT_PRIVATE_KEY,
+ PROP_CERT_PRIVATE_KEY_BYTES,
PROP_CERT_PRIVATE_KEY_PEM,
PROP_CERT_ISSUER
};
@@ -133,7 +135,9 @@ g_test_tls_certificate_set_property (GObject *object,
cert->key_pem = g_value_dup_string (value);
break;
case PROP_CERT_CERTIFICATE:
+ case PROP_CERT_CERTIFICATE_BYTES:
case PROP_CERT_PRIVATE_KEY:
+ case PROP_CERT_PRIVATE_KEY_BYTES:
case PROP_CERT_ISSUER:
/* ignore */
break;
@@ -162,8 +166,10 @@ g_test_tls_certificate_class_init (GTestTlsCertificateClass *certificate_class)
gobject_class->finalize = g_test_tls_certificate_finalize;
g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE, "certificate");
+ g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_BYTES, "certificate-bytes");
g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_PEM, "certificate-pem");
g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY, "private-key");
+ g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_BYTES, "private-key-bytes");
g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_PEM, "private-key-pem");
g_object_class_override_property (gobject_class, PROP_CERT_ISSUER, "issuer");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]