{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Crypto.WebAuthn.Cose.Internal.Registry
(
CoseKeyType (..),
CoseKeyCommonParameter (..),
CoseKeyTypeParameterOKP (..),
CoseKeyTypeParameterEC2 (..),
CoseKeyTypeParameterRSA (..),
parameterCount,
CoseEllipticCurveOKP (..),
CoseEllipticCurveEC2 (..),
)
where
import Codec.CBOR.Decoding (decodeIntCanonical)
import Codec.CBOR.Encoding (encodeInt)
import Codec.Serialise (Serialise)
import Codec.Serialise.Class (decode, encode)
data CoseKeyCommonParameter
=
CoseKeyCommonParameterKty
|
CoseKeyCommonParameterAlg
deriving (CoseKeyCommonParameter -> CoseKeyCommonParameter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoseKeyCommonParameter -> CoseKeyCommonParameter -> Bool
$c/= :: CoseKeyCommonParameter -> CoseKeyCommonParameter -> Bool
== :: CoseKeyCommonParameter -> CoseKeyCommonParameter -> Bool
$c== :: CoseKeyCommonParameter -> CoseKeyCommonParameter -> Bool
Eq, Int -> CoseKeyCommonParameter -> ShowS
[CoseKeyCommonParameter] -> ShowS
CoseKeyCommonParameter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoseKeyCommonParameter] -> ShowS
$cshowList :: [CoseKeyCommonParameter] -> ShowS
show :: CoseKeyCommonParameter -> String
$cshow :: CoseKeyCommonParameter -> String
showsPrec :: Int -> CoseKeyCommonParameter -> ShowS
$cshowsPrec :: Int -> CoseKeyCommonParameter -> ShowS
Show, CoseKeyCommonParameter
forall a. a -> a -> Bounded a
maxBound :: CoseKeyCommonParameter
$cmaxBound :: CoseKeyCommonParameter
minBound :: CoseKeyCommonParameter
$cminBound :: CoseKeyCommonParameter
Bounded, Int -> CoseKeyCommonParameter
CoseKeyCommonParameter -> Int
CoseKeyCommonParameter -> [CoseKeyCommonParameter]
CoseKeyCommonParameter -> CoseKeyCommonParameter
CoseKeyCommonParameter
-> CoseKeyCommonParameter -> [CoseKeyCommonParameter]
CoseKeyCommonParameter
-> CoseKeyCommonParameter
-> CoseKeyCommonParameter
-> [CoseKeyCommonParameter]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: CoseKeyCommonParameter
-> CoseKeyCommonParameter
-> CoseKeyCommonParameter
-> [CoseKeyCommonParameter]
$cenumFromThenTo :: CoseKeyCommonParameter
-> CoseKeyCommonParameter
-> CoseKeyCommonParameter
-> [CoseKeyCommonParameter]
enumFromTo :: CoseKeyCommonParameter
-> CoseKeyCommonParameter -> [CoseKeyCommonParameter]
$cenumFromTo :: CoseKeyCommonParameter
-> CoseKeyCommonParameter -> [CoseKeyCommonParameter]
enumFromThen :: CoseKeyCommonParameter
-> CoseKeyCommonParameter -> [CoseKeyCommonParameter]
$cenumFromThen :: CoseKeyCommonParameter
-> CoseKeyCommonParameter -> [CoseKeyCommonParameter]
enumFrom :: CoseKeyCommonParameter -> [CoseKeyCommonParameter]
$cenumFrom :: CoseKeyCommonParameter -> [CoseKeyCommonParameter]
fromEnum :: CoseKeyCommonParameter -> Int
$cfromEnum :: CoseKeyCommonParameter -> Int
toEnum :: Int -> CoseKeyCommonParameter
$ctoEnum :: Int -> CoseKeyCommonParameter
pred :: CoseKeyCommonParameter -> CoseKeyCommonParameter
$cpred :: CoseKeyCommonParameter -> CoseKeyCommonParameter
succ :: CoseKeyCommonParameter -> CoseKeyCommonParameter
$csucc :: CoseKeyCommonParameter -> CoseKeyCommonParameter
Enum)
instance Serialise CoseKeyCommonParameter where
encode :: CoseKeyCommonParameter -> Encoding
encode CoseKeyCommonParameter
CoseKeyCommonParameterKty = Int -> Encoding
encodeInt Int
1
encode CoseKeyCommonParameter
CoseKeyCommonParameterAlg = Int -> Encoding
encodeInt Int
3
decode :: forall s. Decoder s CoseKeyCommonParameter
decode =
forall s. Decoder s Int
decodeIntCanonical forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Int
1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyCommonParameter
CoseKeyCommonParameterKty
Int
3 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyCommonParameter
CoseKeyCommonParameterAlg
Int
value -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown COSE key common parameter " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
value
data CoseKeyType
=
CoseKeyTypeOKP
|
CoseKeyTypeEC2
|
CoseKeyTypeRSA
deriving (CoseKeyType -> CoseKeyType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoseKeyType -> CoseKeyType -> Bool
$c/= :: CoseKeyType -> CoseKeyType -> Bool
== :: CoseKeyType -> CoseKeyType -> Bool
$c== :: CoseKeyType -> CoseKeyType -> Bool
Eq, Int -> CoseKeyType -> ShowS
[CoseKeyType] -> ShowS
CoseKeyType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoseKeyType] -> ShowS
$cshowList :: [CoseKeyType] -> ShowS
show :: CoseKeyType -> String
$cshow :: CoseKeyType -> String
showsPrec :: Int -> CoseKeyType -> ShowS
$cshowsPrec :: Int -> CoseKeyType -> ShowS
Show)
instance Serialise CoseKeyType where
encode :: CoseKeyType -> Encoding
encode CoseKeyType
CoseKeyTypeOKP = Int -> Encoding
encodeInt Int
1
encode CoseKeyType
CoseKeyTypeEC2 = Int -> Encoding
encodeInt Int
2
encode CoseKeyType
CoseKeyTypeRSA = Int -> Encoding
encodeInt Int
3
decode :: forall s. Decoder s CoseKeyType
decode =
forall s. Decoder s Int
decodeIntCanonical forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Int
1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyType
CoseKeyTypeOKP
Int
2 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyType
CoseKeyTypeEC2
Int
3 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyType
CoseKeyTypeRSA
Int
value -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown COSE key type " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
value
data CoseKeyTypeParameterOKP
=
CoseKeyTypeParameterOKPCrv
|
CoseKeyTypeParameterOKPX
deriving (CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP -> Bool
$c/= :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP -> Bool
== :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP -> Bool
$c== :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP -> Bool
Eq, Int -> CoseKeyTypeParameterOKP -> ShowS
[CoseKeyTypeParameterOKP] -> ShowS
CoseKeyTypeParameterOKP -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoseKeyTypeParameterOKP] -> ShowS
$cshowList :: [CoseKeyTypeParameterOKP] -> ShowS
show :: CoseKeyTypeParameterOKP -> String
$cshow :: CoseKeyTypeParameterOKP -> String
showsPrec :: Int -> CoseKeyTypeParameterOKP -> ShowS
$cshowsPrec :: Int -> CoseKeyTypeParameterOKP -> ShowS
Show, CoseKeyTypeParameterOKP
forall a. a -> a -> Bounded a
maxBound :: CoseKeyTypeParameterOKP
$cmaxBound :: CoseKeyTypeParameterOKP
minBound :: CoseKeyTypeParameterOKP
$cminBound :: CoseKeyTypeParameterOKP
Bounded, Int -> CoseKeyTypeParameterOKP
CoseKeyTypeParameterOKP -> Int
CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP
CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP
-> [CoseKeyTypeParameterOKP]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP
-> [CoseKeyTypeParameterOKP]
$cenumFromThenTo :: CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP
-> [CoseKeyTypeParameterOKP]
enumFromTo :: CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
$cenumFromTo :: CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
enumFromThen :: CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
$cenumFromThen :: CoseKeyTypeParameterOKP
-> CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
enumFrom :: CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
$cenumFrom :: CoseKeyTypeParameterOKP -> [CoseKeyTypeParameterOKP]
fromEnum :: CoseKeyTypeParameterOKP -> Int
$cfromEnum :: CoseKeyTypeParameterOKP -> Int
toEnum :: Int -> CoseKeyTypeParameterOKP
$ctoEnum :: Int -> CoseKeyTypeParameterOKP
pred :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP
$cpred :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP
succ :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP
$csucc :: CoseKeyTypeParameterOKP -> CoseKeyTypeParameterOKP
Enum)
instance Serialise CoseKeyTypeParameterOKP where
encode :: CoseKeyTypeParameterOKP -> Encoding
encode CoseKeyTypeParameterOKP
CoseKeyTypeParameterOKPCrv = Int -> Encoding
encodeInt (-Int
1)
encode CoseKeyTypeParameterOKP
CoseKeyTypeParameterOKPX = Int -> Encoding
encodeInt (-Int
2)
decode :: forall s. Decoder s CoseKeyTypeParameterOKP
decode =
forall s. Decoder s Int
decodeIntCanonical forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
-1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyTypeParameterOKP
CoseKeyTypeParameterOKPCrv
-2 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyTypeParameterOKP
CoseKeyTypeParameterOKPX
Int
value -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown COSE key type parameter " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
value forall a. Semigroup a => a -> a -> a
<> String
" for key type OKP"
data CoseEllipticCurveOKP
=
CoseEllipticCurveEd25519
deriving (CoseEllipticCurveOKP -> CoseEllipticCurveOKP -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoseEllipticCurveOKP -> CoseEllipticCurveOKP -> Bool
$c/= :: CoseEllipticCurveOKP -> CoseEllipticCurveOKP -> Bool
== :: CoseEllipticCurveOKP -> CoseEllipticCurveOKP -> Bool
$c== :: CoseEllipticCurveOKP -> CoseEllipticCurveOKP -> Bool
Eq, Int -> CoseEllipticCurveOKP -> ShowS
[CoseEllipticCurveOKP] -> ShowS
CoseEllipticCurveOKP -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoseEllipticCurveOKP] -> ShowS
$cshowList :: [CoseEllipticCurveOKP] -> ShowS
show :: CoseEllipticCurveOKP -> String
$cshow :: CoseEllipticCurveOKP -> String
showsPrec :: Int -> CoseEllipticCurveOKP -> ShowS
$cshowsPrec :: Int -> CoseEllipticCurveOKP -> ShowS
Show)
instance Serialise CoseEllipticCurveOKP where
encode :: CoseEllipticCurveOKP -> Encoding
encode CoseEllipticCurveOKP
CoseEllipticCurveEd25519 = Int -> Encoding
encodeInt Int
6
decode :: forall s. Decoder s CoseEllipticCurveOKP
decode =
forall s. Decoder s Int
decodeIntCanonical forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Int
6 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseEllipticCurveOKP
CoseEllipticCurveEd25519
Int
value -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown COSE elliptic curve " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
value forall a. Semigroup a => a -> a -> a
<> String
" for key type OKP"
data CoseKeyTypeParameterEC2
=
CoseKeyTypeParameterEC2Crv
|
CoseKeyTypeParameterEC2X
|
CoseKeyTypeParameterEC2Y
deriving (CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2 -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2 -> Bool
$c/= :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2 -> Bool
== :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2 -> Bool
$c== :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2 -> Bool
Eq, Int -> CoseKeyTypeParameterEC2 -> ShowS
[CoseKeyTypeParameterEC2] -> ShowS
CoseKeyTypeParameterEC2 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoseKeyTypeParameterEC2] -> ShowS
$cshowList :: [CoseKeyTypeParameterEC2] -> ShowS
show :: CoseKeyTypeParameterEC2 -> String
$cshow :: CoseKeyTypeParameterEC2 -> String
showsPrec :: Int -> CoseKeyTypeParameterEC2 -> ShowS
$cshowsPrec :: Int -> CoseKeyTypeParameterEC2 -> ShowS
Show, CoseKeyTypeParameterEC2
forall a. a -> a -> Bounded a
maxBound :: CoseKeyTypeParameterEC2
$cmaxBound :: CoseKeyTypeParameterEC2
minBound :: CoseKeyTypeParameterEC2
$cminBound :: CoseKeyTypeParameterEC2
Bounded, Int -> CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2 -> Int
CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2
-> [CoseKeyTypeParameterEC2]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2
-> [CoseKeyTypeParameterEC2]
$cenumFromThenTo :: CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2
-> [CoseKeyTypeParameterEC2]
enumFromTo :: CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
$cenumFromTo :: CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
enumFromThen :: CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
$cenumFromThen :: CoseKeyTypeParameterEC2
-> CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
enumFrom :: CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
$cenumFrom :: CoseKeyTypeParameterEC2 -> [CoseKeyTypeParameterEC2]
fromEnum :: CoseKeyTypeParameterEC2 -> Int
$cfromEnum :: CoseKeyTypeParameterEC2 -> Int
toEnum :: Int -> CoseKeyTypeParameterEC2
$ctoEnum :: Int -> CoseKeyTypeParameterEC2
pred :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2
$cpred :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2
succ :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2
$csucc :: CoseKeyTypeParameterEC2 -> CoseKeyTypeParameterEC2
Enum)
instance Serialise CoseKeyTypeParameterEC2 where
encode :: CoseKeyTypeParameterEC2 -> Encoding
encode CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2Crv = Int -> Encoding
encodeInt (-Int
1)
encode CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2X = Int -> Encoding
encodeInt (-Int
2)
encode CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2Y = Int -> Encoding
encodeInt (-Int
3)
decode :: forall s. Decoder s CoseKeyTypeParameterEC2
decode =
forall s. Decoder s Int
decodeIntCanonical forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
-1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2Crv
-2 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2X
-3 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyTypeParameterEC2
CoseKeyTypeParameterEC2Y
Int
value -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown COSE key type parameter " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
value forall a. Semigroup a => a -> a -> a
<> String
" for key type EC2"
data CoseEllipticCurveEC2
=
CoseEllipticCurveEC2P256
|
CoseEllipticCurveEC2P384
|
CoseEllipticCurveEC2P521
deriving (CoseEllipticCurveEC2 -> CoseEllipticCurveEC2 -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoseEllipticCurveEC2 -> CoseEllipticCurveEC2 -> Bool
$c/= :: CoseEllipticCurveEC2 -> CoseEllipticCurveEC2 -> Bool
== :: CoseEllipticCurveEC2 -> CoseEllipticCurveEC2 -> Bool
$c== :: CoseEllipticCurveEC2 -> CoseEllipticCurveEC2 -> Bool
Eq, Int -> CoseEllipticCurveEC2 -> ShowS
[CoseEllipticCurveEC2] -> ShowS
CoseEllipticCurveEC2 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoseEllipticCurveEC2] -> ShowS
$cshowList :: [CoseEllipticCurveEC2] -> ShowS
show :: CoseEllipticCurveEC2 -> String
$cshow :: CoseEllipticCurveEC2 -> String
showsPrec :: Int -> CoseEllipticCurveEC2 -> ShowS
$cshowsPrec :: Int -> CoseEllipticCurveEC2 -> ShowS
Show)
instance Serialise CoseEllipticCurveEC2 where
encode :: CoseEllipticCurveEC2 -> Encoding
encode CoseEllipticCurveEC2
CoseEllipticCurveEC2P256 = Int -> Encoding
encodeInt Int
1
encode CoseEllipticCurveEC2
CoseEllipticCurveEC2P384 = Int -> Encoding
encodeInt Int
2
encode CoseEllipticCurveEC2
CoseEllipticCurveEC2P521 = Int -> Encoding
encodeInt Int
3
decode :: forall s. Decoder s CoseEllipticCurveEC2
decode =
forall s. Decoder s Int
decodeIntCanonical forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Int
1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseEllipticCurveEC2
CoseEllipticCurveEC2P256
Int
2 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseEllipticCurveEC2
CoseEllipticCurveEC2P384
Int
3 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseEllipticCurveEC2
CoseEllipticCurveEC2P521
Int
value -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown COSE elliptic curve " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
value forall a. Semigroup a => a -> a -> a
<> String
" for key type EC2"
data CoseKeyTypeParameterRSA
=
CoseKeyTypeParameterRSAN
|
CoseKeyTypeParameterRSAE
deriving (CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA -> Bool
$c/= :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA -> Bool
== :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA -> Bool
$c== :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA -> Bool
Eq, Int -> CoseKeyTypeParameterRSA -> ShowS
[CoseKeyTypeParameterRSA] -> ShowS
CoseKeyTypeParameterRSA -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoseKeyTypeParameterRSA] -> ShowS
$cshowList :: [CoseKeyTypeParameterRSA] -> ShowS
show :: CoseKeyTypeParameterRSA -> String
$cshow :: CoseKeyTypeParameterRSA -> String
showsPrec :: Int -> CoseKeyTypeParameterRSA -> ShowS
$cshowsPrec :: Int -> CoseKeyTypeParameterRSA -> ShowS
Show, CoseKeyTypeParameterRSA
forall a. a -> a -> Bounded a
maxBound :: CoseKeyTypeParameterRSA
$cmaxBound :: CoseKeyTypeParameterRSA
minBound :: CoseKeyTypeParameterRSA
$cminBound :: CoseKeyTypeParameterRSA
Bounded, Int -> CoseKeyTypeParameterRSA
CoseKeyTypeParameterRSA -> Int
CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA
CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA
-> [CoseKeyTypeParameterRSA]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA
-> [CoseKeyTypeParameterRSA]
$cenumFromThenTo :: CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA
-> [CoseKeyTypeParameterRSA]
enumFromTo :: CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
$cenumFromTo :: CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
enumFromThen :: CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
$cenumFromThen :: CoseKeyTypeParameterRSA
-> CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
enumFrom :: CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
$cenumFrom :: CoseKeyTypeParameterRSA -> [CoseKeyTypeParameterRSA]
fromEnum :: CoseKeyTypeParameterRSA -> Int
$cfromEnum :: CoseKeyTypeParameterRSA -> Int
toEnum :: Int -> CoseKeyTypeParameterRSA
$ctoEnum :: Int -> CoseKeyTypeParameterRSA
pred :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA
$cpred :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA
succ :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA
$csucc :: CoseKeyTypeParameterRSA -> CoseKeyTypeParameterRSA
Enum)
instance Serialise CoseKeyTypeParameterRSA where
encode :: CoseKeyTypeParameterRSA -> Encoding
encode CoseKeyTypeParameterRSA
CoseKeyTypeParameterRSAN = Int -> Encoding
encodeInt (-Int
1)
encode CoseKeyTypeParameterRSA
CoseKeyTypeParameterRSAE = Int -> Encoding
encodeInt (-Int
2)
decode :: forall s. Decoder s CoseKeyTypeParameterRSA
decode =
forall s. Decoder s Int
decodeIntCanonical forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
-1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyTypeParameterRSA
CoseKeyTypeParameterRSAN
-2 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure CoseKeyTypeParameterRSA
CoseKeyTypeParameterRSAE
Int
value -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Unknown COSE key type parameter " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
value forall a. Semigroup a => a -> a -> a
<> String
" for key type RSA"
parameterCount :: CoseKeyType -> Word
parameterCount :: CoseKeyType -> Word
parameterCount CoseKeyType
CoseKeyTypeOKP = forall a b. (Bounded a, Enum a, Num b) => b
cardinality @CoseKeyCommonParameter forall a. Num a => a -> a -> a
+ forall a b. (Bounded a, Enum a, Num b) => b
cardinality @CoseKeyTypeParameterOKP
parameterCount CoseKeyType
CoseKeyTypeEC2 = forall a b. (Bounded a, Enum a, Num b) => b
cardinality @CoseKeyCommonParameter forall a. Num a => a -> a -> a
+ forall a b. (Bounded a, Enum a, Num b) => b
cardinality @CoseKeyTypeParameterEC2
parameterCount CoseKeyType
CoseKeyTypeRSA = forall a b. (Bounded a, Enum a, Num b) => b
cardinality @CoseKeyCommonParameter forall a. Num a => a -> a -> a
+ forall a b. (Bounded a, Enum a, Num b) => b
cardinality @CoseKeyTypeParameterRSA
cardinality :: forall a b. (Bounded a, Enum a, Num b) => b
cardinality :: forall a b. (Bounded a, Enum a, Num b) => b
cardinality = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Int
1 forall a. Num a => a -> a -> a
+ forall a. Enum a => a -> Int
fromEnum @a forall a. Bounded a => a
maxBound forall a. Num a => a -> a -> a
- forall a. Enum a => a -> Int
fromEnum @a forall a. Bounded a => a
minBound