aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/security/integrity.lux
blob: 81dee0c16c0bc40105546567326550f33ebddfb2 (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
46
47
48
49
50
51
(.module:
  [lux #*
   [control
    [functor (#+ Functor)]
    [apply (#+ Apply)]
    [monad (#+ Monad)]]
   [data
    [error (#+ Error)]]
   [type
    abstract]])

(abstract: #export (Dirty a)
  {#.doc (doc "A value which is considered untrustworthy due to its origin.")}
  
  a

  (def: #export taint
    {#.doc (doc "Mark a value as dirty/untrustworthy.")}
    (All [a] (-> a (Dirty a)))
    (|>> :abstraction))

  (def: #export (validate validator dirty)
    {#.doc (doc "Test a dirty/untrustworthy value."
                "Potentially produces a 'clean' value.")}
    (All [a b] (-> (-> a (Error b)) (Dirty a) (Error b)))
    (validator (:representation dirty)))

  (def: #export trust
    {#.doc (doc "Trusts a (previously thought as) dirty/untrustworthy value."
                "Only use this function if you know what you are doing."
                "Trusting a value that hasn't been validated opens a security vulnerability.")}
    (All [a] (-> (Dirty a) a))
    (|>> :representation))

  (structure: #export functor (Functor Dirty)
    (def: (map f fa)
      (|> fa :representation f :abstraction)))

  (structure: #export apply (Apply Dirty)
    (def: &functor ..functor)

    (def: (apply ff fa)
      (:abstraction ((:representation ff) (:representation fa)))))

  (structure: #export monad (Monad Dirty)
    (def: &functor ..functor)

    (def: wrap (|>> :abstraction))

    (def: join (|>> :representation)))
  )