Rather than messy sed invocations
+function keyline() {
+ awk -vline="$1" 'NR == line' "$keyfile"
+}
+
+function keyfield() {
+ awk -vline="$1" -vfield="$2" 'NR == line { print $field }' "$keyfile"
+}
+
function go() {
layer=$1
if (( layer == 0 || layer > num_layers ));then
cat
else
function go() {
layer=$1
if (( layer == 0 || layer > num_layers ));then
cat
else
- operation=$(sed -n "${layer}{;s/ .*//;p;}" "$keyfile")
+ operation=$(keyfield "$layer" 1)
if [[ "$operation" == openssl-enc ]];then
if [[ "$operation" == openssl-enc ]];then
- openssl enc $openssl_decrypt "-$(sed -rn "${layer}s/[^ ]+ ([^ ]+) .*/\\1/p" "$keyfile")" \
- -nosalt -pass fd:37 37< <(sed -rn "${layer}s/^[^ ]+ [^ ]+ //p" "$keyfile")
+ openssl enc $openssl_decrypt "-$(keyfield "$layer" 2)" \
+ -nosalt -pass fd:37 37< <(keyfield "$layer" 3)
elif [[ "$operation" == reverse ]];then
elif [[ "$operation" == reverse ]];then
+ "$(dirname "$0")/reverse"
elif [[ "$operation" == openssl-dgst ]];then
elif [[ "$operation" == openssl-dgst ]];then
- tee >(echo "$(sed -n "${layer}p" "$keyfile") $(
+ tee >(echo "$(keyline "$layer") $(
- awk -vlayer="$layer" 'NR == layer { print $3 }' "$keyfile" | base64 -d
+ keyfield "$layer" 3 | base64 -d
- awk -vlayer="$layer" 'NR == layer { print $4 }' "$keyfile" | base64 -d
+ keyfield "$layer" 4 | base64 -d
- openssl dgst -binary "-$(sed -rn "${layer}s/^[^ ]+ ([^ ]+).*/\\1/p" "$keyfile")" |
+ openssl dgst -binary "-$(keyfield "$layer" 2)" |
base64 --wrap=0)" > "$hash_dir/$layer")
else
die "Unknown operation"
base64 --wrap=0)" > "$hash_dir/$layer")
else
die "Unknown operation"