! Copyright (C) 2008 Doug Coleman, Daniel Ehrenberg.
-! See http://factorcode.org/license.txt for BSD license.
+! 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
]
: alphabet-inverse ( alphabet -- seq )
- dup supremum 1 + f <array> [
+ dup maximum 1 + f <array> [
'[ swap _ set-nth ] each-index
] keep ;
>>
: 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 )
:: (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
[ CHAR: = eq? 1 0 ? ] tri@ + +
[ head-slice* ] unless-zero
output stream-write
- ] while drop ;
+ ] while* ;
PRIVATE>
{ CHAR: / CHAR: _ }
} substitute ;
+: >urlsafe-base64-jwt ( seq -- base64 )
+ >urlsafe-base64 [ CHAR: = = ] trim-tail ;
+
: urlsafe-base64> ( base64 -- seq )
H{
{ CHAR: - CHAR: + }