aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2018-12-05 18:47:21 -0400
committerEduardo Julian2018-12-05 18:47:21 -0400
commitdd1eaeed77b536950e4b6bdf3ce44237e19cb275 (patch)
tree3d66a06e6de55a932263fe72687829918cde4876 /stdlib/source
parentaa4393c55c4f9538bfdb6004f333ad1169327824 (diff)
Some small improvements.
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/control/security/privacy.lux51
-rw-r--r--stdlib/source/lux/type/abstract.lux23
2 files changed, 51 insertions, 23 deletions
diff --git a/stdlib/source/lux/control/security/privacy.lux b/stdlib/source/lux/control/security/privacy.lux
index eeccbd57e..ad85ae679 100644
--- a/stdlib/source/lux/control/security/privacy.lux
+++ b/stdlib/source/lux/control/security/privacy.lux
@@ -7,10 +7,10 @@
[type
abstract]])
-(abstract: #export (Private label value)
+(abstract: #export (Private value label)
{#.doc (doc "A value that is regarded as 'private'."
"The special 'label' parameter exists to distinguish private values of the same basic type."
- "This distinction is necessary when such values are produced in different policies."
+ "This distinction is necessary when such values are produced by different policies."
"This matters, as different policies will have different means to deal with private values."
"The main way to deal with private values is to produce 'public' values from them, by calculating values which do not reveal any private information."
"An example of a computation which may produce a public value from a private value, would be a hashing function.")}
@@ -19,39 +19,60 @@
## there to prevent confusing private values from different origins.
value
- (signature: #export (Privilege label value)
- (: (-> value (Private label value))
+ (type: #export (Close label)
+ (All [value] (-> value (Private value label))))
+
+ (type: #export (Open label)
+ (All [value] (-> (Private value label) value)))
+
+ (signature: #export (Privilege label)
+ (: (Close label)
conceal)
- (: (-> (Private label value) value)
+ (: (Open label)
reveal))
- (type: #export (Policy value scope label)
- (-> (Privilege label value)
+ (def: Privilege<_>
+ Privilege
+ (structure (def: conceal (|>> :abstraction))
+ (def: reveal (|>> :representation))))
+
+ (type: #export (Delegation from to)
+ (All [value] (-> (Private value from) (Private value to))))
+
+ (def: #export (delegation open close)
+ (All [from to] (-> (Open from) (Close to) (Delegation from to)))
+ (|>> open close))
+
+ (type: #export (Context scope label)
+ (-> (Privilege label)
(scope label)))
- (def: #export (with-privacy policy)
+ (def: #export (with-privacy context)
{#.doc (doc "Takes a function that will operate in a privileged/trusted context."
"Within that context, it will be possible to label values as 'private'."
"It will also be possible to downgrade private values to 'public' (un-labelled) values."
"This function can be used to instantiate structures for signatures that provide privacy-sensitive operations."
"The context should not, under any circumstance, reveal any private information it may be privy to."
"Make sure any functions which produce public values from private values are properly reviewed for potential information leaks.")}
- (All [value scope]
+ (All [scope]
(Ex [label]
- (-> (Policy value scope label)
+ (-> (Context scope label)
(scope label))))
- (policy (structure (def: conceal (|>> :abstraction))
- (def: reveal (|>> :representation)))))
+ (context ..Privilege<_>))
+
+ (def: (privatize constructor)
+ (-> Type Type)
+ (type (All [label] (constructor (All [value] (Private value label))))))
(structure: #export Functor<Private>
- (All [label] (Functor (Private label)))
+ (:~ (privatize Functor))
(def: (map f fa)
(|> fa :representation f :abstraction)))
(structure: #export Apply<Private>
- (All [label] (Apply (Private label)))
+ (:~ (privatize Apply))
(def: functor Functor<Private>)
@@ -59,7 +80,7 @@
(:abstraction ((:representation ff) (:representation fa)))))
(structure: #export Monad<Private>
- (All [label] (Monad (Private label)))
+ (:~ (privatize Monad))
(def: functor Functor<Private>)
diff --git a/stdlib/source/lux/type/abstract.lux b/stdlib/source/lux/type/abstract.lux
index 4faea93cf..1ed24af1d 100644
--- a/stdlib/source/lux/type/abstract.lux
+++ b/stdlib/source/lux/type/abstract.lux
@@ -4,6 +4,7 @@
[monad (#+ do Monad)]
["p" parser]]
[data
+ [name ("name/." Codec<Text,Name>)]
[text ("text/." Equivalence<Text> Monoid<Text>)]
["." error]
[collection
@@ -59,9 +60,12 @@
(def: macro-anns Code (' {#.macro? #1}))
(def: representation-name
- (-> Text Text)
- (|>> ($_ text/compose "{" kind "@" module "}")
- (let [[module kind] (name-of #..Representation)])))
+ (-> Name Text)
+ (|>> name/encode
+ ($_ text/compose
+ "{"
+ (name/encode (name-of #..Representation))
+ "} ")))
(def: (cast type-vars input-declaration output-declaration)
(-> (List Code) Code Code Macro)
@@ -80,7 +84,8 @@
[this-module (macro.find-module this-module-name)
#let [type-varsC (list/map code.local-identifier type-vars)
abstraction-declaration (` ((~ (code.local-identifier name)) (~+ type-varsC)))
- representation-declaration (` ((~ (code.local-identifier (representation-name name))) (~+ type-varsC)))
+ representation-declaration (` ((~ (code.local-identifier (representation-name [this-module-name name])))
+ (~+ type-varsC)))
this-module (|> this-module
(update@ #.definitions (put down-cast (: Definition
[Macro macro-anns
@@ -143,10 +148,12 @@
{annotations (p.default cs.empty-annotations csr.annotations)}
representation-type
{primitives (p.some s.any)})
- (let [hidden-name (representation-name name)
- type-varsC (list/map code.local-identifier type-vars)
- abstraction-declaration (` ((~ (code.local-identifier name)) (~+ type-varsC)))
- representation-declaration (` ((~ (code.local-identifier hidden-name)) (~+ type-varsC)))]
+ (do @
+ [current-module macro.current-module-name
+ #let [hidden-name (representation-name [current-module name])
+ type-varsC (list/map code.local-identifier type-vars)
+ abstraction-declaration (` ((~ (code.local-identifier name)) (~+ type-varsC)))
+ representation-declaration (` ((~ (code.local-identifier hidden-name)) (~+ type-varsC)))]]
(wrap (list& (` (type: (~+ (csw.export export)) (~ abstraction-declaration)
(~ (csw.annotations annotations))
(primitive (~ (code.text hidden-name)) [(~+ type-varsC)])))