blob: 7ec3cceec56543416d66717c21c242861b66bc01 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
(.module:
[lux #*
["." ffi (#+ import:)]
[abstract
[equivalence (#+ Equivalence)]]
[data
["." product]
["." text
["%" format (#+ format)]
["." encoding]]]])
(type: #export User
Text)
(type: #export Password
Text)
(type: #export Identity
{#user User
#password Password})
(def: #export equivalence
(Equivalence Identity)
($_ product.equivalence
text.equivalence
text.equivalence
))
(import: java/util/Base64$Encoder
["#::."
(encodeToString [[byte]] java/lang/String)])
(import: java/util/Base64
["#::."
(#static getEncoder [] java/util/Base64$Encoder)])
(def: #export (basic_auth user password)
(-> User Password Text)
(let [credentials (\ encoding.utf8 encode (format user ":" password))]
(|> (java/util/Base64::getEncoder)
(java/util/Base64$Encoder::encodeToString credentials)
(format "Basic "))))
|