-
Notifications
You must be signed in to change notification settings - Fork 13
/
asn1
executable file
·67 lines (60 loc) · 1.2 KB
/
asn1
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
#!/usr/bin/env bash
# asn1 -- convenience wrapper for dumpasn1
#
# The dumpasn1 tool doesn't base64-decode input on its own, and won't
# completely decode unseekable input such as stdin or pipes.
. lib.bash || exit
options=()
inputs=()
waitarg=0
optend=0
for arg; do
if (( optend )); then
inputs+=("$arg")
elif (( waitarg )); then
options+=("$arg")
waitarg=0
elif [[ $arg == -[cfwm] ]]; then
options+=("$arg")
waitarg=1
elif [[ $arg == -- ]]; then
options+=("$arg")
optend=1
elif [[ $arg == -[!-]* ]]; then
options+=("$arg")
elif [[ $arg == --help ]]; then
dumpasn1 --help
exit 0
else
inputs+=("$arg")
fi
done
if (( ! ${#inputs[@]} )); then
if [[ -t 0 ]]; then
vdie "no input files"
fi
inputs+=("-")
fi
r=0
for arg in "${inputs[@]}"; do
tmp=()
if [[ $arg == "-" ]]; then
buf=$(mktemp /tmp/asn1.XXXXXXXX)
tmp+=("$buf")
cat > "$buf"
arg=$buf
fi
if grep -qs "^-----" "$arg"; then
raw=$(mktemp /tmp/asn1.XXXXXXXX)
tmp+=("$raw")
sed -n '/^-----BEGIN .*-----/,/^-----END .*-----/ {
s/\r//g; /^[A-Za-z0-9+/=]*$/p
}' "$arg" | base64 -d > "$raw"
arg=$raw
fi
dumpasn1 "${options[@]}" -- "$arg" || r=1
if (( ${#tmp[@]} )); then
rm -f "${tmp[@]}"
fi
done
exit $r