gpg: Add ostree_gpg_verify_result_describe_variant()

Needed for printing signature details in places where
OstreeGpgVerifyResult cannot go.
This commit is contained in:
Matthew Barnes 2015-05-05 17:41:13 -04:00
parent 4a3c2a25b7
commit 83aac088d1
3 changed files with 41 additions and 4 deletions

View File

@ -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

View File

@ -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,

View File

@ -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