Walnut/Advanced Topics/Build your Own Guards
From Erights
(Difference between revisions)
(Simple guard example) |
|||
Line 3: | Line 3: | ||
===Build Your Own Guards=== | ===Build Your Own Guards=== | ||
- | < | + | <span style="color:red">Put in explanation of the following example. First put in a simple example. This is way too fancy as the basic intro to making a guard.</span> |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | </ | + | |
- | First, here is | + | First, here is the emaker that makes a pair of VOC claim check guards, a proveAuth (i.e., a claimCheck), and a checkAuth (i.e., a checkedClaim): |
- | + | <pre> | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | < | + | <nowiki># E sample |
def makeVOCPair(brandName :String) :near { | def makeVOCPair(brandName :String) :near { | ||
Line 77: | Line 49: | ||
myTempContents := null | myTempContents := null | ||
if (specimenBox.__respondsTo("offerContent", 0)) { | if (specimenBox.__respondsTo("offerContent", 0)) { | ||
- | + | </nowiki><font color="#FF0000"><nowiki># XXX Using __respondsTo/2 here is a kludge</nowiki></font> | |
specimenBox.offerContent() | specimenBox.offerContent() | ||
} else { | } else { | ||
Line 104: | Line 76: | ||
} | } | ||
return [ProveAuth, CheckAuth] | return [ProveAuth, CheckAuth] | ||
- | }</ | + | } |
+ | |||
+ | </pre> | ||
Now here is an example of the pair of VOC guards in use: | Now here is an example of the pair of VOC guards in use: | ||
- | <pre>? def [ProveAuth, CheckAuth] := <elib:sealing.makeVOCPair>("voc") | + | <pre> |
+ | |||
+ | ? def [ProveAuth, CheckAuth] := <elib:sealing.makeVOCPair>("voc") | ||
# value: [<voc prover>, <voc checker template>] | # value: [<voc prover>, <voc checker template>] | ||
Line 149: | Line 125: | ||
? bar(f1 :ProveAuth) | ? bar(f1 :ProveAuth) | ||
- | # problem: <NoSuchMethodException: <a sealedBox>.getPath/0></pre> | + | # problem: <NoSuchMethodException: <a sealedBox>.getPath/0> |
+ | |||
+ | |||
+ | </pre> |
Revision as of 10:50, 29 November 2006
Build Your Own Guards
Put in explanation of the following example. First put in a simple example. This is way too fancy as the basic intro to making a guard.
First, here is the emaker that makes a pair of VOC claim check guards, a proveAuth (i.e., a claimCheck), and a checkAuth (i.e., a checkedClaim):
# E sample def makeVOCPair(brandName :String) :near { var myTempContents := def none {} def brand { to __printOn(out :TextWriter) :void { out.print(brandName) } } def ProveAuth { to __printOn(out :TextWriter) :void { out.print(`<$brandName prover>`) } to getBrand() :near { return brand } to coerce(specimen, optEjector) :near { def sealedBox { to getBrand() :near { return brand } to offerContent() :void { myTempContents := specimen } } return sealedBox } } def CheckAuth { to __printOn(out :TextWriter) :void { out.print(`<$brandName checker template>`) } to getBrand() :near { return brand } match [`get`, authList :any[]] { def checker { to __printOn(out :TextWriter) :void { out.print(`<$brandName checker>`) } to getBrand() :near { return brand } to coerce(specimenBox, optEjector) :any { myTempContents := null if (specimenBox.__respondsTo("offerContent", 0)) { <font color="#FF0000"># XXX Using __respondsTo/2 here is a kludge</font> specimenBox.offerContent() } else { myTempContents := specimenBox } for auth in authList { if (auth == myTempContents) { return auth } } myTempContents := none throw.eject(optEjector, `Unmatched $brandName authorization`) } } } match [`__respondsTo`, [`get`, _]] { true } match [`__respondsTo`, [_, _]] { false } match [`__getAllegedType`, []] { null.__getAllegedType() } } return [ProveAuth, CheckAuth] }
Now here is an example of the pair of VOC guards in use:
? def [ProveAuth, CheckAuth] := <elib:sealing.makeVOCPair>("voc") # value: [<voc prover>, <voc checker template>] ? def f1 := <file:~/.bashrc> # value: <file:c:/Documents and Settings/millerm1/.bashrc> ? def f2 := <file:~/Desktop> # value: <file:c:/Documents and Settings/millerm1/Desktop/> ? def foo(f :CheckAuth[f1,f2]) :void { > println(f.getPath()) > } # value: <foo> ? foo(f1) # stdout: c:/Documents and Settings/millerm1/.bashrc # ? def f3 := <file:~> # value: <file:c:/Documents and Settings/millerm1/> ? foo(f3) # problem: Unmatched voc authorization ? foo(f1 :ProveAuth) # stdout: c:/Documents and Settings/millerm1/.bashrc # ? foo(f3 :ProveAuth) # problem: Unmatched voc authorization ? def bar(f) :void { > println(f.getPath()) > } # value: <bar> ? bar(f1) # stdout: c:/Documents and Settings/millerm1/.bashrc # ? bar(f1 :ProveAuth) # problem: <NoSuchMethodException: <a sealedBox>.getPath/0>