-- SignatureQualities.hs: OpenPGP (RFC4880) signature qualities
-- Copyright © 2012-2019  Clint Adams
-- This software is released under the terms of the Expat license.
-- (See the LICENSE file).
module Codec.Encryption.OpenPGP.SignatureQualities
  ( sigType
  , sigPKA
  , sigHA
  , sigCT
  ) where

import Data.List (find)

import Codec.Encryption.OpenPGP.Ontology (isSigCreationTime)
import Codec.Encryption.OpenPGP.Types

sigType :: SignaturePayload -> Maybe SigType
sigType :: SignaturePayload -> Maybe SigType
sigType (SigV3 st :: SigType
st _ _ _ _ _ _) = SigType -> Maybe SigType
forall a. a -> Maybe a
Just SigType
st
sigType (SigV4 st :: SigType
st _ _ _ _ _ _) = SigType -> Maybe SigType
forall a. a -> Maybe a
Just SigType
st
sigType _ = Maybe SigType
forall a. Maybe a
Nothing -- this includes v2 sigs, which don't seem to be specified in the RFCs but exist in the wild

sigPKA :: SignaturePayload -> Maybe PubKeyAlgorithm
sigPKA :: SignaturePayload -> Maybe PubKeyAlgorithm
sigPKA (SigV3 _ _ _ pka :: PubKeyAlgorithm
pka _ _ _) = PubKeyAlgorithm -> Maybe PubKeyAlgorithm
forall a. a -> Maybe a
Just PubKeyAlgorithm
pka
sigPKA (SigV4 _ pka :: PubKeyAlgorithm
pka _ _ _ _ _) = PubKeyAlgorithm -> Maybe PubKeyAlgorithm
forall a. a -> Maybe a
Just PubKeyAlgorithm
pka
sigPKA _ = Maybe PubKeyAlgorithm
forall a. Maybe a
Nothing -- this includes v2 sigs, which don't seem to be specified in the RFCs but exist in the wild

sigHA :: SignaturePayload -> Maybe HashAlgorithm
sigHA :: SignaturePayload -> Maybe HashAlgorithm
sigHA (SigV3 _ _ _ _ ha :: HashAlgorithm
ha _ _) = HashAlgorithm -> Maybe HashAlgorithm
forall a. a -> Maybe a
Just HashAlgorithm
ha
sigHA (SigV4 _ _ ha :: HashAlgorithm
ha _ _ _ _) = HashAlgorithm -> Maybe HashAlgorithm
forall a. a -> Maybe a
Just HashAlgorithm
ha
sigHA _ = Maybe HashAlgorithm
forall a. Maybe a
Nothing -- this includes v2 sigs, which don't seem to be specified in the RFCs but exist in the wild

sigCT :: SignaturePayload -> Maybe ThirtyTwoBitTimeStamp
sigCT :: SignaturePayload -> Maybe ThirtyTwoBitTimeStamp
sigCT (SigV3 _ ct :: ThirtyTwoBitTimeStamp
ct _ _ _ _ _) = ThirtyTwoBitTimeStamp -> Maybe ThirtyTwoBitTimeStamp
forall a. a -> Maybe a
Just ThirtyTwoBitTimeStamp
ct
sigCT (SigV4 _ _ _ hsubs :: [SigSubPacket]
hsubs _ _ _) =
  (SigSubPacket -> ThirtyTwoBitTimeStamp)
-> Maybe SigSubPacket -> Maybe ThirtyTwoBitTimeStamp
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    (\(SigSubPacket _ (SigCreationTime i :: ThirtyTwoBitTimeStamp
i)) -> ThirtyTwoBitTimeStamp
i)
    ((SigSubPacket -> Bool) -> [SigSubPacket] -> Maybe SigSubPacket
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find SigSubPacket -> Bool
isSigCreationTime [SigSubPacket]
hsubs)
sigCT _ = Maybe ThirtyTwoBitTimeStamp
forall a. Maybe a
Nothing