pashage

Yet Another Opinionated Re-engineering of the Unix Password Store
git clone https://git.instinctive.eu/pashage.git
Log | Files | Refs | README | LICENSE

commit c52ac5c603f3f2340404b044e0eb996d93c13f2c
parent f8e2d7ebaccbe7807927a1798f5f56063a6e3879
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Tue, 15 Oct 2024 18:37:21 +0000

Positional arguments in mock encryption are properly escaped
Diffstat:
Mspec/support/bin/mock-age | 26+++++++++++++-------------
Mspec/support/bin/mock-gpg | 18+++++++++---------
2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/spec/support/bin/mock-age b/spec/support/bin/mock-age @@ -10,15 +10,15 @@ die() { case "$1" in -e) shift - MOCK_AGE_OUTPUT="$(@mktemp "$(dirname "$2")/mock-age-encrypt.XXXXXXX")" + MOCK_AGE_OUT="$(@mktemp -- "$(dirname "$2")/mock-age-encrypt.XXXXXXX")" DEST='-' while [ $# -gt 0 ]; do case "$1" in -R|-i) - @sed 's/^/ageRecipient:/' "$2" >>"${MOCK_AGE_OUTPUT}" + @sed -- 's/^/ageRecipient:/' "$2" >>"${MOCK_AGE_OUT}" shift 2 ;; -r) - printf 'ageRecipient:%s\n' "$2" >>"${MOCK_AGE_OUTPUT}" + printf 'ageRecipient:%s\n' "$2" >>"${MOCK_AGE_OUT}" shift 2 ;; -o) DEST="$2" @@ -33,16 +33,16 @@ case "$1" in if [ $# -gt 1 ]; then die "Unexpected arguments to age -e [...] $*\n" elif [ $# -eq 1 ]; then - @sed 's/^/age:/' "$1" >>"${MOCK_AGE_OUTPUT}" + @sed -- 's/^/age:/' "$1" >>"${MOCK_AGE_OUT}" else - @sed 's/^/age:/' >>"${MOCK_AGE_OUTPUT}" + @sed 's/^/age:/' >>"${MOCK_AGE_OUT}" fi if [ "${DEST}" = '-' ]; then - @cat "${MOCK_AGE_OUTPUT}" - @rm -f "${MOCK_AGE_OUTPUT}" + @cat -- "${MOCK_AGE_OUT}" + @rm -f -- "${MOCK_AGE_OUT}" else - @mv -f "${MOCK_AGE_OUTPUT}" "${DEST}" + @mv -f -- "${MOCK_AGE_OUT}" "${DEST}" fi ;; -d) @@ -54,19 +54,19 @@ case "$1" in fi [ "$1" = '-i' ] || die "Unexpected age -d arg: \"$1\"" MOCK_AGE_ID_SRC="$2" - MOCK_AGE_ID="$(@cat "$2")" + MOCK_AGE_ID="$(@cat -- "$2")" shift 2 [ "$1" = '--' ] && shift [ $# -eq 1 ] || die "Too many age -d arguments ($#): $*" - @grep -v '^age' "$1" >&2 && die "Bad encrypted file \"$1\"" - if ! @grep -qFx "ageRecipient:${MOCK_AGE_ID}" "$1"; then + @grep -v -- '^age' "$1" >&2 && die "Bad encrypted file \"$1\"" + if ! @grep -qFx -- "ageRecipient:${MOCK_AGE_ID}" "$1"; then die "Bad identity \"${MOCK_AGE_ID_SRC}\": ${MOCK_AGE_ID}" exit 1 fi if [ "${DEST}" = '-' ]; then - @sed -n 's/^age://p' "$1" + @sed -n -- 's/^age://p' "$1" else - @sed -n 's/^age://p' "$1" >|"${DEST}" + @sed -n -- 's/^age://p' "$1" >|"${DEST}" fi ;; *) diff --git a/spec/support/bin/mock-gpg b/spec/support/bin/mock-gpg @@ -16,12 +16,12 @@ check_eq() { case "$1" in -e) shift - MOCK_AGE_OUTPUT="$(@mktemp "$(dirname "$2")/mock-gpg-encrypt.XXXXXXX")" + MOCK_AGE_OUT="$(@mktemp -- "$(dirname "$2")/mock-gpg-encrypt.XXXXXXX")" DEST='-' while [ $# -gt 0 ]; do case "$1" in -r) - printf 'gpgRecipient:%s\n' "$2" >>"${MOCK_AGE_OUTPUT}" + printf 'gpgRecipient:%s\n' "$2" >>"${MOCK_AGE_OUT}" shift 2 ;; -o) DEST="$2" @@ -40,15 +40,15 @@ case "$1" in check_eq "$3" '--compress-algo=none' "Unexpected gpg -e \$3: \"$3\"" check_eq "$4" '--no-encrypt-to' "Unexpected gpg -e \$4: \"$4\"" if [ $# -eq 5 ]; then - @sed 's/^/gpg:/' "$5" >>"${MOCK_AGE_OUTPUT}" + @sed -- 's/^/gpg:/' "$5" >>"${MOCK_AGE_OUT}" else - @sed 's/^/gpg:/' >>"${MOCK_AGE_OUTPUT}" + @sed 's/^/gpg:/' >>"${MOCK_AGE_OUT}" fi if [ "${DEST}" = '-' ]; then - @cat "${MOCK_AGE_OUTPUT}" - @rm -f "${MOCK_AGE_OUTPUT}" + @cat -- "${MOCK_AGE_OUT}" + @rm -f -- "${MOCK_AGE_OUT}" else - @mv -f "${MOCK_AGE_OUTPUT}" "${DEST}" + @mv -f -- "${MOCK_AGE_OUT}" "${DEST}" fi ;; -d) @@ -64,9 +64,9 @@ case "$1" in check_eq "$4" '--no-encrypt-to' "Unexpected gpg -d \$4: \"$4\"" @grep -v '^gpg' "$5" >&2 && die "Bad encrypted file \"$5\"" if [ "${OUTPUT}" = '-' ]; then - @sed -n 's/^gpg://p' "$5" + @sed -n -- 's/^gpg://p' "$5" else - @sed -n 's/^gpg://p' "$5" >|"${OUTPUT}" + @sed -n -- 's/^gpg://p' "$5" >|"${OUTPUT}" fi ;; --list-config)