cuddle-0.5.0.0: CDDL Generator and test utilities
Safe HaskellNone
LanguageGHC2021

Codec.CBOR.Cuddle.CBOR.Validator

Synopsis

Documentation

data CDDLResult Source #

Constructors

Valid Rule

The rule was valid

ChoiceFail

All alternatives failed

Fields

ListExpansionFail

All expansions failed

An expansion is: Given a CBOR TList of N elements, we will expand the rules in a list spec to match the number of items in the list.

Fields

  • Rule

    Rule we are trying

  • [[Rule]]

    List of expansions of rules

  • [[(Rule, CBORTermResult)]]

    For each expansion, for each of the rules in the expansion, the result

MapExpansionFail

All expansions failed

An expansion is: Given a CBOR TMap of N elements, we will expand the rules in a map spec to match the number of items in the map.

Fields

InvalidControl

The rule was valid but the control failed

Fields

InvalidRule Rule 
InvalidTagged

A tagged was invalid

Fields

UnapplicableRule

The rule we are trying is not applicable to the CBOR term

Fields

  • Rule

    Rule we are trying

Instances

Instances details
Show CDDLResult Source # 
Instance details

Defined in Codec.CBOR.Cuddle.CBOR.Validator

data ANonMatchedItem Source #

Constructors

ANonMatchedItem 

Fields

Instances

Instances details
Show ANonMatchedItem Source # 
Instance details

Defined in Codec.CBOR.Cuddle.CBOR.Validator

data AMatchedItem Source #

Constructors

AMatchedItem 

Fields

Instances

Instances details
Show AMatchedItem Source # 
Instance details

Defined in Codec.CBOR.Cuddle.CBOR.Validator

validateTerm :: MonadReader CDDL m => Term -> Rule -> m CBORTermResult Source #

Core function that validates a CBOR term to a particular rule of the CDDL spec

validateInteger :: MonadReader CDDL m => Integer -> Rule -> m CDDLResult Source #

Validation of an Int or Integer. CBOR categorizes every integral in TInt or TInteger but it can be the case that we are decoding something that is expected to be a Word64 even if we get a TInt.

ghci> encodeWord64 15
[TkInt 15]
ghci> encodeWord64 maxBound
[TkInteger 18446744073709551615]

For this reason, we cannot assume that bounds or literals are going to be Ints, so we convert everything to Integer.

controlInteger :: MonadReader CDDL m => Integer -> CtlOp -> Rule -> m (Either (Maybe CBORTermResult) ()) Source #

Controls for an Integer

validateHalf :: MonadReader CDDL m => Float -> Rule -> m CDDLResult Source #

Validating a Float16

controlHalf :: MonadReader CDDL m => Float -> CtlOp -> Rule -> m (Either (Maybe CBORTermResult) ()) Source #

Controls for Float16

validateFloat :: MonadReader CDDL m => Float -> Rule -> m CDDLResult Source #

Validating a Float32

controlFloat :: MonadReader CDDL m => Float -> CtlOp -> Rule -> m (Either (Maybe CBORTermResult) ()) Source #

Controls for Float32

validateDouble :: MonadReader CDDL m => Double -> Rule -> m CDDLResult Source #

Validating a Float64

controlDouble :: MonadReader CDDL m => Double -> CtlOp -> Rule -> m (Either (Maybe CBORTermResult) ()) Source #

Controls for Float64

validateBool :: MonadReader CDDL m => Bool -> Rule -> m CDDLResult Source #

Validating a boolean

validateSimple :: MonadReader CDDL m => Word8 -> Rule -> m CDDLResult Source #

Validating a TSimple. It is unclear if this is used for anything else than undefined.

validateNull :: MonadReader CDDL m => Rule -> m CDDLResult Source #

Validating nil

validateBytes :: MonadReader CDDL m => ByteString -> Rule -> m CDDLResult Source #

Validating a byte sequence

controlBytes :: MonadReader CDDL m => ByteString -> CtlOp -> Rule -> m (Either (Maybe CBORTermResult) ()) Source #

Controls for byte strings

validateText :: MonadReader CDDL m => Text -> Rule -> m CDDLResult Source #

Validating text strings

controlText :: MonadReader CDDL m => Text -> CtlOp -> Rule -> m (Either (Maybe CBORTermResult) ()) Source #

Controls for text strings

flattenGroup :: CDDL -> [Rule] -> [Rule] Source #

Groups might contain enums, or unwraps inside. This resolves all those to the top level of the group.

expandRules :: Int -> [Rule] -> Reader CDDL [[Rule]] Source #

Expand rules to reach exactly the wanted length, which must be the number of items in the container. For example, if we want to validate 3 elements, and we have the following CDDL:

a = [* int, * bool]

this will be expanded to `[int, int, int], [int, int, bool], [int, bool, bool], [bool, bool, bool]`.

Essentially the rules we will parse is the choice among the expansions of the original rules.

isOptional :: MonadReader CDDL m => Rule -> m Bool Source #

Which rules are optional?

ctrlAnd :: Monad m => (Rule -> m CDDLResult) -> Rule -> Rule -> m (Rule -> CDDLResult) Source #

Validate both rules

ctrlDispatch :: Monad m => (Rule -> m CDDLResult) -> CtlOp -> Rule -> Rule -> (CtlOp -> Rule -> m (Either (Maybe CBORTermResult) ())) -> m (Rule -> CDDLResult) Source #

Dispatch to the appropriate control

boolCtrl :: Bool -> Either (Maybe CBORTermResult) () Source #

A boolean control

ifM :: Monad m => m Bool -> m a -> m a -> m a Source #

range :: Ord a => RangeBound -> a -> a -> Bool Source #