Skip to content

Commit f52085d

Browse files
committed
Merge branch 'master' of github.com-functora:functora/functora.github.io
2 parents 3e823d5 + b78e067 commit f52085d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

pub/functora/functora.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ common pkg-cfg
189189
build-depends:
190190
, aeson
191191
, base
192+
, base64-bytestring
192193
, binary
193194
, binary-instances
194195
, bytestring

pub/functora/src/cfg/Functora/Cfg.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module Functora.Cfg
2121
-- $binary
2222
decodeBinary,
2323
encodeBinary,
24+
decodeBinaryB64Url,
25+
encodeBinaryB64Url,
2426
)
2527
where
2628

@@ -35,6 +37,7 @@ import Data.Binary as X (Binary)
3537
import qualified Data.Binary as Binary
3638
import qualified Data.Binary.Get as Binary
3739
import Data.Binary.Instances as X ()
40+
import qualified Data.ByteString.Base64.URL as B64URL
3841
import qualified Data.ByteString.Lazy as BL
3942
import qualified Data.List.NonEmpty as NE
4043
import Functora.CfgOrphan (genericTomlCodec)
@@ -188,3 +191,35 @@ decodeBinary raw = do
188191

189192
encodeBinary :: (Binary a) => a -> BL.ByteString
190193
encodeBinary = Binary.encode
194+
195+
decodeBinaryB64Url ::
196+
forall typ str.
197+
( From str Text,
198+
Show typ,
199+
Data typ,
200+
Binary typ
201+
) =>
202+
str ->
203+
Either (BL.ByteString, Binary.ByteOffset, String) typ
204+
decodeBinaryB64Url b64 = do
205+
bin <-
206+
first (mempty,0,)
207+
. B64URL.decode
208+
. unTagged
209+
$ via @Text @str @(UTF_8 ByteString) b64
210+
decodeBinary bin
211+
212+
encodeBinaryB64Url ::
213+
forall str typ.
214+
( Binary typ,
215+
From Text str
216+
) =>
217+
typ ->
218+
str
219+
encodeBinaryB64Url =
220+
from @Text @str
221+
. unsafeFrom @(UTF_8 ByteString) @Text
222+
. from @ByteString @(UTF_8 ByteString)
223+
. B64URL.encode
224+
. from @BL.ByteString @ByteString
225+
. Binary.encode

pub/functora/src/prelude/Functora/Prelude.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ module Functora.Prelude
120120
dropWhileEnd,
121121
AscOrDesc (..),
122122
Nonce (..),
123+
mkNonce,
123124
NonceGen,
124125
newNonceGen,
125126
withNonce,

0 commit comments

Comments
 (0)