From: Jacob Bachmeyer Date: Sun, 12 Mar 2023 01:10:00 +0000 (-0600) Subject: Add support for whole-keyring export to mock gpg tool X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=beeb450166dc460cda22bf144bfdfeb3808bdd64;p=gatekeeper.git Add support for whole-keyring export to mock gpg tool --- 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.