]> git.scottworley.com Git - overonion/commitdiff
keyline() and keyfield() operations master
authorScott Worley <scottworley@scottworley.com>
Tue, 24 Oct 2017 13:49:52 +0000 (06:49 -0700)
committerScott Worley <scottworley@scottworley.com>
Tue, 24 Oct 2017 13:49:52 +0000 (06:49 -0700)
Rather than messy sed invocations

overonion

index e7634e20314f6524a558dbd30df01fbcf0014e47..50d1958e5f2c03a85185222d201a53e9bee046f9 100755 (executable)
--- a/overonion
+++ b/overonion
@@ -47,25 +47,33 @@ else
   fi
 fi
 
   fi
 fi
 
+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
-      reverse
+      "$(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
               cat
               cat
-              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"