From beeb450166dc460cda22bf144bfdfeb3808bdd64 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Sat, 11 Mar 2023 19:10:00 -0600 Subject: [PATCH] Add support for whole-keyring export to mock gpg tool --- testsuite/lib/exec/mockgpg | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/testsuite/lib/exec/mockgpg b/testsuite/lib/exec/mockgpg index 5ef15d2..7a23dff 100755 --- a/testsuite/lib/exec/mockgpg +++ b/testsuite/lib/exec/mockgpg @@ -228,14 +228,23 @@ case ${Command:?no command given} in export) # The mock keyring format simply lists the appropriate lines here. # The "files" are actually key IDs. - for keyid in "${Files[@]}"; do - [ ${#keyid} -gt 8 ] && keyid=${keyid:0-8} + if [ "${#Files[*]}" -gt 0 ]; then + for keyid in "${Files[@]}"; do + [ ${#keyid} -gt 16 ] && keyid=${keyid:0-16} + if [ x${OutputFile:+set} = xset ]; then + grep -h '^0*'"$keyid": "${Keyrings[@]}" > "$OutputFile" + else + grep -h '^0*'"$keyid": "${Keyrings[@]}" + fi + done + else + # Export everything if no keys are selected. if [ x${OutputFile:+set} = xset ]; then - grep -h '^0*'"$keyid": "${Keyrings[@]}" > "$OutputFile" + cat "${Keyrings[@]}" > "$OutputFile" else - grep -h '^0*'"$keyid": "${Keyrings[@]}" + cat "${Keyrings[@]}" fi - done + fi ;; delete-key) # This simply requires removing the indicated ID from all keyrings. -- 2.25.1