aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/repository/identity.lux
blob: abe5e2e1b8d2a3d855e9b7bb130b9f634a4f2744 (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
43
44
45
(.module:
  [library
   [lux "*"
    ["[0]" ffi {"+" [import:]}]
    [abstract
     [equivalence {"+" [Equivalence]}]]
    [data
     ["[0]" product]
     ["[0]" text
      ["%" format {"+" [format]}]
      [encoding
       ["[0]" utf8]]]]]])

(type: .public User
  Text)

(type: .public Password
  Text)

(type: .public Identity
  (Record
   [#user User
    #password Password]))

(def: .public equivalence
  (Equivalence Identity)
  ($_ product.equivalence
      text.equivalence
      text.equivalence
      ))

(import: java/util/Base64$Encoder
  ["[1]::[0]"
   (encodeToString [[byte]] java/lang/String)])

(import: java/util/Base64
  ["[1]::[0]"
   ("static" getEncoder [] java/util/Base64$Encoder)])

(def: .public (basic_auth user password)
  (-> User Password Text)
  (let [credentials (\ utf8.codec encoded (format user ":" password))]
    (|> (java/util/Base64::getEncoder)
        (java/util/Base64$Encoder::encodeToString credentials)
        (format "Basic "))))