aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2017-01-12 19:39:49 -0400
committerEduardo Julian2017-01-12 19:39:49 -0400
commit7c0793c86076d4f19083a3a0a699de4f1e1661b4 (patch)
tree4c2067f1ccb8def0dcd740b263154a35587f7bb4
parent1f28cd54954e8b2b978b5fa94956c8df4cbee698 (diff)
- Added a module for tainting data.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/taint.lux30
1 files changed, 30 insertions, 0 deletions
diff --git a/stdlib/source/lux/data/taint.lux b/stdlib/source/lux/data/taint.lux
new file mode 100644
index 000000000..935d16c72
--- /dev/null
+++ b/stdlib/source/lux/data/taint.lux
@@ -0,0 +1,30 @@
+## Copyright (c) Eduardo Julian. All rights reserved.
+## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+## If a copy of the MPL was not distributed with this file,
+## You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(;module:
+ lux
+ (lux (data [product])))
+
+(type: #export (Tainted a)
+ [a Void])
+
+(def: #export (taint input)
+ (All [a] (-> a (Tainted a)))
+ [input (:! Void [])])
+
+(def: #export (trust input)
+ (All [a] (-> (Tainted a) a))
+ (product;left input))
+
+(def: #export (validate pred input)
+ (All [a] (-> (-> a Bool) (Tainted a) (Maybe a)))
+ (let [value (product;left input)]
+ (if (pred value)
+ (#;Some value)
+ #;None)))
+
+(def: #export (sanitize f input)
+ (All [a] (-> (-> a a) (Tainted a) a))
+ (|> input product;left f))