-- |
-- Module      : Data.X509.AlgorithmIdentifier
-- License     : BSD-style
-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
-- Stability   : experimental
-- Portability : unknown
module Data.X509.AlgorithmIdentifier (
    HashALG (..),
    PubKeyALG (..),
    SignatureALG (..),
    PSSParams,
    pssHash,
    pssMGFHash,
    pssSaltLength,
    defaultPSSParams,
    rsaPSSSignatureALG,
    signatureALGPSSParams,

    -- * Internal
    pssKeyParamsFromASN1,
    pssKeyAlgToASN1,
) where

import Data.ASN1.Types
import Data.List (find)

-- | Hash Algorithm
data HashALG
    = HashMD2
    | HashMD5
    | HashSHA1
    | HashSHA224
    | HashSHA256
    | HashSHA384
    | HashSHA512
    | HashSHA3_224
    | HashSHA3_256
    | HashSHA3_384
    | HashSHA3_512
    deriving (Int -> HashALG -> ShowS
[HashALG] -> ShowS
HashALG -> String
(Int -> HashALG -> ShowS)
-> (HashALG -> String) -> ([HashALG] -> ShowS) -> Show HashALG
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HashALG -> ShowS
showsPrec :: Int -> HashALG -> ShowS
$cshow :: HashALG -> String
show :: HashALG -> String
$cshowList :: [HashALG] -> ShowS
showList :: [HashALG] -> ShowS
Show, HashALG -> HashALG -> Bool
(HashALG -> HashALG -> Bool)
-> (HashALG -> HashALG -> Bool) -> Eq HashALG
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HashALG -> HashALG -> Bool
== :: HashALG -> HashALG -> Bool
$c/= :: HashALG -> HashALG -> Bool
/= :: HashALG -> HashALG -> Bool
Eq)

-- | Public Key Algorithm
data PubKeyALG
    = -- | RSA Public Key algorithm
      PubKeyALG_RSA
    | -- | RSA PSS Key algorithm (RFC 3447)
      PubKeyALG_RSAPSS
    | -- | DSA Public Key algorithm
      PubKeyALG_DSA
    | -- | ECDSA & ECDH Public Key algorithm
      PubKeyALG_EC
    | -- | ECDH 25519 key agreement
      PubKeyALG_X25519
    | -- | ECDH 448 key agreement
      PubKeyALG_X448
    | -- | EdDSA 25519 signature algorithm
      PubKeyALG_Ed25519
    | -- | EdDSA 448 signature algorithm
      PubKeyALG_Ed448
    | -- | ML-DSA-44 signature algorithm (RFC 9881)
      PubKeyALG_MLDSA44
    | -- | ML-DSA-65 signature algorithm (RFC 9881)
      PubKeyALG_MLDSA65
    | -- | ML-DSA-87 signature algorithm (RFC 9881)
      PubKeyALG_MLDSA87
    | -- | ML-KEM-512 key encapsulation (RFC 9935)
      PubKeyALG_MLKEM512
    | -- | ML-KEM-768 key encapsulation (RFC 9935)
      PubKeyALG_MLKEM768
    | -- | ML-KEM-1024 key encapsulation (RFC 9935)
      PubKeyALG_MLKEM1024
    | -- | Diffie Hellman Public Key algorithm
      PubKeyALG_DH
    | -- | Unknown Public Key algorithm
      PubKeyALG_Unknown OID
    deriving (Int -> PubKeyALG -> ShowS
[PubKeyALG] -> ShowS
PubKeyALG -> String
(Int -> PubKeyALG -> ShowS)
-> (PubKeyALG -> String)
-> ([PubKeyALG] -> ShowS)
-> Show PubKeyALG
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PubKeyALG -> ShowS
showsPrec :: Int -> PubKeyALG -> ShowS
$cshow :: PubKeyALG -> String
show :: PubKeyALG -> String
$cshowList :: [PubKeyALG] -> ShowS
showList :: [PubKeyALG] -> ShowS
Show, PubKeyALG -> PubKeyALG -> Bool
(PubKeyALG -> PubKeyALG -> Bool)
-> (PubKeyALG -> PubKeyALG -> Bool) -> Eq PubKeyALG
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PubKeyALG -> PubKeyALG -> Bool
== :: PubKeyALG -> PubKeyALG -> Bool
$c/= :: PubKeyALG -> PubKeyALG -> Bool
/= :: PubKeyALG -> PubKeyALG -> Bool
Eq)

-- | Signature Algorithm, often composed of a public key algorithm and a hash
-- algorithm.  For some signature algorithms the hash algorithm is intrinsic to
-- the public key algorithm and is not needed in the data type.
data SignatureALG
    = SignatureALG HashALG PubKeyALG
    | SignatureALG_IntrinsicHash PubKeyALG
    | SignatureALG_Unknown OID
    | -- | RSASSA-PSS with parameters other than 'defaultPSSParams'.  With the
      -- default parameters, @SignatureALG h PubKeyALG_RSAPSS@ is used instead;
      -- 'rsaPSSSignatureALG' picks the right form.
      SignatureALG_RSAPSS PSSParams
    deriving (Int -> SignatureALG -> ShowS
[SignatureALG] -> ShowS
SignatureALG -> String
(Int -> SignatureALG -> ShowS)
-> (SignatureALG -> String)
-> ([SignatureALG] -> ShowS)
-> Show SignatureALG
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SignatureALG -> ShowS
showsPrec :: Int -> SignatureALG -> ShowS
$cshow :: SignatureALG -> String
show :: SignatureALG -> String
$cshowList :: [SignatureALG] -> ShowS
showList :: [SignatureALG] -> ShowS
Show, SignatureALG -> SignatureALG -> Bool
(SignatureALG -> SignatureALG -> Bool)
-> (SignatureALG -> SignatureALG -> Bool) -> Eq SignatureALG
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SignatureALG -> SignatureALG -> Bool
== :: SignatureALG -> SignatureALG -> Bool
$c/= :: SignatureALG -> SignatureALG -> Bool
/= :: SignatureALG -> SignatureALG -> Bool
Eq)

-- | RSASSA-PSS parameters (RFC 4055).  Only MGF1 and the trailer field 1
-- are supported.  The constructor is hidden; use 'defaultPSSParams' and
-- record update syntax.
data PSSParams = PSSParams
    { PSSParams -> HashALG
pssHash :: HashALG
    -- ^ The message hash
    , PSSParams -> HashALG
pssMGFHash :: HashALG
    -- ^ The hash used by MGF1
    , PSSParams -> Int
pssSaltLength :: Int
    -- ^ The salt length in bytes
    }
    deriving (Int -> PSSParams -> ShowS
[PSSParams] -> ShowS
PSSParams -> String
(Int -> PSSParams -> ShowS)
-> (PSSParams -> String)
-> ([PSSParams] -> ShowS)
-> Show PSSParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PSSParams -> ShowS
showsPrec :: Int -> PSSParams -> ShowS
$cshow :: PSSParams -> String
show :: PSSParams -> String
$cshowList :: [PSSParams] -> ShowS
showList :: [PSSParams] -> ShowS
Show, PSSParams -> PSSParams -> Bool
(PSSParams -> PSSParams -> Bool)
-> (PSSParams -> PSSParams -> Bool) -> Eq PSSParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PSSParams -> PSSParams -> Bool
== :: PSSParams -> PSSParams -> Bool
$c/= :: PSSParams -> PSSParams -> Bool
/= :: PSSParams -> PSSParams -> Bool
Eq)

-- | The hash for both the message and MGF1, and the salt length equal to
-- the hash length.
defaultPSSParams :: HashALG -> PSSParams
defaultPSSParams :: HashALG -> PSSParams
defaultPSSParams HashALG
h = HashALG -> HashALG -> Int -> PSSParams
PSSParams HashALG
h HashALG
h (HashALG -> Int
hashLength HashALG
h)

hashLength :: HashALG -> Int
hashLength :: HashALG -> Int
hashLength HashALG
HashMD2 = Int
16
hashLength HashALG
HashMD5 = Int
16
hashLength HashALG
HashSHA1 = Int
20
hashLength HashALG
HashSHA224 = Int
28
hashLength HashALG
HashSHA256 = Int
32
hashLength HashALG
HashSHA384 = Int
48
hashLength HashALG
HashSHA512 = Int
64
hashLength HashALG
HashSHA3_224 = Int
28
hashLength HashALG
HashSHA3_256 = Int
32
hashLength HashALG
HashSHA3_384 = Int
48
hashLength HashALG
HashSHA3_512 = Int
64

-- | The RSASSA-PSS signature algorithm with the given parameters.
rsaPSSSignatureALG :: PSSParams -> SignatureALG
rsaPSSSignatureALG :: PSSParams -> SignatureALG
rsaPSSSignatureALG PSSParams
p
    | PSSParams
p PSSParams -> PSSParams -> Bool
forall a. Eq a => a -> a -> Bool
== HashALG -> PSSParams
defaultPSSParams HashALG
h = HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
h PubKeyALG
PubKeyALG_RSAPSS
    | Bool
otherwise = PSSParams -> SignatureALG
SignatureALG_RSAPSS PSSParams
p
  where
    h :: HashALG
h = PSSParams -> HashALG
pssHash PSSParams
p

-- | The RSASSA-PSS parameters of a signature algorithm, if any.
signatureALGPSSParams :: SignatureALG -> Maybe PSSParams
signatureALGPSSParams :: SignatureALG -> Maybe PSSParams
signatureALGPSSParams (SignatureALG HashALG
h PubKeyALG
PubKeyALG_RSAPSS) = PSSParams -> Maybe PSSParams
forall a. a -> Maybe a
Just (HashALG -> PSSParams
defaultPSSParams HashALG
h)
signatureALGPSSParams (SignatureALG_RSAPSS PSSParams
p) = PSSParams -> Maybe PSSParams
forall a. a -> Maybe a
Just PSSParams
p
signatureALGPSSParams SignatureALG
_ = Maybe PSSParams
forall a. Maybe a
Nothing

instance OIDable PubKeyALG where
    getObjectID :: PubKeyALG -> OID
getObjectID PubKeyALG
PubKeyALG_RSA = [Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
1]
    getObjectID PubKeyALG
PubKeyALG_RSAPSS = [Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
10]
    getObjectID PubKeyALG
PubKeyALG_DSA = [Integer
1, Integer
2, Integer
840, Integer
10040, Integer
4, Integer
1]
    getObjectID PubKeyALG
PubKeyALG_EC = [Integer
1, Integer
2, Integer
840, Integer
10045, Integer
2, Integer
1]
    getObjectID PubKeyALG
PubKeyALG_X25519 = [Integer
1, Integer
3, Integer
101, Integer
110]
    getObjectID PubKeyALG
PubKeyALG_X448 = [Integer
1, Integer
3, Integer
101, Integer
111]
    getObjectID PubKeyALG
PubKeyALG_Ed25519 = [Integer
1, Integer
3, Integer
101, Integer
112]
    getObjectID PubKeyALG
PubKeyALG_Ed448 = [Integer
1, Integer
3, Integer
101, Integer
113]
    getObjectID PubKeyALG
PubKeyALG_MLDSA44 = [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
17]
    getObjectID PubKeyALG
PubKeyALG_MLDSA65 = [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
18]
    getObjectID PubKeyALG
PubKeyALG_MLDSA87 = [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
19]
    getObjectID PubKeyALG
PubKeyALG_MLKEM512 = [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
4, Integer
1]
    getObjectID PubKeyALG
PubKeyALG_MLKEM768 = [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
4, Integer
2]
    getObjectID PubKeyALG
PubKeyALG_MLKEM1024 = [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
4, Integer
3]
    getObjectID PubKeyALG
PubKeyALG_DH = [Integer
1, Integer
2, Integer
840, Integer
10046, Integer
2, Integer
1]
    getObjectID (PubKeyALG_Unknown OID
oid) = OID
oid

sig_table :: [(OID, SignatureALG)]
sig_table :: [(OID, SignatureALG)]
sig_table =
    [ ([Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
5], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA1 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
4], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashMD5 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
2], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashMD2 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
11], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA256 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
12], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA384 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
13], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA512 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
14], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA224 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
10040, Integer
4, Integer
3], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA1 PubKeyALG
PubKeyALG_DSA)
    , ([Integer
1, Integer
2, Integer
840, Integer
10045, Integer
4, Integer
1], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA1 PubKeyALG
PubKeyALG_EC)
    , ([Integer
1, Integer
2, Integer
840, Integer
10045, Integer
4, Integer
3, Integer
1], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA224 PubKeyALG
PubKeyALG_EC)
    , ([Integer
1, Integer
2, Integer
840, Integer
10045, Integer
4, Integer
3, Integer
2], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA256 PubKeyALG
PubKeyALG_EC)
    , ([Integer
1, Integer
2, Integer
840, Integer
10045, Integer
4, Integer
3, Integer
3], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA384 PubKeyALG
PubKeyALG_EC)
    , ([Integer
1, Integer
2, Integer
840, Integer
10045, Integer
4, Integer
3, Integer
4], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA512 PubKeyALG
PubKeyALG_EC)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
1], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA224 PubKeyALG
PubKeyALG_DSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
2], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA256 PubKeyALG
PubKeyALG_DSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
5], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_224 PubKeyALG
PubKeyALG_DSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
6], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_256 PubKeyALG
PubKeyALG_DSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
7], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_384 PubKeyALG
PubKeyALG_DSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
8], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_512 PubKeyALG
PubKeyALG_DSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
9], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_224 PubKeyALG
PubKeyALG_EC)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
10], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_256 PubKeyALG
PubKeyALG_EC)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
11], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_384 PubKeyALG
PubKeyALG_EC)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
12], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_512 PubKeyALG
PubKeyALG_EC)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
13], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_224 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
14], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_256 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
15], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_384 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
16], HashALG -> PubKeyALG -> SignatureALG
SignatureALG HashALG
HashSHA3_512 PubKeyALG
PubKeyALG_RSA)
    , ([Integer
1, Integer
3, Integer
101, Integer
112], PubKeyALG -> SignatureALG
SignatureALG_IntrinsicHash PubKeyALG
PubKeyALG_Ed25519)
    , ([Integer
1, Integer
3, Integer
101, Integer
113], PubKeyALG -> SignatureALG
SignatureALG_IntrinsicHash PubKeyALG
PubKeyALG_Ed448)
    ,
        ( [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
17]
        , PubKeyALG -> SignatureALG
SignatureALG_IntrinsicHash PubKeyALG
PubKeyALG_MLDSA44
        )
    ,
        ( [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
18]
        , PubKeyALG -> SignatureALG
SignatureALG_IntrinsicHash PubKeyALG
PubKeyALG_MLDSA65
        )
    ,
        ( [Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
3, Integer
19]
        , PubKeyALG -> SignatureALG
SignatureALG_IntrinsicHash PubKeyALG
PubKeyALG_MLDSA87
        )
    ]

-- | Hash algorithms in RSASSA-PSS parameters.
pssHashTable :: [(OID, HashALG)]
pssHashTable :: [(OID, HashALG)]
pssHashTable =
    [ ([Integer
1, Integer
3, Integer
14, Integer
3, Integer
2, Integer
26], HashALG
HashSHA1)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
1], HashALG
HashSHA256)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
2], HashALG
HashSHA384)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
3], HashALG
HashSHA512)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
4], HashALG
HashSHA224)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
7], HashALG
HashSHA3_224)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
8], HashALG
HashSHA3_256)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
9], HashALG
HashSHA3_384)
    , ([Integer
2, Integer
16, Integer
840, Integer
1, Integer
101, Integer
3, Integer
4, Integer
2, Integer
10], HashALG
HashSHA3_512)
    ]

pssHashOID :: HashALG -> OID
pssHashOID :: HashALG -> OID
pssHashOID HashALG
h =
    OID -> ((OID, HashALG) -> OID) -> Maybe (OID, HashALG) -> OID
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> OID
forall a. HasCallStack => String -> a
error (String
"unknown PSS hash " String -> ShowS
forall a. [a] -> [a] -> [a]
++ HashALG -> String
forall a. Show a => a -> String
show HashALG
h)) (OID, HashALG) -> OID
forall a b. (a, b) -> a
fst (Maybe (OID, HashALG) -> OID) -> Maybe (OID, HashALG) -> OID
forall a b. (a -> b) -> a -> b
$
        ((OID, HashALG) -> Bool)
-> [(OID, HashALG)] -> Maybe (OID, HashALG)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (HashALG -> HashALG -> Bool
forall a. Eq a => a -> a -> Bool
(==) HashALG
h (HashALG -> Bool)
-> ((OID, HashALG) -> HashALG) -> (OID, HashALG) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OID, HashALG) -> HashALG
forall a b. (a, b) -> b
snd) [(OID, HashALG)]
pssHashTable

oidSig :: OID -> SignatureALG
oidSig :: OID -> SignatureALG
oidSig OID
oid = SignatureALG
-> (SignatureALG -> SignatureALG)
-> Maybe SignatureALG
-> SignatureALG
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (OID -> SignatureALG
SignatureALG_Unknown OID
oid) SignatureALG -> SignatureALG
forall a. a -> a
id (Maybe SignatureALG -> SignatureALG)
-> Maybe SignatureALG -> SignatureALG
forall a b. (a -> b) -> a -> b
$ OID -> [(OID, SignatureALG)] -> Maybe SignatureALG
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup OID
oid [(OID, SignatureALG)]
sig_table

sigOID :: SignatureALG -> OID
sigOID :: SignatureALG -> OID
sigOID (SignatureALG_Unknown OID
oid) = OID
oid
sigOID SignatureALG
sig =
    OID
-> ((OID, SignatureALG) -> OID) -> Maybe (OID, SignatureALG) -> OID
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> OID
forall a. HasCallStack => String -> a
error (String
"unknown OID for " String -> ShowS
forall a. [a] -> [a] -> [a]
++ SignatureALG -> String
forall a. Show a => a -> String
show SignatureALG
sig)) (OID, SignatureALG) -> OID
forall a b. (a, b) -> a
fst (Maybe (OID, SignatureALG) -> OID)
-> Maybe (OID, SignatureALG) -> OID
forall a b. (a -> b) -> a -> b
$
        ((OID, SignatureALG) -> Bool)
-> [(OID, SignatureALG)] -> Maybe (OID, SignatureALG)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (SignatureALG -> SignatureALG -> Bool
forall a. Eq a => a -> a -> Bool
(==) SignatureALG
sig (SignatureALG -> Bool)
-> ((OID, SignatureALG) -> SignatureALG)
-> (OID, SignatureALG)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OID, SignatureALG) -> SignatureALG
forall a b. (a, b) -> b
snd) [(OID, SignatureALG)]
sig_table

oidRSAPSS, oidMGF1 :: OID
oidRSAPSS :: OID
oidRSAPSS = [Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
10]
oidMGF1 :: OID
oidMGF1 = [Integer
1, Integer
2, Integer
840, Integer
113549, Integer
1, Integer
1, Integer
8]

-- | Parse the contents of RSASSA-PSS-params, after its 'Start' 'Sequence'.
parsePSSParams :: [ASN1] -> Either String (PSSParams, [ASN1])
parsePSSParams :: [ASN1] -> Either String (PSSParams, [ASN1])
parsePSSParams [ASN1]
xs0 = do
    (HashALG
h, [ASN1]
xs1) <- Int
-> ([ASN1] -> Either String (HashALG, [ASN1]))
-> HashALG
-> [ASN1]
-> Either String (HashALG, [ASN1])
forall {a}.
Int
-> ([ASN1] -> Either String (a, [ASN1]))
-> a
-> [ASN1]
-> Either String (a, [ASN1])
field Int
0 [ASN1] -> Either String (HashALG, [ASN1])
hashAlg HashALG
HashSHA1 [ASN1]
xs0
    (HashALG
m, [ASN1]
xs2) <- Int
-> ([ASN1] -> Either String (HashALG, [ASN1]))
-> HashALG
-> [ASN1]
-> Either String (HashALG, [ASN1])
forall {a}.
Int
-> ([ASN1] -> Either String (a, [ASN1]))
-> a
-> [ASN1]
-> Either String (a, [ASN1])
field Int
1 [ASN1] -> Either String (HashALG, [ASN1])
mgf HashALG
HashSHA1 [ASN1]
xs1
    (Int
s, [ASN1]
xs3) <- Int
-> ([ASN1] -> Either String (Int, [ASN1]))
-> Int
-> [ASN1]
-> Either String (Int, [ASN1])
forall {a}.
Int
-> ([ASN1] -> Either String (a, [ASN1]))
-> a
-> [ASN1]
-> Either String (a, [ASN1])
field Int
2 [ASN1] -> Either String (Int, [ASN1])
forall {a}. Num a => [ASN1] -> Either String (a, [ASN1])
int Int
20 [ASN1]
xs2
    (Int
t, [ASN1]
xs4) <- Int
-> ([ASN1] -> Either String (Int, [ASN1]))
-> Int
-> [ASN1]
-> Either String (Int, [ASN1])
forall {a}.
Int
-> ([ASN1] -> Either String (a, [ASN1]))
-> a
-> [ASN1]
-> Either String (a, [ASN1])
field Int
3 [ASN1] -> Either String (Int, [ASN1])
forall {a}. Num a => [ASN1] -> Either String (a, [ASN1])
int Int
1 [ASN1]
xs3
    case [ASN1]
xs4 of
        End ASN1ConstructionType
Sequence : [ASN1]
rest
            | Int
t Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
1 :: Int) -> (PSSParams, [ASN1]) -> Either String (PSSParams, [ASN1])
forall a b. b -> Either a b
Right (HashALG -> HashALG -> Int -> PSSParams
PSSParams HashALG
h HashALG
m Int
s, [ASN1]
rest)
        [ASN1]
_ -> String -> Either String (PSSParams, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: invalid PSS parameters"
  where
    field :: Int
-> ([ASN1] -> Either String (a, [ASN1]))
-> a
-> [ASN1]
-> Either String (a, [ASN1])
field Int
n [ASN1] -> Either String (a, [ASN1])
p a
_ (Start (Container ASN1Class
Context Int
n') : [ASN1]
xs)
        | Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n' = do
            (a
v, [ASN1]
ys) <- [ASN1] -> Either String (a, [ASN1])
p [ASN1]
xs
            case [ASN1]
ys of
                End (Container ASN1Class
Context Int
n'') : [ASN1]
zs | Int
n'' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n -> (a, [ASN1]) -> Either String (a, [ASN1])
forall a b. b -> Either a b
Right (a
v, [ASN1]
zs)
                [ASN1]
_ -> String -> Either String (a, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: invalid PSS parameters"
    field Int
_ [ASN1] -> Either String (a, [ASN1])
_ a
def [ASN1]
xs = (a, [ASN1]) -> Either String (a, [ASN1])
forall a b. b -> Either a b
Right (a
def, [ASN1]
xs)
    hashAlg :: [ASN1] -> Either String (HashALG, [ASN1])
hashAlg (Start ASN1ConstructionType
Sequence : OID OID
o : ASN1
Null : End ASN1ConstructionType
Sequence : [ASN1]
xs) = OID -> [ASN1] -> Either String (HashALG, [ASN1])
forall {b}. OID -> b -> Either String (HashALG, b)
hashOID OID
o [ASN1]
xs
    hashAlg (Start ASN1ConstructionType
Sequence : OID OID
o : End ASN1ConstructionType
Sequence : [ASN1]
xs) = OID -> [ASN1] -> Either String (HashALG, [ASN1])
forall {b}. OID -> b -> Either String (HashALG, b)
hashOID OID
o [ASN1]
xs
    hashAlg [ASN1]
_ = String -> Either String (HashALG, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: invalid PSS hash"
    hashOID :: OID -> b -> Either String (HashALG, b)
hashOID OID
o b
xs = case OID -> [(OID, HashALG)] -> Maybe HashALG
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup OID
o [(OID, HashALG)]
pssHashTable of
        Just HashALG
h -> (HashALG, b) -> Either String (HashALG, b)
forall a b. b -> Either a b
Right (HashALG
h, b
xs)
        Maybe HashALG
Nothing -> String -> Either String (HashALG, b)
forall a b. a -> Either a b
Left (String
"fromASN1: X509.SignatureALG: unknown PSS hash " String -> ShowS
forall a. [a] -> [a] -> [a]
++ OID -> String
forall a. Show a => a -> String
show OID
o)
    mgf :: [ASN1] -> Either String (HashALG, [ASN1])
mgf (Start ASN1ConstructionType
Sequence : OID OID
o : [ASN1]
xs)
        | OID
o OID -> OID -> Bool
forall a. Eq a => a -> a -> Bool
== OID
oidMGF1 = do
            (HashALG
h, [ASN1]
ys) <- [ASN1] -> Either String (HashALG, [ASN1])
hashAlg [ASN1]
xs
            case [ASN1]
ys of
                End ASN1ConstructionType
Sequence : [ASN1]
zs -> (HashALG, [ASN1]) -> Either String (HashALG, [ASN1])
forall a b. b -> Either a b
Right (HashALG
h, [ASN1]
zs)
                [ASN1]
_ -> String -> Either String (HashALG, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: invalid MGF1"
    mgf [ASN1]
_ = String -> Either String (HashALG, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: unsupported mask generation function"
    int :: [ASN1] -> Either String (a, [ASN1])
int (IntVal Integer
i : [ASN1]
xs)
        | Integer
i Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
0 Bool -> Bool -> Bool
&& Integer
i Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
65536 = (a, [ASN1]) -> Either String (a, [ASN1])
forall a b. b -> Either a b
Right (Integer -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i, [ASN1]
xs)
    int [ASN1]
_ = String -> Either String (a, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: invalid PSS integer"

-- | Encode an AlgorithmIdentifier of RSASSA-PSS with its parameters,
-- omitting the DER default values.  Hash identifiers have NULL
-- parameters as in RFC 4055 2.1.
encodePSSParams :: PSSParams -> [ASN1] -> [ASN1]
encodePSSParams :: PSSParams -> [ASN1] -> [ASN1]
encodePSSParams PSSParams
p [ASN1]
xs =
    ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: OID -> ASN1
OID OID
oidRSAPSS ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: PSSParams -> [ASN1] -> [ASN1]
pssParamsToASN1 PSSParams
p (ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs)

pssParamsToASN1 :: PSSParams -> [ASN1] -> [ASN1]
pssParamsToASN1 :: PSSParams -> [ASN1] -> [ASN1]
pssParamsToASN1 (PSSParams HashALG
h HashALG
m Int
s) [ASN1]
xs =
    ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ([ASN1]
hashField [ASN1] -> [ASN1] -> [ASN1]
forall a. [a] -> [a] -> [a]
++ [ASN1]
mgfField [ASN1] -> [ASN1] -> [ASN1]
forall a. [a] -> [a] -> [a]
++ [ASN1]
saltField [ASN1] -> [ASN1] -> [ASN1]
forall a. [a] -> [a] -> [a]
++ ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs)
  where
    hashField :: [ASN1]
hashField
        | HashALG
h HashALG -> HashALG -> Bool
forall a. Eq a => a -> a -> Bool
== HashALG
HashSHA1 = []
        | Bool
otherwise = Int -> [ASN1] -> [ASN1]
ctx Int
0 [ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence, OID -> ASN1
OID (HashALG -> OID
pssHashOID HashALG
h), ASN1
Null, ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence]
    mgfField :: [ASN1]
mgfField
        | HashALG
m HashALG -> HashALG -> Bool
forall a. Eq a => a -> a -> Bool
== HashALG
HashSHA1 = []
        | Bool
otherwise =
            Int -> [ASN1] -> [ASN1]
ctx Int
1 ([ASN1] -> [ASN1]) -> [ASN1] -> [ASN1]
forall a b. (a -> b) -> a -> b
$
                [ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence, OID -> ASN1
OID OID
oidMGF1, ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence, OID -> ASN1
OID (HashALG -> OID
pssHashOID HashALG
m), ASN1
Null]
                    [ASN1] -> [ASN1] -> [ASN1]
forall a. [a] -> [a] -> [a]
++ [ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence, ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence]
    saltField :: [ASN1]
saltField
        | Int
s Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
20 = []
        | Bool
otherwise = Int -> [ASN1] -> [ASN1]
ctx Int
2 [Integer -> ASN1
IntVal (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
s)]
    ctx :: Int -> [ASN1] -> [ASN1]
ctx Int
n [ASN1]
l = ASN1ConstructionType -> ASN1
Start (ASN1Class -> Int -> ASN1ConstructionType
Container ASN1Class
Context Int
n) ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
l [ASN1] -> [ASN1] -> [ASN1]
forall a. [a] -> [a] -> [a]
++ [ASN1ConstructionType -> ASN1
End (ASN1Class -> Int -> ASN1ConstructionType
Container ASN1Class
Context Int
n)]

-- | Parse the rest of an RSASSA-PSS key AlgorithmIdentifier, after its
-- OID, up to and including its 'End' 'Sequence'.  Absent parameters
-- (RFC 4055 1.2) mean that the key is not restricted.
pssKeyParamsFromASN1 :: [ASN1] -> Either String (Maybe PSSParams, [ASN1])
pssKeyParamsFromASN1 :: [ASN1] -> Either String (Maybe PSSParams, [ASN1])
pssKeyParamsFromASN1 (End ASN1ConstructionType
Sequence : [ASN1]
xs) = (Maybe PSSParams, [ASN1])
-> Either String (Maybe PSSParams, [ASN1])
forall a b. b -> Either a b
Right (Maybe PSSParams
forall a. Maybe a
Nothing, [ASN1]
xs)
pssKeyParamsFromASN1 (ASN1
Null : End ASN1ConstructionType
Sequence : [ASN1]
xs) = (Maybe PSSParams, [ASN1])
-> Either String (Maybe PSSParams, [ASN1])
forall a b. b -> Either a b
Right (Maybe PSSParams
forall a. Maybe a
Nothing, [ASN1]
xs)
pssKeyParamsFromASN1 (Start ASN1ConstructionType
Sequence : [ASN1]
xs) = do
    (PSSParams
p, [ASN1]
ys) <- [ASN1] -> Either String (PSSParams, [ASN1])
parsePSSParams [ASN1]
xs
    case [ASN1]
ys of
        End ASN1ConstructionType
Sequence : [ASN1]
zs -> (Maybe PSSParams, [ASN1])
-> Either String (Maybe PSSParams, [ASN1])
forall a b. b -> Either a b
Right (PSSParams -> Maybe PSSParams
forall a. a -> Maybe a
Just PSSParams
p, [ASN1]
zs)
        [ASN1]
_ -> String -> Either String (Maybe PSSParams, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: RSASSA-PSS key: invalid parameters"
pssKeyParamsFromASN1 [ASN1]
_ = String -> Either String (Maybe PSSParams, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: RSASSA-PSS key: invalid parameters"

-- | Encode an AlgorithmIdentifier of an RSASSA-PSS key.
pssKeyAlgToASN1 :: Maybe PSSParams -> [ASN1] -> [ASN1]
pssKeyAlgToASN1 :: Maybe PSSParams -> [ASN1] -> [ASN1]
pssKeyAlgToASN1 Maybe PSSParams
mp [ASN1]
xs =
    ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: OID -> ASN1
OID OID
oidRSAPSS ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ([ASN1] -> [ASN1])
-> (PSSParams -> [ASN1] -> [ASN1])
-> Maybe PSSParams
-> [ASN1]
-> [ASN1]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [ASN1] -> [ASN1]
forall a. a -> a
id PSSParams -> [ASN1] -> [ASN1]
pssParamsToASN1 Maybe PSSParams
mp (ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs)

instance ASN1Object SignatureALG where
    fromASN1 :: [ASN1] -> Either String (SignatureALG, [ASN1])
fromASN1 (Start ASN1ConstructionType
Sequence : OID OID
oid : ASN1
Null : End ASN1ConstructionType
Sequence : [ASN1]
xs) =
        case OID -> SignatureALG
oidSig OID
oid of
            SignatureALG_IntrinsicHash PubKeyALG
_ ->
                String -> Either String (SignatureALG, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: EdDSA and ML-DSA require absent parameter"
            SignatureALG
signatureAlg -> (SignatureALG, [ASN1]) -> Either String (SignatureALG, [ASN1])
forall a b. b -> Either a b
Right (SignatureALG
signatureAlg, [ASN1]
xs)
    fromASN1 (Start ASN1ConstructionType
Sequence : OID OID
oid : End ASN1ConstructionType
Sequence : [ASN1]
xs) =
        (SignatureALG, [ASN1]) -> Either String (SignatureALG, [ASN1])
forall a b. b -> Either a b
Right (OID -> SignatureALG
oidSig OID
oid, [ASN1]
xs)
    fromASN1 (Start ASN1ConstructionType
Sequence : OID OID
oid : Start ASN1ConstructionType
Sequence : [ASN1]
xs)
        | OID
oid OID -> OID -> Bool
forall a. Eq a => a -> a -> Bool
== OID
oidRSAPSS = do
            (PSSParams
p, [ASN1]
ys) <- [ASN1] -> Either String (PSSParams, [ASN1])
parsePSSParams [ASN1]
xs
            case [ASN1]
ys of
                End ASN1ConstructionType
Sequence : [ASN1]
zs -> (SignatureALG, [ASN1]) -> Either String (SignatureALG, [ASN1])
forall a b. b -> Either a b
Right (PSSParams -> SignatureALG
rsaPSSSignatureALG PSSParams
p, [ASN1]
zs)
                [ASN1]
_ -> String -> Either String (SignatureALG, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: invalid PSS parameters"
    fromASN1 [ASN1]
_ =
        String -> Either String (SignatureALG, [ASN1])
forall a b. a -> Either a b
Left String
"fromASN1: X509.SignatureALG: unknown format"
    toASN1 :: SignatureALG -> [ASN1] -> [ASN1]
toASN1 (SignatureALG_Unknown OID
oid) = \[ASN1]
xs -> ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: OID -> ASN1
OID OID
oid ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ASN1
Null ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs
    toASN1 (SignatureALG HashALG
h PubKeyALG
PubKeyALG_RSAPSS) = PSSParams -> [ASN1] -> [ASN1]
encodePSSParams (HashALG -> PSSParams
defaultPSSParams HashALG
h)
    toASN1 (SignatureALG_RSAPSS PSSParams
p) = PSSParams -> [ASN1] -> [ASN1]
encodePSSParams PSSParams
p
    toASN1 signatureAlg :: SignatureALG
signatureAlg@(SignatureALG_IntrinsicHash PubKeyALG
_) = \[ASN1]
xs -> ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: OID -> ASN1
OID (SignatureALG -> OID
sigOID SignatureALG
signatureAlg) ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs
    -- ECDSA: "the encoding MUST omit the parameters field"
    -- (RFC 5758 3.2, RFC 3279 2.2.3)
    toASN1 signatureAlg :: SignatureALG
signatureAlg@(SignatureALG HashALG
_ PubKeyALG
PubKeyALG_EC) = \[ASN1]
xs -> ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: OID -> ASN1
OID (SignatureALG -> OID
sigOID SignatureALG
signatureAlg) ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs
    -- DSA: "the encoding SHALL omit the parameters field"
    -- (RFC 5758 3.1, RFC 3279 2.2.2)
    toASN1 signatureAlg :: SignatureALG
signatureAlg@(SignatureALG HashALG
_ PubKeyALG
PubKeyALG_DSA) = \[ASN1]
xs -> ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: OID -> ASN1
OID (SignatureALG -> OID
sigOID SignatureALG
signatureAlg) ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs
    toASN1 SignatureALG
signatureAlg = \[ASN1]
xs -> ASN1ConstructionType -> ASN1
Start ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: OID -> ASN1
OID (SignatureALG -> OID
sigOID SignatureALG
signatureAlg) ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ASN1
Null ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: ASN1ConstructionType -> ASN1
End ASN1ConstructionType
Sequence ASN1 -> [ASN1] -> [ASN1]
forall a. a -> [a] -> [a]
: [ASN1]
xs