fi
}
+# import_key <keyfile> <keyring>
+function import_key() {
+ [ -f "$1" ] || return
+ KRTmpFile=mockgpg-import.$$
+ cat "$1" >> "$2"
+ sort -u -t : -k 1 -k 2 -k 4 -o "$2" "$2"
+ awk -F: 'BEGIN { OFS = FS }
+ $2 == "R" { RevKeyID = $1 }
+ $1 == RevKeyID { $2 = "R" }
+ { print }' "$2" > "$KRTmpFile"
+ sort -u -t : -k 1 -k 4 -o "$2" "$KRTmpFile"
+ rm -f "$KRTmpFile"
+}
+
case ${Command:?no command given} in
import)
# The mock keyring format is such that import is accomplished by
if [ "${#Files[*]}" -gt 0 ]; then
for file in "${Files[@]}"; do
for keyring in "${Keyrings[@]}"; do
- [ -f "$file" ] && cat "$file" >>"$keyring"
+ import_key "$file" "$keyring"
done
done
else
TmpFile=mockgpg-scratchpad.$$
cat >"$TmpFile"
for keyring in "${Keyrings[@]}"; do
- cat "$TmpFile" >>"$keyring"
+ import_key "$TmpFile" "$keyring"
done
rm -f "$TmpFile"
fi
{ id 1002 name {test 1-2} }
}
+run_gpg [testfile K1.gpg] --import [testfile k1a.pgp]
+
+check_test_keyring "duplicate import" [testfile K1.gpg] {
+ { id 1001 name {test 1-1} }
+ { id 1002 name {test 1-2} }
+}
+
+write_test_keyring [testfile k1a1.pgp] {
+ { id 1001 name {test 1-1a} }
+}
+
+run_gpg [testfile K1.gpg] --import [testfile k1a1.pgp]
+
+check_test_keyring "merge import" [testfile K1.gpg] {
+ { id 1001 name {test 1-1} }
+ { id 1001 name {test 1-1a} }
+ { id 1002 name {test 1-2} }
+}
+
+write_test_keyring [testfile k1b1.pgp] {
+ { id 1002 name {test 1-2} is revoked }
+}
+
+run_gpg [testfile K1.gpg] --import [testfile k1b1.pgp]
+
+check_test_keyring "import revocation certificate" [testfile K1.gpg] {
+ { id 1001 name {test 1-1} }
+ { id 1001 name {test 1-1a} }
+ { id 1002 name {test 1-2} is revoked }
+}
+
+write_test_keyring [testfile k1c.pgp] {
+ { id 1003 name {test 1-3} }
+ { id 1004 name {test 1-4} }
+}
+
+write_test_keyring [testfile k1c1.pgp] {
+ { id 1003 name {test 1-3r} is revoked }
+}
+
+run_gpg [testfile K1.gpg] --import [testfile k1c.pgp]
+run_gpg [testfile K1.gpg] --import [testfile k1c1.pgp]
+
+check_test_keyring "import revocation merge" [testfile K1.gpg] {
+ { id 1001 name {test 1-1} }
+ { id 1001 name {test 1-1a} }
+ { id 1002 name {test 1-2} is revoked }
+ { id 1003 name {test 1-3} is revoked }
+ { id 1003 name {test 1-3r} is revoked }
+ { id 1004 name {test 1-4} }
+}
+
#
write_test_keyring [testfile K2.gpg] {