diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-04-23 04:58:57 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-04-23 04:58:57 +0200 |
commit | 67abc395d981b9b4a5f71fc00a8807195e2865e3 (patch) | |
tree | 0a91d4cf9c8c3cef3d9668c2916798ec50803c39 /tests/setup.sh | |
parent | 6eafaf31325dd18404e942f453130dd7a6e92f77 (diff) | |
download | pass-67abc395d981b9b4a5f71fc00a8807195e2865e3.tar.gz pass-67abc395d981b9b4a5f71fc00a8807195e2865e3.tar.bz2 pass-67abc395d981b9b4a5f71fc00a8807195e2865e3.zip |
tests: add key resolution functions
Diffstat (limited to '')
-rwxr-xr-x | tests/setup.sh | 32 |
1 files changed, 32 insertions, 0 deletions
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: <key name>... +# 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: <gpg file> +# 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: <group> +# 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 |