mirror of
https://github.com/urbit/shrub.git
synced 2025-01-08 22:18:12 +03:00
updates +de:base64 to output +octs
This commit is contained in:
parent
3238cf6ce6
commit
67590f70c7
@ -57,26 +57,43 @@
|
|||||||
::
|
::
|
||||||
++ de
|
++ de
|
||||||
|= a=cord
|
|= a=cord
|
||||||
^- (unit @)
|
^- (unit octs)
|
||||||
%+ rush a
|
(rush a parse)
|
||||||
:: XX refactor and expose parser combinator
|
:: +parse:base64: parse base64 cord to +octs
|
||||||
%+ cook (cury swp 3)
|
::
|
||||||
%+ bass 64
|
++ parse
|
||||||
%+ cook welp
|
%+ sear reduce
|
||||||
;~ plug
|
;~ plug
|
||||||
%- plus
|
%- plus ;~ pose
|
||||||
;~ pose
|
|
||||||
(cook |=(a=@ (sub a 'A')) (shim 'A' 'Z'))
|
(cook |=(a=@ (sub a 'A')) (shim 'A' 'Z'))
|
||||||
(cook |=(a=@ (sub a 'G')) (shim 'a' 'z'))
|
(cook |=(a=@ (sub a 'G')) (shim 'a' 'z'))
|
||||||
(cook |=(a=@ (add a 4)) (shim '0' '9'))
|
(cook |=(a=@ (add a 4)) (shim '0' '9'))
|
||||||
(cold 62 (just ?:(url '-' '+')))
|
(cold 62 (just ?:(url '-' '+')))
|
||||||
(cold 63 (just ?:(url '_' '/')))
|
(cold 63 (just ?:(url '_' '/')))
|
||||||
==
|
==
|
||||||
?: pad
|
|
||||||
(stun 0^2 (cold %0 tis))
|
(stun 0^2 (cold %0 tis))
|
||||||
=/ b (~(dif fo 4) 0 (met 3 a))
|
|
||||||
(cold (reap b %0) (easy ~))
|
|
||||||
==
|
==
|
||||||
|
:: +reduce: reduce, measure, and swap base64 digits
|
||||||
|
::
|
||||||
|
++ reduce
|
||||||
|
|= [dat=(list @) dap=(list @)]
|
||||||
|
^- (unit [len=@ud dat=@])
|
||||||
|
=/ lat (lent dat)
|
||||||
|
=/ lap (lent dap)
|
||||||
|
=/ dif (~(dif fo 4) 0 lat)
|
||||||
|
?: &(pad !=(dif lap))
|
||||||
|
:: padding required and incorrect
|
||||||
|
~&(%base-64-padding-err-one ~)
|
||||||
|
?: &(!pad !=(0 lap))
|
||||||
|
:: padding not required but present
|
||||||
|
~&(%base-64-padding-err-two ~)
|
||||||
|
=/ len (sub (mul 3 (div (add lat dif) 4)) dif)
|
||||||
|
:+ ~ len
|
||||||
|
%+ swp 3
|
||||||
|
:: %+ base 64
|
||||||
|
%+ roll
|
||||||
|
(weld dat (reap dif 0))
|
||||||
|
|=([p=@ q=@] (add p (mul 64 q)))
|
||||||
--
|
--
|
||||||
:: +en-base64url: url-safe base64 encoding, without padding
|
:: +en-base64url: url-safe base64 encoding, without padding
|
||||||
::
|
::
|
||||||
@ -482,7 +499,7 @@
|
|||||||
:: XX validate label?
|
:: XX validate label?
|
||||||
?. =((rap 3 ['-----BEGIN ' lab '-----' ~]) i.mep) ~
|
?. =((rap 3 ['-----BEGIN ' lab '-----' ~]) i.mep) ~
|
||||||
?. =((rap 3 ['-----END ' lab '-----' ~]) (snag a t.mep)) ~
|
?. =((rap 3 ['-----END ' lab '-----' ~]) (snag a t.mep)) ~
|
||||||
=- ?~(- ~ `[(met 3 u.-) u.-])
|
^- (unit [@ @])
|
||||||
(de:base64 (rap 3 (scag a t.mep)))
|
(de:base64 (rap 3 (scag a t.mep)))
|
||||||
--
|
--
|
||||||
:: |pkcs1: RSA asymmetric cryptography (rfc3447)
|
:: |pkcs1: RSA asymmetric cryptography (rfc3447)
|
||||||
@ -855,10 +872,9 @@
|
|||||||
++ pass
|
++ pass
|
||||||
=, dejs-soft:format
|
=, dejs-soft:format
|
||||||
%+ ci
|
%+ ci
|
||||||
|= [kty=@t n=(unit @) e=(unit @)]
|
|= [kty=@t n=(unit octs) e=(unit octs)]
|
||||||
^- (unit key:rsa)
|
^- (unit key:rsa)
|
||||||
=/ swp (cury swp 3)
|
=/ pub (both (bind n de:octn) (bind e de:octn))
|
||||||
=/ pub (both (bind n swp) (bind e swp))
|
|
||||||
?~(pub ~ `[u.pub ~])
|
?~(pub ~ `[u.pub ~])
|
||||||
%- ot :~
|
%- ot :~
|
||||||
kty+(su (jest 'RSA'))
|
kty+(su (jest 'RSA'))
|
||||||
@ -871,16 +887,15 @@
|
|||||||
=, dejs-soft:format
|
=, dejs-soft:format
|
||||||
%+ ci
|
%+ ci
|
||||||
|= $: kty=@t
|
|= $: kty=@t
|
||||||
n=(unit @)
|
n=(unit octs)
|
||||||
e=(unit @)
|
e=(unit octs)
|
||||||
d=(unit @)
|
d=(unit octs)
|
||||||
p=(unit @)
|
p=(unit octs)
|
||||||
q=(unit @)
|
q=(unit octs)
|
||||||
==
|
==
|
||||||
^- (unit key:rsa)
|
^- (unit key:rsa)
|
||||||
=/ swp (cury swp 3)
|
=/ pub (both (bind n de:octn) (bind e de:octn))
|
||||||
=/ pub (both (bind n swp) (bind e swp))
|
=/ sek :(both (bind d de:octn) (bind p de:octn) (bind q de:octn))
|
||||||
=/ sek :(both (bind d swp) (bind p swp) (bind q swp))
|
|
||||||
?:(|(?=(~ pub) ?=(~ sek)) ~ `[u.pub sek])
|
?:(|(?=(~ pub) ?=(~ sek)) ~ `[u.pub sek])
|
||||||
%- ot :~
|
%- ot :~
|
||||||
kty+(su (jest 'RSA'))
|
kty+(su (jest 'RSA'))
|
||||||
@ -1855,17 +1870,17 @@
|
|||||||
%- expect-eq !>
|
%- expect-eq !>
|
||||||
['AQAB' (en-base64url (en:octn 65.537))]
|
['AQAB' (en-base64url (en:octn 65.537))]
|
||||||
%- expect-eq !>
|
%- expect-eq !>
|
||||||
[65.537 (need (de-base64url 'AQAB'))]
|
[65.537 (de:octn (need (de-base64url 'AQAB')))]
|
||||||
:: echo "hello" | base64
|
:: echo "hello" | base64
|
||||||
%- expect-eq !>
|
%- expect-eq !>
|
||||||
['aGVsbG8K' (en:base64 (as-octs:mimes:html 'hello\0a'))]
|
['aGVsbG8K' (en:base64 (as-octs:mimes:html 'hello\0a'))]
|
||||||
%- expect-eq !>
|
%- expect-eq !>
|
||||||
['hello\0a' (need (de:base64 'aGVsbG8K'))]
|
['hello\0a' +:(need (de:base64 'aGVsbG8K'))]
|
||||||
:: echo -n -e "\x01\x01\x02\x03" | base64
|
:: echo -n -e "\x01\x01\x02\x03" | base64
|
||||||
%- expect-eq !>
|
%- expect-eq !>
|
||||||
['AQECAw==' (en:base64 (en:octn 0x101.0203))]
|
['AQECAw==' (en:base64 (en:octn 0x101.0203))]
|
||||||
%- expect-eq !>
|
%- expect-eq !>
|
||||||
[0x302.0101 (need (de:base64 'AQECAw=='))]
|
[0x302.0101 +:(need (de:base64 'AQECAw=='))]
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
++ test-asn1
|
++ test-asn1
|
||||||
|
Loading…
Reference in New Issue
Block a user