[ostree] gpg: Add ostree_gpg_verify_result_describe_variant()



commit 83aac088d1e28c3c56e6595ba1fb8ed531059393
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue May 5 17:41:13 2015 -0400

    gpg: Add ostree_gpg_verify_result_describe_variant()
    
    Needed for printing signature details in places where
    OstreeGpgVerifyResult cannot go.

 doc/ostree-sections.txt                  |    1 +
 src/libostree/ostree-gpg-verify-result.c |   39 ++++++++++++++++++++++++++---
 src/libostree/ostree-gpg-verify-result.h |    5 ++++
 3 files changed, 41 insertions(+), 4 deletions(-)
---
diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt
index b75efc9..b1b86f0 100644
--- a/doc/ostree-sections.txt
+++ b/doc/ostree-sections.txt
@@ -176,6 +176,7 @@ ostree_gpg_verify_result_get
 ostree_gpg_verify_result_get_all
 OstreeGpgSignatureFormatFlags
 ostree_gpg_verify_result_describe
+ostree_gpg_verify_result_describe_variant
 <SUBSECTION Standard>
 OSTREE_GPG_VERIFY_RESULT
 OSTREE_IS_GPG_VERIFY_RESULT
diff --git a/src/libostree/ostree-gpg-verify-result.c b/src/libostree/ostree-gpg-verify-result.c
index f1560a7..6a2d869 100644
--- a/src/libostree/ostree-gpg-verify-result.c
+++ b/src/libostree/ostree-gpg-verify-result.c
@@ -480,11 +480,40 @@ ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
                                    OstreeGpgSignatureFormatFlags flags)
 {
   g_autoptr(GVariant) variant = NULL;
+
+  g_return_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result));
+
+  variant = ostree_gpg_verify_result_get_all (result, signature_index);
+
+  ostree_gpg_verify_result_describe_variant (variant, output_buffer, line_prefix, flags);
+}
+
+/**
+ * ostree_gpg_verify_result_describe_variant:
+ * @variant: a #GVariant from ostree_gpg_verify_result_get_all()
+ * @output_buffer: a #GString to hold the description
+ * @line_prefix: (allow-none): optional line prefix string
+ * @flags: flags to adjust the description format
+ *
+ * Similar to ostree_gpg_verify_result_describe() but takes a #GVariant of
+ * all attributes for a GPG signature instead of an #OstreeGpgVerifyResult
+ * and signature index.
+ *
+ * The @variant <emphasis>MUST</emphasis> have been created by
+ * ostree_gpg_verify_result_get_all().
+ */
+void
+ostree_gpg_verify_result_describe_variant (GVariant *variant,
+                                           GString *output_buffer,
+                                           const gchar *line_prefix,
+                                           OstreeGpgSignatureFormatFlags flags)
+{
   g_autoptr(GDateTime) date_time_utc = NULL;
   g_autoptr(GDateTime) date_time_local = NULL;
   g_autofree char *formatted_date_time = NULL;
   gint64 timestamp;
   gint64 exp_timestamp;
+  const char *type_string;
   const char *fingerprint;
   const char *pubkey_algo;
   const char *user_name;
@@ -495,16 +524,18 @@ ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
   gboolean key_missing;
   gsize len;
 
-  g_return_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result));
+  g_return_if_fail (variant != NULL);
   g_return_if_fail (output_buffer != NULL);
 
+  /* Verify the variant's type string.  This code is
+   * not prepared to handle just any random GVariant. */
+  type_string = g_variant_get_type_string (variant);
+  g_return_if_fail (strcmp (type_string, "(bbbbbsxxssss)") == 0);
+
   /* The default format roughly mimics the verify output generated by
    * check_sig_and_print() in gnupg/g10/mainproc.c, though obviously
    * greatly simplified. */
 
-  variant = ostree_gpg_verify_result_get_all (result, signature_index);
-  g_return_if_fail (variant != NULL);
-
   g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_VALID,
                        "b", &valid);
   g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED,
diff --git a/src/libostree/ostree-gpg-verify-result.h b/src/libostree/ostree-gpg-verify-result.h
index a380ce9..ce20718 100644
--- a/src/libostree/ostree-gpg-verify-result.h
+++ b/src/libostree/ostree-gpg-verify-result.h
@@ -119,4 +119,9 @@ void ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
                                         const gchar *line_prefix,
                                         OstreeGpgSignatureFormatFlags flags);
 
+void ostree_gpg_verify_result_describe_variant (GVariant *variant,
+                                                GString *output_buffer,
+                                                const gchar *line_prefix,
+                                                OstreeGpgSignatureFormatFlags flags);
+
 G_END_DECLS


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