summaryrefslogtreecommitdiff
path: root/gcr
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2022-07-06 09:57:11 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2022-07-07 13:40:25 +0200
commit8927be67708f5b8fcb66e3d65b2de4b8fe77b236 (patch)
tree00a2a9ef54cad54d797402f92b923ce8c7fd2ecb /gcr
parent8f8926a0fa911ba9b4a299966f1c097b8954ca2b (diff)
downloadgcr-8927be67708f5b8fcb66e3d65b2de4b8fe77b236.tar.gz
Use GDateTime instead of GDate
... and remove some functions that still use `time_t`
Diffstat (limited to 'gcr')
-rw-r--r--gcr/gcr-certificate.c34
-rw-r--r--gcr/gcr-certificate.h4
-rw-r--r--gcr/test-certificate.c22
3 files changed, 20 insertions, 40 deletions
diff --git a/gcr/gcr-certificate.c b/gcr/gcr-certificate.c
index 3e83927..13b2379 100644
--- a/gcr/gcr-certificate.c
+++ b/gcr/gcr-certificate.c
@@ -273,7 +273,7 @@ gcr_certificate_default_init (GcrCertificateIface *iface)
*/
g_object_interface_install_property (iface,
g_param_spec_boxed ("expiry-date", "Expiry date", "Certificate expiry date",
- G_TYPE_DATE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ G_TYPE_DATE_TIME, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_once_init_leave (&initialized, 1);
}
@@ -687,16 +687,12 @@ gcr_certificate_get_subject_raw (GcrCertificate *self, gsize *n_data)
*
* Get the issued date of this certificate.
*
- * The #GDate returned should be freed by the caller using
- * g_date_free() when no longer required.
- *
- * Returns: (nullable): An allocated issued date of this certificate.
+ * Returns: (nullable): A issued date of this certificate.
*/
-GDate*
+GDateTime *
gcr_certificate_get_issued_date (GcrCertificate *self)
{
GcrCertificateInfo *info;
- GDate *date;
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
@@ -704,13 +700,7 @@ gcr_certificate_get_issued_date (GcrCertificate *self)
if (info == NULL)
return NULL;
- date = g_date_new ();
- if (!egg_asn1x_get_time_as_date (egg_asn1x_node (info->asn1, "tbsCertificate", "validity", "notBefore", NULL), date)) {
- g_date_free (date);
- return NULL;
- }
-
- return date;
+ return egg_asn1x_get_time_as_date_time (egg_asn1x_node (info->asn1, "tbsCertificate", "validity", "notBefore", NULL));
}
/**
@@ -719,16 +709,12 @@ gcr_certificate_get_issued_date (GcrCertificate *self)
*
* Get the expiry date of this certificate.
*
- * The #GDate returned should be freed by the caller using
- * g_date_free() when no longer required.
- *
- * Returns: (nullable): An allocated expiry date of this certificate.
+ * Returns: (nullable): An expiry date of this certificate.
*/
-GDate*
+GDateTime *
gcr_certificate_get_expiry_date (GcrCertificate *self)
{
GcrCertificateInfo *info;
- GDate *date;
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
@@ -736,13 +722,7 @@ gcr_certificate_get_expiry_date (GcrCertificate *self)
if (info == NULL)
return NULL;
- date = g_date_new ();
- if (!egg_asn1x_get_time_as_date (egg_asn1x_node (info->asn1, "tbsCertificate", "validity", "notAfter", NULL), date)) {
- g_date_free (date);
- return NULL;
- }
-
- return date;
+ return egg_asn1x_get_time_as_date_time (egg_asn1x_node (info->asn1, "tbsCertificate", "validity", "notAfter", NULL));
}
/**
diff --git a/gcr/gcr-certificate.h b/gcr/gcr-certificate.h
index 444b2f5..ab65026 100644
--- a/gcr/gcr-certificate.h
+++ b/gcr/gcr-certificate.h
@@ -102,9 +102,9 @@ gchar* gcr_certificate_get_subject_part (GcrCertificate *self
guchar * gcr_certificate_get_subject_raw (GcrCertificate *self,
gsize *n_data);
-GDate* gcr_certificate_get_issued_date (GcrCertificate *self);
+GDateTime * gcr_certificate_get_issued_date (GcrCertificate *self);
-GDate* gcr_certificate_get_expiry_date (GcrCertificate *self);
+GDateTime * gcr_certificate_get_expiry_date (GcrCertificate *self);
guchar* gcr_certificate_get_serial_number (GcrCertificate *self,
gsize *n_length);
diff --git a/gcr/test-certificate.c b/gcr/test-certificate.c
index 2fed913..8bca034 100644
--- a/gcr/test-certificate.c
+++ b/gcr/test-certificate.c
@@ -174,23 +174,23 @@ test_subject_raw (Test *test, gconstpointer unused)
static void
test_issued_date (Test *test, gconstpointer unused)
{
- GDate *date = gcr_certificate_get_issued_date (test->certificate);
- g_assert (date);
- g_assert_cmpuint (g_date_get_year (date), ==, 1999);
- g_assert_cmpuint (g_date_get_month (date), ==, 6);
- g_assert_cmpuint (g_date_get_day (date), ==, 26);
- g_date_free (date);
+ GDateTime *date = gcr_certificate_get_issued_date (test->certificate);
+ g_assert_nonnull (date);
+ g_assert_cmpuint (g_date_time_get_year (date), ==, 1999);
+ g_assert_cmpuint (g_date_time_get_month (date), ==, 6);
+ g_assert_cmpuint (g_date_time_get_day_of_month (date), ==, 26);
+ g_date_time_unref (date);
}
static void
test_expiry_date (Test *test, gconstpointer unused)
{
- GDate *date = gcr_certificate_get_expiry_date (test->certificate);
+ GDateTime *date = gcr_certificate_get_expiry_date (test->certificate);
g_assert (date);
- g_assert_cmpuint (g_date_get_year (date), ==, 2019);
- g_assert_cmpuint (g_date_get_month (date), ==, 6);
- g_assert_cmpuint (g_date_get_day (date), ==, 26);
- g_date_free (date);
+ g_assert_cmpuint (g_date_time_get_year (date), ==, 2019);
+ g_assert_cmpuint (g_date_time_get_month (date), ==, 6);
+ g_assert_cmpuint (g_date_time_get_day_of_month (date), ==, 26);
+ g_date_time_unref (date);
}
static void