diff options
author | Eduardo Julian | 2018-12-05 19:29:36 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-12-05 19:29:36 -0400 |
commit | aa154846497701cffba97004c743f80d5a345a57 (patch) | |
tree | ec2d122adc15831bf5cf012ad45c494ab47a6692 /stdlib/source | |
parent | dd1eaeed77b536950e4b6bdf3ce44237e19cb275 (diff) |
Made some improvements to value taining, and added some tests.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/security/taint.lux | 45 | ||||
-rw-r--r-- | stdlib/source/lux/data/tainted.lux | 28 |
2 files changed, 45 insertions, 28 deletions
diff --git a/stdlib/source/lux/control/security/taint.lux b/stdlib/source/lux/control/security/taint.lux new file mode 100644 index 000000000..745baa95f --- /dev/null +++ b/stdlib/source/lux/control/security/taint.lux @@ -0,0 +1,45 @@ +(.module: + [lux #* + [control + [predicate (#+ Predicate)] + [functor (#+ Functor)] + [apply (#+ Apply)] + [monad (#+ Monad)]] + [type + abstract]]) + +(abstract: #export (Dirty a) + a + + (def: #export taint + (All [a] (-> a (Dirty a))) + (|>> :abstraction)) + + (def: #export (validate valid? dirty) + (All [a] (-> (Predicate a) (Dirty a) (Maybe a))) + (let [value (:representation dirty)] + (if (valid? value) + (#.Some value) + #.None))) + + (def: #export trust + (All [a] (-> (Dirty a) a)) + (|>> :representation)) + + (structure: #export _ (Functor Dirty) + (def: (map f fa) + (|> fa :representation f :abstraction))) + + (structure: #export _ (Apply Dirty) + (def: functor Functor<Dirty>) + + (def: (apply ff fa) + (:abstraction ((:representation ff) (:representation fa))))) + + (structure: #export _ (Monad Dirty) + (def: functor Functor<Dirty>) + + (def: wrap (|>> :abstraction)) + + (def: join (|>> :representation))) + ) diff --git a/stdlib/source/lux/data/tainted.lux b/stdlib/source/lux/data/tainted.lux deleted file mode 100644 index 7ff754081..000000000 --- a/stdlib/source/lux/data/tainted.lux +++ /dev/null @@ -1,28 +0,0 @@ -(.module: - [lux #* - [data - [product]] - [type - abstract]]) - -(abstract: #export (Tainted a) - a - - (def: #export taint - (All [a] (-> a (Tainted a))) - (|>> :abstraction)) - - (def: #export trust - (All [a] (-> (Tainted a) a)) - (|>> :representation))) - -(def: #export (validate pred tainted) - (All [a] (-> (-> a Bit) (Tainted a) (Maybe a))) - (let [value (trust tainted)] - (if (pred value) - (#.Some value) - #.None))) - -(def: #export (sanitize f tainted) - (All [a] (-> (-> a a) (Tainted a) a)) - (|> tainted trust f)) |