Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Capability m d = MkCapability {
- runCapability :: d -> m AccessDecision
- type Capabilities m d = [Capability m d]
- data AccessDecision
- newtype SafeAccessT d m a = SafeAccessT {
- runSafeAccessT :: Capabilities m d -> m (Either d a)
- class (Monad m, Monad s) => MonadSafeAccess d m s | m -> s, m -> d where
- getCapabilities :: m (Capabilities s d)
- liftSub :: s a -> m a
- denyAccess :: d -> m ()
- catchAccessError :: m a -> (d -> m a) -> m a
- ensureAccess :: MonadSafeAccess d m s => d -> m ()
- unsecureAllow :: (Monad m, Eq d) => [d] -> SafeAccessT d m a -> SafeAccessT d m a
- singleCapability :: (Applicative f, Eq d) => d -> Capability f d
- someCapabilities :: (Applicative f, Eq d) => [d] -> Capability f d
- passthroughCapability :: Applicative f => Capability f d
- liftExceptT :: ExceptT d m a -> SafeAccessT d m a
- liftCapability :: (Monad m, MonadTrans t) => Capability m d -> Capability (t m) d
Documentation
newtype Capability m d Source #
Allow things to be accessed. See ensureAccess
.
d
is the type describing an access.
MkCapability | |
|
Instances
Applicative m => Semigroup (Capability m d) Source # | |
Defined in Control.SafeAccess (<>) :: Capability m d -> Capability m d -> Capability m d # sconcat :: NonEmpty (Capability m d) -> Capability m d # stimes :: Integral b => b -> Capability m d -> Capability m d # | |
Applicative m => Monoid (Capability m d) Source # | |
Defined in Control.SafeAccess mempty :: Capability m d # mappend :: Capability m d -> Capability m d -> Capability m d # mconcat :: [Capability m d] -> Capability m d # |
type Capabilities m d = [Capability m d] Source #
data AccessDecision Source #
Control the decision process.
The constructors are ordered by prevalence. For instance, if two capabilities
respectively return AccessGranted
and AccessDenied
,
the final decision will be AccessDenied
.
AccessDeniedSoft | No but another |
AccessGranted | Final yes (see explanation) |
AccessDenied | Final no |
Instances
Eq AccessDecision Source # | |
Defined in Control.SafeAccess (==) :: AccessDecision -> AccessDecision -> Bool # (/=) :: AccessDecision -> AccessDecision -> Bool # | |
Show AccessDecision Source # | |
Defined in Control.SafeAccess showsPrec :: Int -> AccessDecision -> ShowS # show :: AccessDecision -> String # showList :: [AccessDecision] -> ShowS # | |
Semigroup AccessDecision Source # | |
Defined in Control.SafeAccess (<>) :: AccessDecision -> AccessDecision -> AccessDecision # sconcat :: NonEmpty AccessDecision -> AccessDecision # stimes :: Integral b => b -> AccessDecision -> AccessDecision # | |
Monoid AccessDecision Source # | |
Defined in Control.SafeAccess mappend :: AccessDecision -> AccessDecision -> AccessDecision # mconcat :: [AccessDecision] -> AccessDecision # |
newtype SafeAccessT d m a Source #
A simple monad transformer to ensure that data are accessed legitimately.
The return value is either the description of an access having been denied (left) or the result of the normal computation (right).
SafeAccessT | |
|
Instances
class (Monad m, Monad s) => MonadSafeAccess d m s | m -> s, m -> d where Source #
getCapabilities :: m (Capabilities s d) Source #
liftSub :: s a -> m a Source #
denyAccess :: d -> m () Source #
catchAccessError :: m a -> (d -> m a) -> m a Source #
Catch an access error, i.e. an access descriptor which resulted into an access denied given the capabilities.
Instances
ensureAccess :: MonadSafeAccess d m s => d -> m () Source #
Check that the access is legal or make the monad "fail".
unsecureAllow :: (Monad m, Eq d) => [d] -> SafeAccessT d m a -> SafeAccessT d m a Source #
Allow certain accesses regardless of the capabilities. (unsecure!)
singleCapability :: (Applicative f, Eq d) => d -> Capability f d Source #
Create a capability which only allows a given access
someCapabilities :: (Applicative f, Eq d) => [d] -> Capability f d Source #
Create a capability which only allows given accesses
passthroughCapability :: Applicative f => Capability f d Source #
A special capability which allows every access. Be careful with this!
liftExceptT :: ExceptT d m a -> SafeAccessT d m a Source #
Lift an action from ErrorT
to SafeAccessT
.
liftCapability :: (Monad m, MonadTrans t) => Capability m d -> Capability (t m) d Source #