Skip to content

Commit 5c9266f

Browse files
committed
Only require xxd when absolutely required to support OpenSSL version 3+ #138
1 parent 029ba93 commit 5c9266f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

transcrypt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,20 @@ git_clean() {
139139
password=$(git config --get --local transcrypt.password)
140140
openssl_path=$(git config --get --local transcrypt.openssl-path)
141141
salt=$("${openssl_path}" dgst -hmac "${filename}:${password}" -sha256 "$tempfile" | tr -d '\r\n' | tail -c16)
142-
# Encrypt the file to base64, ensuring it always includes the prefix 'Salted__' with the salt. #133
143-
(
144-
# Always prepend encrypted ciphertext with "Salted__" prefix and binary salt value
145-
echo -n "Salted__" && echo -n "$salt" | xxd -r -p &&
146-
# Encrypt file to binary ciphertext
147-
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md MD5 -pass env:ENC_PASS -S "$salt" -in "$tempfile" |
148-
# Strip "Salted__" prefix and salt value if also added by OpenSSL (version < 3)
149-
LC_ALL=C sed -e "s/^\(Salted__.\{8\}\)\(.*\)/\2/"
150-
) |
151-
base64
142+
143+
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
144+
if [ "$openssl_major_version" -ge "3" ]; then
145+
# Encrypt the file to base64, ensuring it includes the prefix 'Salted__' with the salt. #133
146+
(
147+
echo -n "Salted__" && echo -n "$salt" | xxd -r -p &&
148+
# Encrypt file to binary ciphertext
149+
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md MD5 -pass env:ENC_PASS -S "$salt" -in "$tempfile"
150+
) |
151+
base64
152+
else
153+
# Encrypt file to base64 ciphertext
154+
ENC_PASS=$password "$openssl_path" enc -e -a "-${cipher}" -md MD5 -pass env:ENC_PASS -S "$salt" -in "$tempfile"
155+
fi
152156
fi
153157
}
154158

0 commit comments

Comments
 (0)