]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/base64/base64.factor
mason: move alignment to mason.css, right align but-last columns in table body
[factor.git] / basis / base64 / base64.factor
index 1e46e60275a7e173a08cfba6b8ac45d8b2b9c93f..abd7023bb3935842145c1ea1001d12bede25758a 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman, Daniel Ehrenberg.
-! See http://factorcode.org/license.txt for BSD license.
-USING: arrays assocs byte-arrays combinators fry growable io
-io.binary io.encodings.binary io.streams.byte-array kernel
-kernel.private literals locals math math.bitwise namespaces
-sbufs sequences sequences.private ;
+! See https://factorcode.org/license.txt for BSD license.
+USING: arrays assocs byte-arrays combinators growable io
+io.encodings.binary io.streams.byte-array kernel kernel.private
+literals math math.bitwise namespaces sbufs sequences
+sequences.private ;
 IN: base64
 
 ERROR: malformed-base64 ;
@@ -17,7 +17,7 @@ CONSTANT: alphabet $[
 ]
 
 : alphabet-inverse ( alphabet -- seq )
-    dup supremum 1 + f <array> [
+    dup maximum 1 + f <array> [
         '[ swap _ set-nth ] each-index
     ] keep ;
 >>
@@ -82,7 +82,7 @@ PRIVATE>
 
 : read-ignoring ( n ignoring stream -- accum )
     pick <sbuf> [
-        '[ _ _ read1-ignoring [ ] _ push-if ] times
+        '[ _ _ read1-ignoring [ ] _ push-when ] times
     ] keep ;
 
 : decode4 ( a b c d -- x y z )
@@ -95,7 +95,7 @@ PRIVATE>
 
 :: (decode-base64) ( input output -- )
     3 <byte-array> :> data
-    [ B{ CHAR: \n CHAR: \r } input read1-ignoring dup ] [
+    [ B{ CHAR: \n CHAR: \r } input read1-ignoring ] [
         B{ CHAR: \n CHAR: \r } input read1-ignoring CHAR: = or
         B{ CHAR: \n CHAR: \r } input read1-ignoring CHAR: = or
         B{ CHAR: \n CHAR: \r } input read1-ignoring CHAR: = or
@@ -103,7 +103,7 @@ PRIVATE>
         [ CHAR: = eq? 1 0 ? ] tri@ + +
         [ head-slice* ] unless-zero
         output stream-write
-    ] while drop ;
+    ] while* ;
 
 PRIVATE>
 
@@ -122,7 +122,7 @@ PRIVATE>
 
 PRIVATE>
 
-: >base64 ( base64 -- seq )
+: >base64 ( seq -- base64 )
     binary [
         ensure-encode-length
         binary [ encode-base64 ] with-byte-reader
@@ -146,6 +146,9 @@ PRIVATE>
         { CHAR: / CHAR: _ }
     } substitute ;
 
+: >urlsafe-base64-jwt ( seq -- base64 )
+    >urlsafe-base64 [ CHAR: = = ] trim-tail ;
+
 : urlsafe-base64> ( base64 -- seq )
     H{
         { CHAR: - CHAR: + }