module DCLabel.NanoEDSL (
(.\/.), (./\.)
, (<>), (><)
, newDC
, newPriv, newTCBPriv
) where
import DCLabel.Core
infixl 7 .\/.
infixl 6 ./\.
class Singleton a where
singleton :: a -> Label
instance Singleton Principal where
singleton p = MkLabel $ MkConj [ MkDisj [p] ]
instance Singleton String where
singleton s = MkLabel $ MkConj [ MkDisj [principal s] ]
class DisjunctionOf a b where
(.\/.) :: a -> b -> Label
instance DisjunctionOf Principal Principal where
p1 .\/. p2 = MkLabel $ MkConj [ MkDisj [p1,p2] ]
instance DisjunctionOf Principal Label where
p .\/. l = (singleton p) `or_label` l
instance DisjunctionOf Label Principal where
l .\/. p = p .\/. l
instance DisjunctionOf Label Label where
l1 .\/. l2 = l1 `or_label` l2
instance DisjunctionOf String String where
s1 .\/. s2 = singleton s1 .\/. singleton s2
instance DisjunctionOf String Label where
s .\/. l = singleton s .\/. l
instance DisjunctionOf Label String where
l .\/. p = p .\/. l
class ConjunctionOf a b where
(./\.) :: a -> b -> Label
instance ConjunctionOf Principal Principal where
p1 ./\. p2 = MkLabel $ MkConj [ MkDisj [p1], MkDisj [p2] ]
instance ConjunctionOf Principal Label where
p ./\. l = singleton p `and_label` l
instance ConjunctionOf Label Principal where
l ./\. p = p ./\. l
instance ConjunctionOf Label Label where
l1 ./\. l2 = l1 `and_label` l2
instance ConjunctionOf String String where
s1 ./\. s2 = singleton s1 ./\. singleton s2
instance ConjunctionOf String Label where
s ./\. l = singleton s `and_label` l
instance ConjunctionOf Label String where
l ./\. s = s ./\. l
instance ConjunctionOf Disj Disj where
d1 ./\. d2 = MkLabel $ MkConj [ d1, d2 ]
instance ConjunctionOf Disj Label where
d ./\. l = (MkLabel $ MkConj [d]) `and_label` l
instance ConjunctionOf Label Disj where
l ./\. d = d ./\. l
instance ConjunctionOf Principal Disj where
p ./\. d = singleton p ./\. d
instance ConjunctionOf Disj Principal where
d ./\. p = p ./\. d
instance ConjunctionOf String Disj where
p ./\. d = singleton p ./\. d
instance ConjunctionOf Disj String where
d ./\. p = p ./\. d
(<>) :: Label
(<>) = emptyLabel
(><) :: Label
(><) = allLabel
class NewDC a b where
newDC :: a -> b -> DCLabel
instance NewDC Label Label where
newDC l1 l2 = MkDCLabel l1 l2
instance NewDC Principal Label where
newDC p l = MkDCLabel (singleton p) l
instance NewDC Label Principal where
newDC l p = MkDCLabel l (singleton p)
instance NewDC Principal Principal where
newDC p1 p2 = MkDCLabel (singleton p1) (singleton p2)
instance NewDC String Label where
newDC p l = MkDCLabel (singleton p) l
instance NewDC Label String where
newDC l p = MkDCLabel l (singleton p)
instance NewDC String String where
newDC p1 p2 = MkDCLabel (singleton p1) (singleton p2)
class NewPriv a where
newPriv :: a -> Priv
newTCBPriv :: TCBPriv -> a -> Maybe TCBPriv
newTCBPriv p = delegatePriv p . newPriv
instance NewPriv Label where
newPriv = id
instance NewPriv Principal where
newPriv p = singleton p
instance NewPriv String where
newPriv p = singleton p