diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-07-18 13:31:57 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-18 13:31:57 -0700 |
commit | ba69ae876b0462831cab94e43d1e2876dce3e4cd (patch) | |
tree | a04c3e8737a33f6a4cd4ead29d63d26a5ffd6c3e /gpg-interface.c | |
parent | 7f8d098b1b1ca1e5b91b17d05b51bc5b7a7ad6bf (diff) | |
parent | 803978da494bf88ee60fb9598c94e25d601c5c32 (diff) |
Merge branch 'jd/gpg-interface-trust-level-string'
The code to convert between GPG trust level strings and internal
constants we use to represent them have been cleaned up.
* jd/gpg-interface-trust-level-string:
gpg-interface: add function for converting trust level to string
Diffstat (limited to 'gpg-interface.c')
-rw-r--r-- | gpg-interface.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/gpg-interface.c b/gpg-interface.c index 947b58ad4d..6dff241460 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -165,15 +165,17 @@ static struct { { 0, "TRUST_", GPG_STATUS_TRUST_LEVEL }, }; -static struct { +/* Keep the order same as enum signature_trust_level */ +static struct sigcheck_gpg_trust_level { const char *key; + const char *display_key; enum signature_trust_level value; } sigcheck_gpg_trust_level[] = { - { "UNDEFINED", TRUST_UNDEFINED }, - { "NEVER", TRUST_NEVER }, - { "MARGINAL", TRUST_MARGINAL }, - { "FULLY", TRUST_FULLY }, - { "ULTIMATE", TRUST_ULTIMATE }, + { "UNDEFINED", "undefined", TRUST_UNDEFINED }, + { "NEVER", "never", TRUST_NEVER }, + { "MARGINAL", "marginal", TRUST_MARGINAL }, + { "FULLY", "fully", TRUST_FULLY }, + { "ULTIMATE", "ultimate", TRUST_ULTIMATE }, }; static void replace_cstring(char **field, const char *line, const char *next) @@ -905,6 +907,20 @@ const char *get_signing_key(void) return git_committer_info(IDENT_STRICT | IDENT_NO_DATE); } +const char *gpg_trust_level_to_str(enum signature_trust_level level) +{ + struct sigcheck_gpg_trust_level *trust; + + if (level < 0 || level >= ARRAY_SIZE(sigcheck_gpg_trust_level)) + BUG("invalid trust level requested %d", level); + + trust = &sigcheck_gpg_trust_level[level]; + if (trust->value != level) + BUG("sigcheck_gpg_trust_level[] unsorted"); + + return sigcheck_gpg_trust_level[level].display_key; +} + int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key) { return use_format->sign_buffer(buffer, signature, signing_key); |