123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #!/usr/bin/env sh
- # vim: filetype=sh:tabstop=4:tw=80
- set -e > /dev/null 2>&1
- set -u > /dev/null 2>&1
- me=oa8verify
- vers=1.1.1
- osl=openssl
- a85=ascii85
- # shellcheck disable=SC2097,SC2098
- if ! PATH="$(command -p env -i \
- getconf PATH)" \
- command -p env -i TMPDIR="${TMPDIR:-}" PATH="${PATH:-}" \
- rm -f \
- "$(command -p env -i TMPDIR="${TMPDIR:-}" mktemp)"; then
- printf '%s\n' \
- "Error: Misbehaving shell or environment; aborting" >&2
- exit 1
- fi
- cleanup() {
- command -p env -i \
- rm -f \
- "${tmpfile:-}" ||
- true
- }
- filename=${1:-}
- signature=${2:-}
- publickey=${3:-}
- exitstatus=""
- if ! command -p env \
- "${osl:?}" version > /dev/null 2>&1; then
- printf '%s\n' \
- "Error: ${osl:?} could not be executed" >&2
- exit 1
- fi
- exitstatus=""
- if ! command -p env \
- "${a85:?}" -h > /dev/null 2>&1; then
- exitstatus="${?:?Error: exitstatus undefined}"
- if [ "${exitstatus:-}" -eq 126 ]; then
- printf '%s\n' \
- "Error: ${a85:?} could not be executed" >&2
- exit 1
- elif [ "${exitstatus:-}" -eq 127 ]; then
- printf '%s\n' \
- "Error: ${a85:?} could not be found" >&2
- printf '\t%s\n' \
- 'Suggestion: "gem install Ascii85"' >&2
- exit 1
- else
- printf '%s\n' \
- "Error: ${a85:?} failure ${exitstatus:-}" >&2
- exit 1
- fi
- fi
- if [ ${#} -lt 3 ]; then
- printf '%s\n' \
- "*** ${me:?Error: me undefined} (v${vers:?Error: vers undefined})"
- printf '\t%s\n' \
- "Usage: ${me:?} <file> <signature.oa8> <public.oa8>"
- exit 1
- fi
- tmpfile=""
- tmpfile="$(command -p env -i TMPDIR="${TMPDIR:-}" \
- mktemp)" ||
- {
- printf '%s\n' \
- "Error: mktemp failure" >&2
- exit 1
- }
- exitstatus=""
- command -p env \
- "${a85:?}" -d \
- < "${signature:?Error: signature undefined}" \
- > "${tmpfile:?Error: tmpfile undefined}" ||
- {
- exitstatus="${?:?Error: exitstatus undefined}"
- if [ "${exitstatus:-}" -eq 126 ]; then
- printf '%s\n' \
- "Error: ${a85:?} could not be executed" >&2
- cleanup
- exit 1
- elif [ "${exitstatus:-}" -eq 127 ]; then
- printf '%s\n' \
- "Error: ${a85:?} could not be found" >&2
- printf '\t%s\n' \
- 'Suggestion: "gem install Ascii85"' >&2
- cleanup
- exit 1
- else
- printf '%s\n' \
- "Error: signature parsing failure ${exitstatus:-}" \
- >&2
- cleanup
- exit 3
- fi
- }
- exitstatus=""
- command -p env \
- "${osl:?}" dgst -sha3-512 \
- -verify "${publickey:?Error: publickey undefined}" \
- -signature "${tmpfile:?Error: tmpfile undefined}" \
- "${filename:?Error filename undefined}" ||
- {
- exitstatus="${?:?Error: exitstatus undefined}"
- if [ "${exitstatus:-}" -eq 126 ]; then
- printf '%s\n' \
- "Error: ${osl:?} could not be executed" >&2
- cleanup
- exit 1
- elif [ "${exitstatus:-}" -eq 127 ]; then
- printf '%s\n' \
- "Error: ${osl:?} could not be found" >&2
- cleanup
- exit 1
- else
- printf '%s\n' \
- "Error: ${me:?} failure ${exitstatus:-}" \
- >&2
- cleanup
- exit 2
- fi
- }
- cleanup
- # Local Variables:
- # mode: sh
- # sh-shell: sh
- # sh-indentation: 4
- # sh-basic-offset: 4
- # tab-width: 4
- # End:
|