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