Add support for whole-keyring export to mock gpg tool
authorJacob Bachmeyer <jcb@gnu.org>
Sun, 12 Mar 2023 01:10:00 +0000 (19:10 -0600)
committerJacob Bachmeyer <jcb@gnu.org>
Sun, 12 Mar 2023 01:10:00 +0000 (19:10 -0600)
testsuite/lib/exec/mockgpg

index 5ef15d270d72846ceabb294b3359dd7cddf94a5c..7a23dff4d8cff2357eb1d6fc55de36a10d26b5b2 100755 (executable)
@@ -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.