From 67abc395d981b9b4a5f71fc00a8807195e2865e3 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 23 Apr 2014 04:58:57 +0200 Subject: tests: add key resolution functions --- tests/setup.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/setup.sh b/tests/setup.sh index df53943..b5729e4 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -29,6 +29,8 @@ fi export GNUPGHOME=$(pwd)"/gnupg/" chmod 700 "$GNUPGHOME" export PASSWORD_STORE_KEY="3DEEA12D" # "Password-store Test Key" +GPG="gpg" +which gpg2 &>/dev/null && GPG="gpg2" # We don't want to use any running agent. # We want an agent to appear to pass to be running. @@ -164,5 +166,35 @@ verify_password() { test_cmp "$expectedfile" "$actualfile" } +# canonicalize_gpg_keys() +# +# Resolves key names to key ids. +# +# Arguments: ... +# Returns: 0, and echos keys on new lines +canonicalize_gpg_keys() { + $GPG --list-keys --keyid-format long "$@" | sed -n 's/sub *.*\/\([A-F0-9]\{16\}\) .*/\1/p' | sort -u +} + +# gpg_keys_from_encrypted_file() +# +# Finds keys used to encrypt a .gpg file. +# +# Arguments: +# Returns 0, and echos keys on new lines +gpg_keys_from_encrypted_file() { + $GPG -v --list-only --keyid-format long "$1" 2>&1 | cut -d ' ' -f 5 | sort -u +} + +# gpg_keys_from_group() +# +# Finds keys used in gpg.conf group +# +# Arguments: +# Returns: 0, and echos keys on new lines, which might be non-canonical +gpg_keys_from_group() { + $GPG --list-config --with-colons | sed -n "s/^cfg:group:$1:\\(.*\\)/\\1/p" | tr ';' '\n' +} + # Initialize the test harness . ./sharness.sh -- cgit v1.2.3