File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,7 @@ common pkg-cfg
189
189
build-depends :
190
190
, aeson
191
191
, base
192
+ , base64-bytestring
192
193
, binary
193
194
, binary-instances
194
195
, bytestring
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ module Functora.Cfg
21
21
-- $binary
22
22
decodeBinary ,
23
23
encodeBinary ,
24
+ decodeBinaryB64Url ,
25
+ encodeBinaryB64Url ,
24
26
)
25
27
where
26
28
@@ -35,6 +37,7 @@ import Data.Binary as X (Binary)
35
37
import qualified Data.Binary as Binary
36
38
import qualified Data.Binary.Get as Binary
37
39
import Data.Binary.Instances as X ()
40
+ import qualified Data.ByteString.Base64.URL as B64URL
38
41
import qualified Data.ByteString.Lazy as BL
39
42
import qualified Data.List.NonEmpty as NE
40
43
import Functora.CfgOrphan (genericTomlCodec )
@@ -188,3 +191,35 @@ decodeBinary raw = do
188
191
189
192
encodeBinary :: (Binary a ) => a -> BL. ByteString
190
193
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
Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ module Functora.Prelude
120
120
dropWhileEnd ,
121
121
AscOrDesc (.. ),
122
122
Nonce (.. ),
123
+ mkNonce ,
123
124
NonceGen ,
124
125
newNonceGen ,
125
126
withNonce ,
You can’t perform that action at this time.
0 commit comments