[evolution-data-server] CamelCert: Change 'rawcert' from GByteArray to GBytes.



commit c120109c8880825776069a00852aa246ecdabde0
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Sep 25 17:09:28 2013 -0400

    CamelCert: Change 'rawcert' from GByteArray to GBytes.
    
    More efficient, and nicer when working with GIO streams.

 camel/camel-certdb.c         |    4 ++--
 camel/camel-certdb.h         |    2 +-
 camel/camel-tcp-stream-ssl.c |   29 +++++++++++++++--------------
 3 files changed, 18 insertions(+), 17 deletions(-)
---
diff --git a/camel/camel-certdb.c b/camel/camel-certdb.c
index 4e1fb8e..28ef193 100644
--- a/camel/camel-certdb.c
+++ b/camel/camel-certdb.c
@@ -294,8 +294,8 @@ camel_cert_unref (CamelCert *cert)
                g_free (cert->hostname);
                g_free (cert->fingerprint);
 
-               if (cert->rawcert)
-                       g_byte_array_free (cert->rawcert, TRUE);
+               if (cert->rawcert != NULL)
+                       g_bytes_unref (cert->rawcert);
 
                g_slice_free (CamelCert, cert);
        }
diff --git a/camel/camel-certdb.h b/camel/camel-certdb.h
index 0b94a50..bf8a851 100644
--- a/camel/camel-certdb.h
+++ b/camel/camel-certdb.h
@@ -80,7 +80,7 @@ typedef struct {
        gchar *fingerprint;
 
        CamelCertTrust trust;
-       GByteArray *rawcert;
+       GBytes *rawcert;
 } CamelCert;
 
 struct _CamelCertDB {
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c
index 3a55e9d..c467e57 100644
--- a/camel/camel-tcp-stream-ssl.c
+++ b/camel/camel-tcp-stream-ssl.c
@@ -187,6 +187,7 @@ camel_certdb_nss_cert_get (CamelCertDB *certdb,
 {
        gchar *fingerprint;
        CamelCert *ccert;
+       GBytes *bytes;
 
        fingerprint = cert_fingerprint (cert);
 
@@ -197,7 +198,6 @@ camel_certdb_nss_cert_get (CamelCertDB *certdb,
        }
 
        if (ccert->rawcert == NULL) {
-               GByteArray *array;
                gchar *filename;
                gchar *contents;
                gsize length;
@@ -224,21 +224,21 @@ camel_certdb_nss_cert_get (CamelCertDB *certdb,
                }
                g_free (filename);
 
-               array = g_byte_array_sized_new (length);
-               g_byte_array_append (array, (guint8 *) contents, length);
-               g_free (contents);
-
-               ccert->rawcert = array;
+               ccert->rawcert = g_bytes_new_take (contents, length);
        }
 
        g_free (fingerprint);
-       if (ccert->rawcert->len != cert->derCert.len
-           || memcmp (ccert->rawcert->data, cert->derCert.data, cert->derCert.len) != 0) {
+
+       bytes = g_bytes_new_static (cert->derCert.data, cert->derCert.len);
+
+       if (g_bytes_compare (bytes, ccert->rawcert) != 0) {
                g_warning ("rawcert != derCer");
                ccert->trust = CAMEL_CERT_TRUST_UNKNOWN;
                camel_certdb_touch (certdb);
        }
 
+       g_bytes_unref (bytes);
+
        return ccert;
 }
 
@@ -270,11 +270,10 @@ camel_certdb_nss_cert_set (CamelCertDB *certdb,
 
        fingerprint = ccert->fingerprint;
 
-       if (ccert->rawcert == NULL)
-               ccert->rawcert = g_byte_array_new ();
+       if (ccert->rawcert != NULL)
+               g_bytes_unref (ccert->rawcert);
 
-       g_byte_array_set_size (ccert->rawcert, cert->derCert.len);
-       memcpy (ccert->rawcert->data, cert->derCert.data, cert->derCert.len);
+       ccert->rawcert = g_bytes_new (cert->derCert.data, cert->derCert.len);
 
        cert_dir = tcp_stream_ssl_get_cert_dir ();
        filename = g_build_filename (cert_dir, fingerprint, NULL);
@@ -283,8 +282,10 @@ camel_certdb_nss_cert_set (CamelCertDB *certdb,
                filename, O_WRONLY | O_CREAT | O_TRUNC, 0600, NULL);
        if (stream != NULL) {
                if (camel_stream_write (
-                       stream, (const gchar *) ccert->rawcert->data,
-                       ccert->rawcert->len, NULL, NULL) == -1) {
+                       stream,
+                       g_bytes_get_data (ccert->rawcert, NULL),
+                       g_bytes_get_size (ccert->rawcert),
+                       NULL, NULL) == -1) {
                        g_warning (
                                "Could not save cert: %s: %s",
                                filename, g_strerror (errno));


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