summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-02-26 13:01:34 -0300
committerSilvio Rhatto <rhatto@riseup.net>2013-02-26 13:01:34 -0300
commit4153129f3ae06a7dca7085e05e278232bbb81d32 (patch)
tree01faf2714587cdf081a8e511d98f4eb8852597ca
parent67adc630f06c7779937a410f1d5925ad51f6e017 (diff)
downloadkeyringer-4153129f3ae06a7dca7085e05e278232bbb81d32.tar.gz
keyringer-4153129f3ae06a7dca7085e05e278232bbb81d32.tar.bz2
Recrypt only when decrypt is successful (#6)
-rwxr-xr-xshare/keyringer/decrypt3
-rwxr-xr-xshare/keyringer/recrypt10
2 files changed, 13 insertions, 0 deletions
diff --git a/share/keyringer/decrypt b/share/keyringer/decrypt
index adc1134..bab9b34 100755
--- a/share/keyringer/decrypt
+++ b/share/keyringer/decrypt
@@ -12,3 +12,6 @@ keyringer_get_file "$2"
# Decrypt
$GPG --quiet --use-agent -d "$KEYDIR/$FILE"
+
+# Exit
+exit "$?"
diff --git a/share/keyringer/recrypt b/share/keyringer/recrypt
index cbf1af9..fc16603 100755
--- a/share/keyringer/recrypt
+++ b/share/keyringer/recrypt
@@ -14,6 +14,16 @@ function keyringer_recrypt {
# Set recipients file
keyringer_set_recipients "$FILE"
+ # Test decryption
+ $GPG --use-agent -d "$KEYDIR/$FILE" > /dev/null
+
+ err="$?"
+
+ if [ "$err" != "0" ]; then
+ echo "$BASENAME: decryption failed. Can't recrypt."
+ exit "$err"
+ fi
+
# Recrypt
$GPG --use-agent -d "$KEYDIR/$FILE" | $GPG --use-agent --armor -e -s $(keyringer_recipients "$RECIPIENTS_FILE") > "$KEYDIR/$FILE"