-
Notifications
You must be signed in to change notification settings - Fork 0
/
oa8verify
executable file
·143 lines (129 loc) · 3.05 KB
/
oa8verify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env sh
# vim: filetype=sh:tabstop=4:tw=80
# shellcheck disable=SC2097,SC2098
set -e > /dev/null 2>&1
set -u > /dev/null 2>&1
me=oa8verify
vers=1.1.1
osl=openssl
a85=ascii85
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 env \
"${osl:?}" version > /dev/null 2>&1; then
printf '%s\n' \
"Error: ${osl:?} could not be executed" >&2
exit 1
fi
exitstatus=""
command env "${a85:?}" -h > /dev/null 2>&1
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
elif [ "${exitstatus:-}" -ne 0 ]; then
printf '%s\n' \
"Error: ${a85:?} failure ${exitstatus:-}" >&2
exit 1
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: