@@ -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
@@ -305,6 +309,12 @@ run_safety_checks() {
305309 for cmd in {column,grep,mktemp," ${openssl_path} " ,sed,tee}; do
306310 command -v " $cmd " > /dev/null || die ' required command "%s" was not found' " $cmd "
307311 done
312+ # check for extra `xxd` dependency when running against OpenSSL version 3+
313+ openssl_major_version=$( $openssl_path version | cut -d' ' -f2 | cut -d' .' -f1)
314+ if [ " $openssl_major_version " -ge " 3" ]; then
315+ cmd=" xxd"
316+ command -v " $cmd " > /dev/null || die ' required command "%s" was not found' " $cmd "
317+ fi
308318
309319 # ensure the repository is clean (if it has a HEAD revision) so we can force
310320 # checkout files without the destruction of uncommitted changes
0 commit comments