aboutsummaryrefslogtreecommitdiff
path: root/lib/base64.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-12-30 19:04:34 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-12-30 19:04:45 -0800
commit8a3c32408733a2f5e14f8a2dbafa3f980b2f73a1 (patch)
tree68f1e8a8b956c33ed24cc7a6a369fd97b8849321 /lib/base64.nom
parent359152da1772ce501609edd8f84b4985ed3e42f2 (diff)
Update to new syntax.
Diffstat (limited to 'lib/base64.nom')
-rw-r--r--lib/base64.nom44
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/base64.nom b/lib/base64.nom
index 6f22afc..44d68cb 100644
--- a/lib/base64.nom
+++ b/lib/base64.nom
@@ -1,17 +1,17 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
This file defines actions for encoding/decoding base 64, as specified in:
https://tools.ietf.org/html/rfc4648
$b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-$b64_chars = [: for $ in 1 to (size of $b64_str): add ($b64_str|character $)]
+$b64_chars = [: for $ in 1 to (size of $b64_str): add ($b64_str, character $)]
$reverse_b64 = {: for $c in $b64_chars at $i: add $c = ($i - 1)}
$reverse_b64."=" = 64
-set $reverse_b64's metatable to {__index: -> 0}
+set $reverse_b64's metatable to {.__index = (-> 0)}
test:
$cases = ["", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy"]
for $len = $encoded in $cases:
- $plain = ("foobar"|from 1 to ($len - 1))
+ $plain = ("foobar", from 1 to ($len - 1))
assume (base64 $plain) == $encoded
assume (base64 decode $encoded) == $plain
@@ -19,32 +19,32 @@ externally [base64 $str, base64 encode $str, $str base64] all mean:
$chars = []
for $i in 1 to (size of $str) via 3:
$bytes = [=lua "\$str:byte(\$i, \($i + 2))"]
- $chars|add $b64_chars.((($bytes.1 & 252) >> 2) + 1)
+ $chars, add $b64_chars.((($bytes.1 & 252) >> 2) + 1)
if (size of $bytes) is:
3:
- $chars|add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1)
- $chars|add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1)
- $chars|add $b64_chars.(($bytes.3 & 63) + 1)
+ $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1)
+ $chars, add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1)
+ $chars, add $b64_chars.(($bytes.3 & 63) + 1)
2:
- $chars|add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1)
- $chars|add $b64_chars.((($bytes.2 & 15) << 2) + 1)
- $chars|add "="
+ $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1)
+ $chars, add $b64_chars.((($bytes.2 & 15) << 2) + 1)
+ $chars, add "="
1:
- $chars|add $b64_chars.((($bytes.1 & 3) << 4) + 1)
- $chars|add "="
- $chars|add "="
- return ($chars|joined)
+ $chars, add $b64_chars.((($bytes.1 & 3) << 4) + 1)
+ $chars, add "="
+ $chars, add "="
+ return ($chars, joined)
externally (chr $) means (=lua "string.char(\$)")
externally [decode base64 $str, $str base64 decoded, base64 decode $str] all mean:
$chars = []
for $i in 1 to (size of $str) via 4:
- $indices = [: for $j in $i to ($i + 3): add $reverse_b64.($str|character $j)]
- $chars|add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4)))
- if (($str|character ($i + 2)) == "="): stop
- $chars|add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2)))
- if (($str|character ($i + 3)) == "="): stop
- $chars|add (chr ((($indices.3 & 3) << 6) + $indices.4))
- return ($chars|joined)
+ $indices = [: for $j in $i to ($i + 3): add $reverse_b64.($str, character $j)]
+ $chars, add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4)))
+ if (($str, character ($i + 2)) == "="): stop
+ $chars, add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2)))
+ if (($str, character ($i + 3)) == "="): stop
+ $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4))
+ return ($chars, joined)