Skip to content

Commit 61a352d

Browse files
committed
Potential fix for unbound variable in MacOS (tests)
- Use `:+` bash parameter expansion to include pbkdf2 argument to openssl only if variable is set - Simplify variable `pbkdf2_arg` from list to string, since the `[@]` referencing doesn't work in all cases for MacOS (at least not for the unit tests): an empty list errors with `unbound variable`
1 parent c77f489 commit 61a352d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

transcrypt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ _openssl_encrypt() {
8181
(
8282
printf "Salted__" && printf "%s" "$final_salt" | xxd -r -p &&
8383
# Encrypt file to binary ciphertext
84-
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md "${digest}" -pass env:ENC_PASS -S "$final_salt" "${pbkdf2_args[@]}" -in "$tempfile"
84+
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md "${digest}" -pass env:ENC_PASS -S "$final_salt" ${pbkdf2_arg:+"$pbkdf2_arg"} -in "$tempfile"
8585
) |
8686
base64
8787
else
8888
# Encrypt file to base64 ciphertext
89-
ENC_PASS=$password "$openssl_path" enc -e -a "-${cipher}" -md "${digest}" -pass env:ENC_PASS -S "$final_salt" "${pbkdf2_args[@]}" -in "$tempfile"
89+
ENC_PASS=$password "$openssl_path" enc -e -a "-${cipher}" -md "${digest}" -pass env:ENC_PASS -S "$final_salt" ${pbkdf2_arg:+"$pbkdf2_arg"} -in "$tempfile"
9090
fi
9191
}
9292

9393
_openssl_decrypt() {
9494
# Expects that the following variables are set:
95-
# password, openssl_path, cipher, digest, pbkdf2_args
95+
# password, openssl_path, cipher, digest, pbkdf2_arg
9696
# This works the same across openssl versions
97-
ENC_PASS=$password "$openssl_path" enc -d "-${cipher}" -md "${digest}" -pass env:ENC_PASS -a "$@" "${pbkdf2_args[@]}"
97+
ENC_PASS=$password "$openssl_path" enc -d "-${cipher}" -md "${digest}" -pass env:ENC_PASS -a ${pbkdf2_arg:+"$pbkdf2_arg"} "$@"
9898
}
9999

100100
# compatible openssl list command
@@ -251,9 +251,7 @@ _load_vars_for_encryption() {
251251
_load_transcrypt_config_vars
252252

253253
if [[ "$kdf" == "1" ]] || [[ "$kdf" == "pbkdf2" ]]; then
254-
pbkdf2_args=('-pbkdf2')
255-
else
256-
pbkdf2_args=()
254+
pbkdf2_arg='-pbkdf2'
257255
fi
258256

259257
if [[ "$salt_method" == "password" ]]; then

0 commit comments

Comments
 (0)