aboutsummaryrefslogtreecommitdiff
path: root/lib/base64.nom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/base64.nom')
-rw-r--r--lib/base64.nom11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/base64.nom b/lib/base64.nom
index fb12319..92ce7c4 100644
--- a/lib/base64.nom
+++ b/lib/base64.nom
@@ -1,10 +1,10 @@
-#!/usr/bin/env nomsu -V3.6.5.6
+#!/usr/bin/env nomsu -V3.7.5.6
#
This file defines actions for encoding/decoding base 64, as specified in:
https://tools.ietf.org/html/rfc4648
%b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-%reverse_b64 = (%b64_str.%i = (%i - 1) for %i in 1 to (length of %b64_str))
+%reverse_b64 = (%b64_str.%i = (%i - 1) for %i in 1 to (size of %b64_str))
%reverse_b64."=" = 0
test:
@@ -14,15 +14,16 @@ test:
assume ((base64 %plain) == %encoded) or barf ".."
\(quote %plain) base64 encoded to \(quote (base64 %plain)) \
..instead of \(quote %encoded)
+
assume ((base64 decode %encoded) == %plain) or barf ".."
\(quote %encoded) base64 decoded to \(quote (base64 decode %encoded)) \
..instead of \(quote %plain)
action [base64 %str, base64 encode %str, %str base64]:
%chars = []
- for %i in 1 to (length of %str) via 3:
+ for %i in 1 to (size of %str) via 3:
%bytes = [=lua "\%str:byte(\%i, \(%i + 2))"]
%chars::add %b64_str.(((%bytes.1 & 252) >> 2) + 1)
- if (length of %bytes) is:
+ if (size of %bytes) is:
3:
%chars::add %b64_str.(((%bytes.1 & 3) << 4) + ((%bytes.2 & 240) >> 4) + 1)
%chars::add %b64_str.(((%bytes.2 & 15) << 2) + ((%bytes.3 & 192) >> 6) + 1)
@@ -43,7 +44,7 @@ action [base64 %str, base64 encode %str, %str base64]:
action [chr %] (=lua "string.char(\%)")
action [decode base64 %str, %str base64 decoded, base64 decode %str]:
%chars = []
- for %i in 1 to (length of %str) via 4:
+ for %i in 1 to (size of %str) via 4:
%indices = (%reverse_b64.(%str.%) for % in %i to (%i + 3))
%chars::add (chr ((%indices.1 << 2) + ((%indices.2 & 48) >> 4)))
if (%str.(%i + 2) == "="): stop