module Codec.Encryption.OpenPGP.Serialize
(
putSKAddendum
, getSecretKey
, parsePkts
) where
import Control.Applicative (many, some)
import Control.Lens ((^.), _1)
import Control.Monad (guard, replicateM, replicateM_)
import Crypto.Number.Basic (numBits)
import Crypto.Number.Serialize (i2osp, os2ip)
import qualified Crypto.PubKey.DSA as D
import qualified Crypto.PubKey.ECC.ECDSA as ECDSA
import qualified Crypto.PubKey.ECC.Types as ECCT
import qualified Crypto.PubKey.RSA as R
import Data.Bifunctor (bimap)
import Data.Binary (Binary, get, put)
import Data.Binary.Get
( ByteOffset
, Get
, getByteString
, getLazyByteString
, getRemainingLazyByteString
, getWord16be
, getWord16le
, getWord32be
, getWord8
, runGetOrFail
)
import Data.Binary.Put
( Put
, putByteString
, putLazyByteString
, putWord16be
, putWord16le
, putWord32be
, putWord8
, runPut
)
import Data.Bits ((.&.), (.|.), shiftL, shiftR, testBit)
import qualified Data.ByteString as B
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BL
import qualified Data.Foldable as F
import Data.List (mapAccumL)
import qualified Data.List.NonEmpty as NE
import Data.Maybe (fromMaybe)
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8With, encodeUtf8)
import Data.Text.Encoding.Error (lenientDecode)
import Data.Word (Word16, Word32, Word8)
import Network.URI (nullURI, parseURI, uriToString)
import Codec.Encryption.OpenPGP.Internal
( curve2Curve
, curveFromCurve
, curveToCurveoidBS
, curveoidBSToCurve
, curveoidBSToEdSigningCurve
, edSigningCurveToCurveoidBS
, multiplicativeInverse
, pubkeyToMPIs
)
import Codec.Encryption.OpenPGP.Types
instance Binary SigSubPacket where
get :: Get SigSubPacket
get = Get SigSubPacket
getSigSubPacket
put :: SigSubPacket -> Put
put = SigSubPacket -> Put
putSigSubPacket
instance Binary CompressionAlgorithm where
get :: Get CompressionAlgorithm
get = Word8 -> CompressionAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> CompressionAlgorithm)
-> Get Word8 -> Get CompressionAlgorithm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
getWord8
put :: CompressionAlgorithm -> Put
put = Word8 -> Put
putWord8 (Word8 -> Put)
-> (CompressionAlgorithm -> Word8) -> CompressionAlgorithm -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompressionAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal
instance Binary PubKeyAlgorithm where
get :: Get PubKeyAlgorithm
get = Word8 -> PubKeyAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> PubKeyAlgorithm) -> Get Word8 -> Get PubKeyAlgorithm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
getWord8
put :: PubKeyAlgorithm -> Put
put = Word8 -> Put
putWord8 (Word8 -> Put)
-> (PubKeyAlgorithm -> Word8) -> PubKeyAlgorithm -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PubKeyAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal
instance Binary HashAlgorithm where
get :: Get HashAlgorithm
get = Word8 -> HashAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> HashAlgorithm) -> Get Word8 -> Get HashAlgorithm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
getWord8
put :: HashAlgorithm -> Put
put = Word8 -> Put
putWord8 (Word8 -> Put) -> (HashAlgorithm -> Word8) -> HashAlgorithm -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal
instance Binary SymmetricAlgorithm where
get :: Get SymmetricAlgorithm
get = Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> SymmetricAlgorithm)
-> Get Word8 -> Get SymmetricAlgorithm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
getWord8
put :: SymmetricAlgorithm -> Put
put = Word8 -> Put
putWord8 (Word8 -> Put)
-> (SymmetricAlgorithm -> Word8) -> SymmetricAlgorithm -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal
instance Binary MPI where
get :: Get MPI
get = Get MPI
getMPI
put :: MPI -> Put
put = MPI -> Put
putMPI
instance Binary SigType where
get :: Get SigType
get = Word8 -> SigType
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> SigType) -> Get Word8 -> Get SigType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
getWord8
put :: SigType -> Put
put = Word8 -> Put
putWord8 (Word8 -> Put) -> (SigType -> Word8) -> SigType -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SigType -> Word8
forall a. FutureVal a => a -> Word8
fromFVal
instance Binary UserAttrSubPacket where
get :: Get UserAttrSubPacket
get = Get UserAttrSubPacket
getUserAttrSubPacket
put :: UserAttrSubPacket -> Put
put = UserAttrSubPacket -> Put
putUserAttrSubPacket
instance Binary S2K where
get :: Get S2K
get = Get S2K
getS2K
put :: S2K -> Put
put = S2K -> Put
putS2K
instance Binary PKESK where
get :: Get PKESK
get = (Pkt -> PKESK) -> Get Pkt -> Get PKESK
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> PKESK
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: PKESK -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (PKESK -> Pkt) -> PKESK -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PKESK -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary Signature where
get :: Get Signature
get = (Pkt -> Signature) -> Get Pkt -> Get Signature
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> Signature
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: Signature -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (Signature -> Pkt) -> Signature -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Signature -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary SKESK where
get :: Get SKESK
get = (Pkt -> SKESK) -> Get Pkt -> Get SKESK
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> SKESK
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: SKESK -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (SKESK -> Pkt) -> SKESK -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SKESK -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary OnePassSignature where
get :: Get OnePassSignature
get = (Pkt -> OnePassSignature) -> Get Pkt -> Get OnePassSignature
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> OnePassSignature
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: OnePassSignature -> Put
put = Pkt -> Put
putPkt (Pkt -> Put)
-> (OnePassSignature -> Pkt) -> OnePassSignature -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnePassSignature -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary SecretKey where
get :: Get SecretKey
get = (Pkt -> SecretKey) -> Get Pkt -> Get SecretKey
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> SecretKey
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: SecretKey -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (SecretKey -> Pkt) -> SecretKey -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SecretKey -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary PublicKey where
get :: Get PublicKey
get = (Pkt -> PublicKey) -> Get Pkt -> Get PublicKey
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> PublicKey
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: PublicKey -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (PublicKey -> Pkt) -> PublicKey -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PublicKey -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary SecretSubkey where
get :: Get SecretSubkey
get = (Pkt -> SecretSubkey) -> Get Pkt -> Get SecretSubkey
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> SecretSubkey
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: SecretSubkey -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (SecretSubkey -> Pkt) -> SecretSubkey -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SecretSubkey -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary CompressedData where
get :: Get CompressedData
get = (Pkt -> CompressedData) -> Get Pkt -> Get CompressedData
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> CompressedData
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: CompressedData -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (CompressedData -> Pkt) -> CompressedData -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompressedData -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary SymEncData where
get :: Get SymEncData
get = (Pkt -> SymEncData) -> Get Pkt -> Get SymEncData
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> SymEncData
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: SymEncData -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (SymEncData -> Pkt) -> SymEncData -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymEncData -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary Marker where
get :: Get Marker
get = (Pkt -> Marker) -> Get Pkt -> Get Marker
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> Marker
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: Marker -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (Marker -> Pkt) -> Marker -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Marker -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary LiteralData where
get :: Get LiteralData
get = (Pkt -> LiteralData) -> Get Pkt -> Get LiteralData
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> LiteralData
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: LiteralData -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (LiteralData -> Pkt) -> LiteralData -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LiteralData -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary Trust where
get :: Get Trust
get = (Pkt -> Trust) -> Get Pkt -> Get Trust
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> Trust
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: Trust -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (Trust -> Pkt) -> Trust -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trust -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary UserId where
get :: Get UserId
get = (Pkt -> UserId) -> Get Pkt -> Get UserId
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> UserId
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: UserId -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (UserId -> Pkt) -> UserId -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UserId -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary PublicSubkey where
get :: Get PublicSubkey
get = (Pkt -> PublicSubkey) -> Get Pkt -> Get PublicSubkey
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> PublicSubkey
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: PublicSubkey -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (PublicSubkey -> Pkt) -> PublicSubkey -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PublicSubkey -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary UserAttribute where
get :: Get UserAttribute
get = (Pkt -> UserAttribute) -> Get Pkt -> Get UserAttribute
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> UserAttribute
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: UserAttribute -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (UserAttribute -> Pkt) -> UserAttribute -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UserAttribute -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary SymEncIntegrityProtectedData where
get :: Get SymEncIntegrityProtectedData
get = (Pkt -> SymEncIntegrityProtectedData)
-> Get Pkt -> Get SymEncIntegrityProtectedData
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> SymEncIntegrityProtectedData
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: SymEncIntegrityProtectedData -> Put
put = Pkt -> Put
putPkt (Pkt -> Put)
-> (SymEncIntegrityProtectedData -> Pkt)
-> SymEncIntegrityProtectedData
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymEncIntegrityProtectedData -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary ModificationDetectionCode where
get :: Get ModificationDetectionCode
get = (Pkt -> ModificationDetectionCode)
-> Get Pkt -> Get ModificationDetectionCode
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> ModificationDetectionCode
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: ModificationDetectionCode -> Put
put = Pkt -> Put
putPkt (Pkt -> Put)
-> (ModificationDetectionCode -> Pkt)
-> ModificationDetectionCode
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModificationDetectionCode -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary OtherPacket where
get :: Get OtherPacket
get = (Pkt -> OtherPacket) -> Get Pkt -> Get OtherPacket
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pkt -> OtherPacket
forall a. Packet a => Pkt -> a
fromPkt Get Pkt
getPkt
put :: OtherPacket -> Put
put = Pkt -> Put
putPkt (Pkt -> Put) -> (OtherPacket -> Pkt) -> OtherPacket -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OtherPacket -> Pkt
forall a. Packet a => a -> Pkt
toPkt
instance Binary Pkt where
get :: Get Pkt
get = Get Pkt
getPkt
put :: Pkt -> Put
put = Pkt -> Put
putPkt
instance Binary a => Binary (Block a) where
get :: Get (Block a)
get = [a] -> Block a
forall a. [a] -> Block a
Block ([a] -> Block a) -> Get [a] -> Get (Block a)
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Get a -> Get [a]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Get a
forall t. Binary t => Get t
get
put :: Block a -> Put
put = (a -> Put) -> [a] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ a -> Put
forall t. Binary t => t -> Put
put ([a] -> Put) -> (Block a -> [a]) -> Block a -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Block a -> [a]
forall a. Block a -> [a]
unBlock
instance Binary PKPayload where
get :: Get PKPayload
get = Get PKPayload
getPKPayload
put :: PKPayload -> Put
put = PKPayload -> Put
putPKPayload
instance Binary SignaturePayload where
get :: Get SignaturePayload
get = Get SignaturePayload
getSignaturePayload
put :: SignaturePayload -> Put
put = SignaturePayload -> Put
putSignaturePayload
instance Binary TK where
get :: Get TK
get = Get TK
forall a. HasCallStack => a
undefined
put :: TK -> Put
put = TK -> Put
putTK
getSigSubPacket :: Get SigSubPacket
getSigSubPacket :: Get SigSubPacket
getSigSubPacket = do
Int64
l <- (Word32 -> Int64) -> Get Word32 -> Get Int64
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Get Word32
getSubPacketLength
(Exportability
crit, Word8
pt) <- Get (Exportability, Word8)
getSigSubPacketType
Word8 -> Exportability -> Int64 -> Get SigSubPacket
getSigSubPacket' Word8
pt Exportability
crit Int64
l
where
getSigSubPacket' :: Word8 -> Bool -> ByteOffset -> Get SigSubPacket
getSigSubPacket' :: Word8 -> Exportability -> Int64 -> Get SigSubPacket
getSigSubPacket' Word8
pt Exportability
crit Int64
l
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
2 = do
ThirtyTwoBitTimeStamp
et <- (Word32 -> ThirtyTwoBitTimeStamp)
-> Get Word32 -> Get ThirtyTwoBitTimeStamp
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> ThirtyTwoBitTimeStamp
ThirtyTwoBitTimeStamp Get Word32
getWord32be
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (ThirtyTwoBitTimeStamp -> SigSubPacketPayload
SigCreationTime ThirtyTwoBitTimeStamp
et)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
3 = do
ThirtyTwoBitDuration
et <- (Word32 -> ThirtyTwoBitDuration)
-> Get Word32 -> Get ThirtyTwoBitDuration
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> ThirtyTwoBitDuration
ThirtyTwoBitDuration Get Word32
getWord32be
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (ThirtyTwoBitDuration -> SigSubPacketPayload
SigExpirationTime ThirtyTwoBitDuration
et)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
4 = do
Exportability
e <- Get Exportability
forall t. Binary t => Get t
get
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Exportability -> SigSubPacketPayload
ExportableCertification Exportability
e)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
5 = do
Word8
tl <- Get Word8
getWord8
Word8
ta <- Get Word8
getWord8
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Word8 -> Word8 -> SigSubPacketPayload
TrustSignature Word8
tl Word8
ta)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
6 = do
ByteString
apdre <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
2)
Word8
nul <- Get Word8
getWord8
Exportability -> Get ()
forall (f :: * -> *). Alternative f => Exportability -> f ()
guard (Word8
nul Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
0)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (ByteString -> SigSubPacketPayload
RegularExpression (ByteString -> ByteString
BL.copy ByteString
apdre))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
7 = do
Exportability
r <- Get Exportability
forall t. Binary t => Get t
get
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Exportability -> SigSubPacketPayload
Revocable Exportability
r)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
9 = do
ThirtyTwoBitDuration
et <- (Word32 -> ThirtyTwoBitDuration)
-> Get Word32 -> Get ThirtyTwoBitDuration
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> ThirtyTwoBitDuration
ThirtyTwoBitDuration Get Word32
getWord32be
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (ThirtyTwoBitDuration -> SigSubPacketPayload
KeyExpirationTime ThirtyTwoBitDuration
et)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
11 = do
[SymmetricAlgorithm]
sa <- Int -> Get SymmetricAlgorithm -> Get [SymmetricAlgorithm]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)) Get SymmetricAlgorithm
forall t. Binary t => Get t
get
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit ([SymmetricAlgorithm] -> SigSubPacketPayload
PreferredSymmetricAlgorithms [SymmetricAlgorithm]
sa)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
12 = do
Word8
rclass <- Get Word8
getWord8
Exportability -> Get ()
forall (f :: * -> *). Alternative f => Exportability -> f ()
guard (Word8 -> Int -> Exportability
forall a. Bits a => a -> Int -> Exportability
testBit Word8
rclass Int
7)
PubKeyAlgorithm
algid <- Get PubKeyAlgorithm
forall t. Binary t => Get t
get
ByteString
fp <- Int64 -> Get ByteString
getLazyByteString Int64
20
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$
Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket
Exportability
crit
(Set RevocationClass
-> PubKeyAlgorithm -> TwentyOctetFingerprint -> SigSubPacketPayload
RevocationKey
(ByteString -> Set RevocationClass
forall a. FutureFlag a => ByteString -> Set a
bsToFFSet (ByteString -> Set RevocationClass)
-> (Word8 -> ByteString) -> Word8 -> Set RevocationClass
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> ByteString
BL.singleton (Word8 -> Set RevocationClass) -> Word8 -> Set RevocationClass
forall a b. (a -> b) -> a -> b
$ Word8
rclass Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x7f)
PubKeyAlgorithm
algid
(ByteString -> TwentyOctetFingerprint
TwentyOctetFingerprint ByteString
fp))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
16 = do
ByteString
keyid <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (EightOctetKeyId -> SigSubPacketPayload
Issuer (ByteString -> EightOctetKeyId
EightOctetKeyId ByteString
keyid))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
20 = do
ByteString
flags <- Int64 -> Get ByteString
getLazyByteString Int64
4
Word16
nl <- Get Word16
getWord16be
Word16
vl <- Get Word16
getWord16be
ByteString
nn <- Int64 -> Get ByteString
getLazyByteString (Word16 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
nl)
ByteString
nv <- Int64 -> Get ByteString
getLazyByteString (Word16 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
vl)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$
Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket
Exportability
crit
(Set NotationFlag
-> NotationName -> NotationValue -> SigSubPacketPayload
NotationData (ByteString -> Set NotationFlag
forall a. FutureFlag a => ByteString -> Set a
bsToFFSet ByteString
flags) (ByteString -> NotationName
NotationName ByteString
nn) (ByteString -> NotationValue
NotationValue ByteString
nv))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
21 = do
[HashAlgorithm]
ha <- Int -> Get HashAlgorithm -> Get [HashAlgorithm]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)) Get HashAlgorithm
forall t. Binary t => Get t
get
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit ([HashAlgorithm] -> SigSubPacketPayload
PreferredHashAlgorithms [HashAlgorithm]
ha)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
22 = do
[CompressionAlgorithm]
ca <- Int -> Get CompressionAlgorithm -> Get [CompressionAlgorithm]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)) Get CompressionAlgorithm
forall t. Binary t => Get t
get
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit ([CompressionAlgorithm] -> SigSubPacketPayload
PreferredCompressionAlgorithms [CompressionAlgorithm]
ca)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
23 = do
ByteString
ksps <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Set KSPFlag -> SigSubPacketPayload
KeyServerPreferences (ByteString -> Set KSPFlag
forall a. FutureFlag a => ByteString -> Set a
bsToFFSet ByteString
ksps))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
24 = do
ByteString
pks <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (ByteString -> SigSubPacketPayload
PreferredKeyServer ByteString
pks)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
25 = do
Exportability
primacy <- Get Exportability
forall t. Binary t => Get t
get
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Exportability -> SigSubPacketPayload
PrimaryUserId Exportability
primacy)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
26 = do
URL
url <-
(ByteString -> URL) -> Get ByteString -> Get URL
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
(URI -> URL
URL (URI -> URL) -> (ByteString -> URI) -> ByteString -> URL
forall b c a. (b -> c) -> (a -> b) -> a -> c
. URI -> Maybe URI -> URI
forall a. a -> Maybe a -> a
fromMaybe URI
nullURI (Maybe URI -> URI)
-> (ByteString -> Maybe URI) -> ByteString -> URI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe URI
parseURI (String -> Maybe URI)
-> (ByteString -> String) -> ByteString -> Maybe URI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> String) -> (ByteString -> Text) -> ByteString -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
OnDecodeError -> ByteString -> Text
decodeUtf8With OnDecodeError
lenientDecode)
(Int -> Get ByteString
getByteString (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)))
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (URL -> SigSubPacketPayload
PolicyURL URL
url)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
27 = do
ByteString
kfs <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Set KeyFlag -> SigSubPacketPayload
KeyFlags (ByteString -> Set KeyFlag
forall a. FutureFlag a => ByteString -> Set a
bsToFFSet ByteString
kfs))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
28 = do
ByteString
uid <- Int -> Get ByteString
getByteString (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1))
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$
Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Text -> SigSubPacketPayload
SignersUserId (OnDecodeError -> ByteString -> Text
decodeUtf8With OnDecodeError
lenientDecode ByteString
uid))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
29 = do
Word8
rcode <- Get Word8
getWord8
Text
rreason <-
(ByteString -> Text) -> Get ByteString -> Get Text
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
(OnDecodeError -> ByteString -> Text
decodeUtf8With OnDecodeError
lenientDecode)
(Int -> Get ByteString
getByteString (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
2)))
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (RevocationCode -> Text -> SigSubPacketPayload
ReasonForRevocation (Word8 -> RevocationCode
forall a. FutureVal a => Word8 -> a
toFVal Word8
rcode) Text
rreason)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
30 = do
ByteString
fbs <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Set FeatureFlag -> SigSubPacketPayload
Features (ByteString -> Set FeatureFlag
forall a. FutureFlag a => ByteString -> Set a
bsToFFSet ByteString
fbs))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
31 = do
PubKeyAlgorithm
pka <- Get PubKeyAlgorithm
forall t. Binary t => Get t
get
HashAlgorithm
ha <- Get HashAlgorithm
forall t. Binary t => Get t
get
ByteString
hash <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
3)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (PubKeyAlgorithm
-> HashAlgorithm -> ByteString -> SigSubPacketPayload
SignatureTarget PubKeyAlgorithm
pka HashAlgorithm
ha ByteString
hash)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
32 = do
SignaturePayload
sp <- Get SignaturePayload
forall t. Binary t => Get t
get :: Get SignaturePayload
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (SignaturePayload -> SigSubPacketPayload
EmbeddedSignature SignaturePayload
sp)
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
33 = do
Word8
kv <- Get Word8
getWord8
ByteString
fp <-
Int64 -> Get ByteString
getLazyByteString
(if Word8
kv Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
4
then Int64
20
else Int64
32)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$
Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Word8 -> TwentyOctetFingerprint -> SigSubPacketPayload
IssuerFingerprint Word8
kv (ByteString -> TwentyOctetFingerprint
TwentyOctetFingerprint ByteString
fp))
| Word8
pt Word8 -> Word8 -> Exportability
forall a. Ord a => a -> a -> Exportability
> Word8
99 Exportability -> Exportability -> Exportability
&& Word8
pt Word8 -> Word8 -> Exportability
forall a. Ord a => a -> a -> Exportability
< Word8
111 = do
ByteString
payload <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Word8 -> ByteString -> SigSubPacketPayload
UserDefinedSigSub Word8
pt ByteString
payload)
| Exportability
otherwise = do
ByteString
payload <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
SigSubPacket -> Get SigSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SigSubPacket -> Get SigSubPacket)
-> SigSubPacket -> Get SigSubPacket
forall a b. (a -> b) -> a -> b
$ Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Word8 -> ByteString -> SigSubPacketPayload
OtherSigSub Word8
pt ByteString
payload)
putSigSubPacket :: SigSubPacket -> Put
putSigSubPacket :: SigSubPacket -> Put
putSigSubPacket (SigSubPacket Exportability
crit (SigCreationTime ThirtyTwoBitTimeStamp
et)) = do
Word32 -> Put
putSubPacketLength Word32
5
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
2
Word32 -> Put
putWord32be (Word32 -> Put)
-> (ThirtyTwoBitTimeStamp -> Word32)
-> ThirtyTwoBitTimeStamp
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThirtyTwoBitTimeStamp -> Word32
unThirtyTwoBitTimeStamp (ThirtyTwoBitTimeStamp -> Put) -> ThirtyTwoBitTimeStamp -> Put
forall a b. (a -> b) -> a -> b
$ ThirtyTwoBitTimeStamp
et
putSigSubPacket (SigSubPacket Exportability
crit (SigExpirationTime ThirtyTwoBitDuration
et)) = do
Word32 -> Put
putSubPacketLength Word32
5
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
3
Word32 -> Put
putWord32be (Word32 -> Put)
-> (ThirtyTwoBitDuration -> Word32) -> ThirtyTwoBitDuration -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThirtyTwoBitDuration -> Word32
unThirtyTwoBitDuration (ThirtyTwoBitDuration -> Put) -> ThirtyTwoBitDuration -> Put
forall a b. (a -> b) -> a -> b
$ ThirtyTwoBitDuration
et
putSigSubPacket (SigSubPacket Exportability
crit (ExportableCertification Exportability
e)) = do
Word32 -> Put
putSubPacketLength Word32
2
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
4
Exportability -> Put
forall t. Binary t => t -> Put
put Exportability
e
putSigSubPacket (SigSubPacket Exportability
crit (TrustSignature Word8
tl Word8
ta)) = do
Word32 -> Put
putSubPacketLength Word32
3
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
5
Word8 -> Put
forall t. Binary t => t -> Put
put Word8
tl
Word8 -> Put
forall t. Binary t => t -> Put
put Word8
ta
putSigSubPacket (SigSubPacket Exportability
crit (RegularExpression ByteString
apdre)) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
2 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
apdre)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
6
ByteString -> Put
putLazyByteString ByteString
apdre
Word8 -> Put
putWord8 Word8
0
putSigSubPacket (SigSubPacket Exportability
crit (Revocable Exportability
r)) = do
Word32 -> Put
putSubPacketLength Word32
2
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
7
Exportability -> Put
forall t. Binary t => t -> Put
put Exportability
r
putSigSubPacket (SigSubPacket Exportability
crit (KeyExpirationTime ThirtyTwoBitDuration
et)) = do
Word32 -> Put
putSubPacketLength Word32
5
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
9
Word32 -> Put
putWord32be (Word32 -> Put)
-> (ThirtyTwoBitDuration -> Word32) -> ThirtyTwoBitDuration -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThirtyTwoBitDuration -> Word32
unThirtyTwoBitDuration (ThirtyTwoBitDuration -> Put) -> ThirtyTwoBitDuration -> Put
forall a b. (a -> b) -> a -> b
$ ThirtyTwoBitDuration
et
putSigSubPacket (SigSubPacket Exportability
crit (PreferredSymmetricAlgorithms [SymmetricAlgorithm]
ess)) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int -> Word32) -> Int -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Put) -> Int -> Put
forall a b. (a -> b) -> a -> b
$ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [SymmetricAlgorithm] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [SymmetricAlgorithm]
ess)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
11
(SymmetricAlgorithm -> Put) -> [SymmetricAlgorithm] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ SymmetricAlgorithm -> Put
forall t. Binary t => t -> Put
put [SymmetricAlgorithm]
ess
putSigSubPacket (SigSubPacket Exportability
crit (RevocationKey Set RevocationClass
rclass PubKeyAlgorithm
algid TwentyOctetFingerprint
fp)) = do
Word32 -> Put
putSubPacketLength Word32
23
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
12
ByteString -> Put
putLazyByteString (ByteString -> Put)
-> (Set RevocationClass -> ByteString)
-> Set RevocationClass
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Set RevocationClass -> ByteString
forall a b. (Integral a, FutureFlag b) => a -> Set b -> ByteString
ffSetToFixedLengthBS (Int
1 :: Int) (Set RevocationClass -> Put) -> Set RevocationClass -> Put
forall a b. (a -> b) -> a -> b
$
RevocationClass -> Set RevocationClass -> Set RevocationClass
forall a. Ord a => a -> Set a -> Set a
Set.insert (Word8 -> RevocationClass
RClOther Word8
0) Set RevocationClass
rclass
PubKeyAlgorithm -> Put
forall t. Binary t => t -> Put
put PubKeyAlgorithm
algid
ByteString -> Put
putLazyByteString (TwentyOctetFingerprint -> ByteString
unTOF TwentyOctetFingerprint
fp)
putSigSubPacket (SigSubPacket Exportability
crit (Issuer EightOctetKeyId
keyid)) = do
Word32 -> Put
putSubPacketLength Word32
9
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
16
ByteString -> Put
putLazyByteString (EightOctetKeyId -> ByteString
unEOKI EightOctetKeyId
keyid)
putSigSubPacket (SigSubPacket Exportability
crit (NotationData Set NotationFlag
nfs (NotationName ByteString
nn) (NotationValue ByteString
nv))) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
9 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
nn Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
nv)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
20
ByteString -> Put
putLazyByteString (ByteString -> Put)
-> (Set NotationFlag -> ByteString) -> Set NotationFlag -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Set NotationFlag -> ByteString
forall a b. (Integral a, FutureFlag b) => a -> Set b -> ByteString
ffSetToFixedLengthBS (Int
4 :: Int) (Set NotationFlag -> Put) -> Set NotationFlag -> Put
forall a b. (a -> b) -> a -> b
$ Set NotationFlag
nfs
Word16 -> Put
putWord16be (Word16 -> Put) -> (ByteString -> Word16) -> ByteString -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word16) -> (ByteString -> Int64) -> ByteString -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
BL.length (ByteString -> Put) -> ByteString -> Put
forall a b. (a -> b) -> a -> b
$ ByteString
nn
Word16 -> Put
putWord16be (Word16 -> Put) -> (ByteString -> Word16) -> ByteString -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word16) -> (ByteString -> Int64) -> ByteString -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
BL.length (ByteString -> Put) -> ByteString -> Put
forall a b. (a -> b) -> a -> b
$ ByteString
nv
ByteString -> Put
putLazyByteString ByteString
nn
ByteString -> Put
putLazyByteString ByteString
nv
putSigSubPacket (SigSubPacket Exportability
crit (PreferredHashAlgorithms [HashAlgorithm]
ehs)) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int -> Word32) -> Int -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Put) -> Int -> Put
forall a b. (a -> b) -> a -> b
$ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [HashAlgorithm] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [HashAlgorithm]
ehs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
21
(HashAlgorithm -> Put) -> [HashAlgorithm] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ HashAlgorithm -> Put
forall t. Binary t => t -> Put
put [HashAlgorithm]
ehs
putSigSubPacket (SigSubPacket Exportability
crit (PreferredCompressionAlgorithms [CompressionAlgorithm]
ecs)) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int -> Word32) -> Int -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Put) -> Int -> Put
forall a b. (a -> b) -> a -> b
$ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [CompressionAlgorithm] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CompressionAlgorithm]
ecs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
22
(CompressionAlgorithm -> Put) -> [CompressionAlgorithm] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ CompressionAlgorithm -> Put
forall t. Binary t => t -> Put
put [CompressionAlgorithm]
ecs
putSigSubPacket (SigSubPacket Exportability
crit (KeyServerPreferences Set KSPFlag
ksps)) = do
let kbs :: ByteString
kbs = Set KSPFlag -> ByteString
forall a. FutureFlag a => Set a -> ByteString
ffSetToBS Set KSPFlag
ksps
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
1 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
kbs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
23
ByteString -> Put
putLazyByteString ByteString
kbs
putSigSubPacket (SigSubPacket Exportability
crit (PreferredKeyServer ByteString
ks)) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
1 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
ks)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
24
ByteString -> Put
putLazyByteString ByteString
ks
putSigSubPacket (SigSubPacket Exportability
crit (PrimaryUserId Exportability
primacy)) = do
Word32 -> Put
putSubPacketLength Word32
2
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
25
Exportability -> Put
forall t. Binary t => t -> Put
put Exportability
primacy
putSigSubPacket (SigSubPacket Exportability
crit (PolicyURL (URL URI
uri))) = do
let bs :: ByteString
bs = Text -> ByteString
encodeUtf8 (String -> Text
T.pack ((String -> String) -> URI -> String -> String
uriToString String -> String
forall a. a -> a
id URI
uri String
""))
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int -> Word32) -> Int -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Put) -> Int -> Put
forall a b. (a -> b) -> a -> b
$ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ ByteString -> Int
B.length ByteString
bs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
26
ByteString -> Put
putByteString ByteString
bs
putSigSubPacket (SigSubPacket Exportability
crit (KeyFlags Set KeyFlag
kfs)) = do
let kbs :: ByteString
kbs = Set KeyFlag -> ByteString
forall a. FutureFlag a => Set a -> ByteString
ffSetToBS Set KeyFlag
kfs
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
1 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
kbs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
27
ByteString -> Put
putLazyByteString ByteString
kbs
putSigSubPacket (SigSubPacket Exportability
crit (SignersUserId Text
userid)) = do
let bs :: ByteString
bs = Text -> ByteString
encodeUtf8 Text
userid
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int -> Word32) -> Int -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Put) -> Int -> Put
forall a b. (a -> b) -> a -> b
$ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ ByteString -> Int
B.length ByteString
bs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
28
ByteString -> Put
putByteString ByteString
bs
putSigSubPacket (SigSubPacket Exportability
crit (ReasonForRevocation RevocationCode
rcode Text
rreason)) = do
let reasonbs :: ByteString
reasonbs = Text -> ByteString
encodeUtf8 Text
rreason
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int -> Word32) -> Int -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Put) -> Int -> Put
forall a b. (a -> b) -> a -> b
$ (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ ByteString -> Int
B.length ByteString
reasonbs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
29
Word8 -> Put
putWord8 (Word8 -> Put)
-> (RevocationCode -> Word8) -> RevocationCode -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RevocationCode -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (RevocationCode -> Put) -> RevocationCode -> Put
forall a b. (a -> b) -> a -> b
$ RevocationCode
rcode
ByteString -> Put
putByteString ByteString
reasonbs
putSigSubPacket (SigSubPacket Exportability
crit (Features Set FeatureFlag
fs)) = do
let fbs :: ByteString
fbs = Set FeatureFlag -> ByteString
forall a. FutureFlag a => Set a -> ByteString
ffSetToBS Set FeatureFlag
fs
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
1 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
fbs)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
30
ByteString -> Put
putLazyByteString ByteString
fbs
putSigSubPacket (SigSubPacket Exportability
crit (SignatureTarget PubKeyAlgorithm
pka HashAlgorithm
ha ByteString
hash)) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
3 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
hash)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
31
PubKeyAlgorithm -> Put
forall t. Binary t => t -> Put
put PubKeyAlgorithm
pka
HashAlgorithm -> Put
forall t. Binary t => t -> Put
put HashAlgorithm
ha
ByteString -> Put
putLazyByteString ByteString
hash
putSigSubPacket (SigSubPacket Exportability
crit (EmbeddedSignature SignaturePayload
sp)) = do
let spb :: ByteString
spb = Put -> ByteString
runPut (SignaturePayload -> Put
forall t. Binary t => t -> Put
put SignaturePayload
sp)
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
1 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
spb)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
32
ByteString -> Put
putLazyByteString ByteString
spb
putSigSubPacket (SigSubPacket Exportability
crit (IssuerFingerprint Word8
kv TwentyOctetFingerprint
fp)) = do
let fpb :: ByteString
fpb = TwentyOctetFingerprint -> ByteString
unTOF TwentyOctetFingerprint
fp
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
2 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
fpb)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
33
Word8 -> Put
putWord8 Word8
kv
ByteString -> Put
putLazyByteString ByteString
fpb
putSigSubPacket (SigSubPacket Exportability
crit (UserDefinedSigSub Word8
ptype ByteString
payload)) =
SigSubPacket -> Put
putSigSubPacket (Exportability -> SigSubPacketPayload -> SigSubPacket
SigSubPacket Exportability
crit (Word8 -> ByteString -> SigSubPacketPayload
OtherSigSub Word8
ptype ByteString
payload))
putSigSubPacket (SigSubPacket Exportability
crit (OtherSigSub Word8
ptype ByteString
payload)) = do
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (Int64 -> Word32) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ (Int64
1 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
payload)
Exportability -> Word8 -> Put
putSigSubPacketType Exportability
crit Word8
ptype
ByteString -> Put
putLazyByteString ByteString
payload
getSubPacketLength :: Get Word32
getSubPacketLength :: Get Word32
getSubPacketLength = Word8 -> Get Word32
forall a. Integral a => Word8 -> Get a
getSubPacketLength' (Word8 -> Get Word32) -> Get Word8 -> Get Word32
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Get Word8
getWord8
where
getSubPacketLength' :: Integral a => Word8 -> Get a
getSubPacketLength' :: forall a. Integral a => Word8 -> Get a
getSubPacketLength' Word8
f
| Word8
f Word8 -> Word8 -> Exportability
forall a. Ord a => a -> a -> Exportability
< Word8
192 = a -> Get a
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Get a) -> (Word8 -> a) -> Word8 -> Get a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Get a) -> Word8 -> Get a
forall a b. (a -> b) -> a -> b
$ Word8
f
| Word8
f Word8 -> Word8 -> Exportability
forall a. Ord a => a -> a -> Exportability
< Word8
224 = do
Word8
secondOctet <- Get Word8
getWord8
a -> Get a
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Get a) -> (Int -> a) -> Int -> Get a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Get a) -> Int -> Get a
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Bits a => a -> Int -> a
shiftL (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
f Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
192) :: Int) Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
+
(Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
secondOctet :: Int) Int -> Int -> Int
forall a. Num a => a -> a -> a
+
Int
192
| Word8
f Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
255 = do
Word32
len <- Get Word32
getWord32be
a -> Get a
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Get a) -> (Word32 -> a) -> Word32 -> Get a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Get a) -> Word32 -> Get a
forall a b. (a -> b) -> a -> b
$ Word32
len
| Exportability
otherwise = String -> Get a
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Partial body length invalid."
putSubPacketLength :: Word32 -> Put
putSubPacketLength :: Word32 -> Put
putSubPacketLength Word32
l
| Word32
l Word32 -> Word32 -> Exportability
forall a. Ord a => a -> a -> Exportability
< Word32
192 = Word8 -> Put
putWord8 (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
l)
| Word32
l Word32 -> Word32 -> Exportability
forall a. Ord a => a -> a -> Exportability
< Word32
8384 =
Word8 -> Put
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
l Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
192) Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` Int
8) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
192 :: Int)) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Word8 -> Put
putWord8 (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
l Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
192) Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0xff)
| Word32
l Word32 -> Word32 -> Exportability
forall a. Ord a => a -> a -> Exportability
<= Word32
0xffffffff = Word8 -> Put
putWord8 Word8
255 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Word32 -> Put
putWord32be (Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
l)
| Exportability
otherwise = String -> Put
forall a. HasCallStack => String -> a
error (String
"too big (" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Word32 -> String
forall a. Show a => a -> String
show Word32
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")")
getSigSubPacketType :: Get (Bool, Word8)
getSigSubPacketType :: Get (Exportability, Word8)
getSigSubPacketType = do
Word8
x <- Get Word8
getWord8
(Exportability, Word8) -> Get (Exportability, Word8)
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return
(if Word8
x Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
128 Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
128
then (Exportability
True, Word8
x Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
127)
else (Exportability
False, Word8
x))
putSigSubPacketType :: Bool -> Word8 -> Put
putSigSubPacketType :: Exportability -> Word8 -> Put
putSigSubPacketType Exportability
False Word8
sst = Word8 -> Put
putWord8 Word8
sst
putSigSubPacketType Exportability
True Word8
sst = Word8 -> Put
putWord8 (Word8
sst Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
0x80)
bsToFFSet :: FutureFlag a => ByteString -> Set a
bsToFFSet :: forall a. FutureFlag a => ByteString -> Set a
bsToFFSet ByteString
bs =
[a] -> Set a
forall a. Eq a => [a] -> Set a
Set.fromAscList ([a] -> Set a) -> ((Int, [[a]]) -> [a]) -> (Int, [[a]]) -> Set a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[a]] -> [a]) -> ((Int, [[a]]) -> [[a]]) -> (Int, [[a]]) -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, [[a]]) -> [[a]]
forall a b. (a, b) -> b
snd ((Int, [[a]]) -> Set a) -> (Int, [[a]]) -> Set a
forall a b. (a -> b) -> a -> b
$
(Int -> Word8 -> (Int, [a])) -> Int -> [Word8] -> (Int, [[a]])
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL
(\Int
acc Word8
y -> (Int
acc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8, (Int -> [a]) -> [Int] -> [a]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Int -> Word8 -> Int -> [a]
forall {a} {a}.
(Bits a, Num a, FutureFlag a) =>
Int -> a -> Int -> [a]
shifty Int
acc Word8
y) [Int
0 .. Int
7]))
Int
0
(ByteString -> [Word8]
BL.unpack ByteString
bs)
where
shifty :: Int -> a -> Int -> [a]
shifty Int
acc a
y Int
x = [Int -> a
forall a. FutureFlag a => Int -> a
toFFlag (Int
acc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x) | a
y a -> a -> a
forall a. Bits a => a -> a -> a
.&. a -> Int -> a
forall a. Bits a => a -> Int -> a
shiftR a
128 Int
x a -> a -> Exportability
forall a. Eq a => a -> a -> Exportability
== a -> Int -> a
forall a. Bits a => a -> Int -> a
shiftR a
128 Int
x]
ffSetToFixedLengthBS :: (Integral a, FutureFlag b) => a -> Set b -> ByteString
ffSetToFixedLengthBS :: forall a b. (Integral a, FutureFlag b) => a -> Set b -> ByteString
ffSetToFixedLengthBS a
len Set b
ffs =
Int64 -> ByteString -> ByteString
BL.take
(a -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
len)
(ByteString -> ByteString -> ByteString
BL.append (Set b -> ByteString
forall a. FutureFlag a => Set a -> ByteString
ffSetToBS Set b
ffs) ([Word8] -> ByteString
BL.pack (Int -> Word8 -> [Word8]
forall a. Int -> a -> [a]
replicate Int
5 Word8
0)))
ffSetToBS :: FutureFlag a => Set a -> ByteString
ffSetToBS :: forall a. FutureFlag a => Set a -> ByteString
ffSetToBS = [Word8] -> ByteString
BL.pack ([Word8] -> ByteString)
-> (Set a -> [Word8]) -> Set a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set a -> [Word8]
forall a. FutureFlag a => Set a -> [Word8]
ffSetToBS'
where
ffSetToBS' :: FutureFlag a => Set a -> [Word8]
ffSetToBS' :: forall a. FutureFlag a => Set a -> [Word8]
ffSetToBS' Set a
ks
| Set a -> Exportability
forall a. Set a -> Exportability
Set.null Set a
ks = []
| Exportability
otherwise =
(Int -> Word8) -> [Int] -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map
(((Word8 -> Word8 -> Word8) -> Word8 -> [Word8] -> Word8
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
(.|.) Word8
0 ([Word8] -> Word8) -> (Set a -> [Word8]) -> Set a -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Word8) -> [a] -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map (Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
shiftR Word8
128 (Int -> Word8) -> (a -> Int) -> a -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int) -> Int -> Int -> Int
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
8 (Int -> Int) -> (a -> Int) -> a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
forall a. FutureFlag a => a -> Int
fromFFlag) ([a] -> [Word8]) -> (Set a -> [a]) -> Set a -> [Word8]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Set a -> [a]
forall a. Set a -> [a]
Set.toAscList) (Set a -> Word8) -> (Int -> Set a) -> Int -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(\Int
x -> (a -> Exportability) -> Set a -> Set a
forall a. (a -> Exportability) -> Set a -> Set a
Set.filter (\a
y -> a -> Int
forall a. FutureFlag a => a -> Int
fromFFlag a
y Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8 Int -> Int -> Exportability
forall a. Eq a => a -> a -> Exportability
== Int
x) Set a
ks))
[Int
0 .. a -> Int
forall a. FutureFlag a => a -> Int
fromFFlag (Set a -> a
forall a. Set a -> a
Set.findMax Set a
ks) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8]
fromS2K :: S2K -> ByteString
fromS2K :: S2K -> ByteString
fromS2K (Simple HashAlgorithm
hashalgo) = [Word8] -> ByteString
BL.pack [Word8
0, Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ HashAlgorithm
hashalgo]
fromS2K (Salted HashAlgorithm
hashalgo Salt
salt)
| ByteString -> Int
B.length (Salt -> ByteString
unSalt Salt
salt) Int -> Int -> Exportability
forall a. Eq a => a -> a -> Exportability
== Int
8 =
[Word8] -> ByteString
BL.pack [Word8
1, Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ HashAlgorithm
hashalgo] ByteString -> ByteString -> ByteString
`BL.append`
(ByteString -> ByteString
BL.fromStrict (ByteString -> ByteString)
-> (Salt -> ByteString) -> Salt -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Salt -> ByteString
unSalt) Salt
salt
| Exportability
otherwise = String -> ByteString
forall a. HasCallStack => String -> a
error String
"Confusing salt size"
fromS2K (IteratedSalted HashAlgorithm
hashalgo Salt
salt IterationCount
count)
| ByteString -> Int
B.length (Salt -> ByteString
unSalt Salt
salt) Int -> Int -> Exportability
forall a. Eq a => a -> a -> Exportability
== Int
8 =
[Word8] -> ByteString
BL.pack [Word8
3, Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ HashAlgorithm
hashalgo] ByteString -> ByteString -> ByteString
`BL.append`
(ByteString -> ByteString
BL.fromStrict (ByteString -> ByteString)
-> (Salt -> ByteString) -> Salt -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Salt -> ByteString
unSalt) Salt
salt ByteString -> Word8 -> ByteString
`BL.snoc`
IterationCount -> Word8
encodeIterationCount IterationCount
count
| Exportability
otherwise = String -> ByteString
forall a. HasCallStack => String -> a
error String
"Confusing salt size"
fromS2K (OtherS2K Word8
_ ByteString
bs) = ByteString
bs
getPacketLength :: Get Integer
getPacketLength :: Get Integer
getPacketLength = do
Word8
firstOctet <- Get Word8
getWord8
Word8 -> Get Integer
forall a. Integral a => Word8 -> Get a
getPacketLength' Word8
firstOctet
where
getPacketLength' :: Integral a => Word8 -> Get a
getPacketLength' :: forall a. Integral a => Word8 -> Get a
getPacketLength' Word8
f
| Word8
f Word8 -> Word8 -> Exportability
forall a. Ord a => a -> a -> Exportability
< Word8
192 = a -> Get a
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Get a) -> (Word8 -> a) -> Word8 -> Get a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Get a) -> Word8 -> Get a
forall a b. (a -> b) -> a -> b
$ Word8
f
| Word8
f Word8 -> Word8 -> Exportability
forall a. Ord a => a -> a -> Exportability
< Word8
224 = do
Word8
secondOctet <- Get Word8
getWord8
a -> Get a
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Get a) -> (Int -> a) -> Int -> Get a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Get a) -> Int -> Get a
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Bits a => a -> Int -> a
shiftL (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
f Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
192) :: Int) Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
+
(Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
secondOctet :: Int) Int -> Int -> Int
forall a. Num a => a -> a -> a
+
Int
192
| Word8
f Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
255 = do
Word32
len <- Get Word32
getWord32be
a -> Get a
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Get a) -> (Word32 -> a) -> Word32 -> Get a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Get a) -> Word32 -> Get a
forall a b. (a -> b) -> a -> b
$ Word32
len
| Exportability
otherwise = String -> Get a
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Partial body length support missing."
putPacketLength :: Integer -> Put
putPacketLength :: Integer -> Put
putPacketLength Integer
l
| Integer
l Integer -> Integer -> Exportability
forall a. Ord a => a -> a -> Exportability
< Integer
192 = Word8 -> Put
putWord8 (Integer -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
l)
| Integer
l Integer -> Integer -> Exportability
forall a. Ord a => a -> a -> Exportability
< Integer
8384 =
Word8 -> Put
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer
l Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
192) Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` Int
8) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
192 :: Int)) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Word8 -> Put
putWord8 (Integer -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer
l Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
192) Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0xff)
| Integer
l Integer -> Integer -> Exportability
forall a. Ord a => a -> a -> Exportability
< Integer
0x100000000 = Word8 -> Put
putWord8 Word8
255 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Word32 -> Put
putWord32be (Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
l)
| Exportability
otherwise = String -> Put
forall a. HasCallStack => String -> a
error String
"partial body length support needed"
getS2K :: Get S2K
getS2K :: Get S2K
getS2K = Word8 -> Get S2K
getS2K' (Word8 -> Get S2K) -> Get Word8 -> Get S2K
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Get Word8
getWord8
where
getS2K' :: Word8 -> Get S2K
getS2K' :: Word8 -> Get S2K
getS2K' Word8
t
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
0 = do
Word8
ha <- Get Word8
getWord8
S2K -> Get S2K
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (S2K -> Get S2K) -> S2K -> Get S2K
forall a b. (a -> b) -> a -> b
$ HashAlgorithm -> S2K
Simple (Word8 -> HashAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
ha)
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
1 = do
Word8
ha <- Get Word8
getWord8
ByteString
salt <- Int -> Get ByteString
getByteString Int
8
S2K -> Get S2K
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (S2K -> Get S2K) -> S2K -> Get S2K
forall a b. (a -> b) -> a -> b
$ HashAlgorithm -> Salt -> S2K
Salted (Word8 -> HashAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
ha) (ByteString -> Salt
Salt ByteString
salt)
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
3 = do
Word8
ha <- Get Word8
getWord8
ByteString
salt <- Int -> Get ByteString
getByteString Int
8
Word8
count <- Get Word8
getWord8
S2K -> Get S2K
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (S2K -> Get S2K) -> S2K -> Get S2K
forall a b. (a -> b) -> a -> b
$
HashAlgorithm -> Salt -> IterationCount -> S2K
IteratedSalted (Word8 -> HashAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
ha) (ByteString -> Salt
Salt ByteString
salt) (Word8 -> IterationCount
decodeIterationCount Word8
count)
| Exportability
otherwise = do
ByteString
bs <- Get ByteString
getRemainingLazyByteString
S2K -> Get S2K
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (S2K -> Get S2K) -> S2K -> Get S2K
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString -> S2K
OtherS2K Word8
t ByteString
bs
putS2K :: S2K -> Put
putS2K :: S2K -> Put
putS2K (Simple HashAlgorithm
hashalgo) = String -> Put
forall a. HasCallStack => String -> a
error (String
"confused by simple" String -> String -> String
forall a. [a] -> [a] -> [a]
++ HashAlgorithm -> String
forall a. Show a => a -> String
show HashAlgorithm
hashalgo)
putS2K (Salted HashAlgorithm
hashalgo Salt
salt) =
String -> Put
forall a. HasCallStack => String -> a
error (String
"confused by salted" String -> String -> String
forall a. [a] -> [a] -> [a]
++ HashAlgorithm -> String
forall a. Show a => a -> String
show HashAlgorithm
hashalgo String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" by " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Salt -> String
forall a. Show a => a -> String
show Salt
salt)
putS2K (IteratedSalted HashAlgorithm
ha Salt
salt IterationCount
count) = do
Word8 -> Put
putWord8 Word8
3
HashAlgorithm -> Put
forall t. Binary t => t -> Put
put HashAlgorithm
ha
ByteString -> Put
putByteString (Salt -> ByteString
unSalt Salt
salt)
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ IterationCount -> Word8
encodeIterationCount IterationCount
count
putS2K (OtherS2K Word8
t ByteString
bs) = Word8 -> Put
putWord8 Word8
t Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
putLazyByteString ByteString
bs
getPacketTypeAndPayload :: Get (Word8, ByteString)
getPacketTypeAndPayload :: Get (Word8, ByteString)
getPacketTypeAndPayload = do
Word8
tag <- Get Word8
getWord8
Exportability -> Get ()
forall (f :: * -> *). Alternative f => Exportability -> f ()
guard (Word8 -> Int -> Exportability
forall a. Bits a => a -> Int -> Exportability
testBit Word8
tag Int
7)
case Word8
tag Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x40 of
Word8
0x00 -> do
let t :: Word8
t = Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
shiftR (Word8
tag Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x3c) Int
2
case Word8
tag Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x03 of
Word8
0 -> do
Word8
len <- Get Word8
getWord8
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString (Word8 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
len)
(Word8, ByteString) -> Get (Word8, ByteString)
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8
t, ByteString
bs)
Word8
1 -> do
Word16
len <- Get Word16
getWord16be
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString (Word16 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
len)
(Word8, ByteString) -> Get (Word8, ByteString)
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8
t, ByteString
bs)
Word8
2 -> do
Word32
len <- Get Word32
getWord32be
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString (Word32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
len)
(Word8, ByteString) -> Get (Word8, ByteString)
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8
t, ByteString
bs)
Word8
3 -> do
ByteString
bs <- Get ByteString
getRemainingLazyByteString
(Word8, ByteString) -> Get (Word8, ByteString)
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8
t, ByteString
bs)
Word8
_ -> String -> Get (Word8, ByteString)
forall a. HasCallStack => String -> a
error String
"This should never happen (getPacketTypeAndPayload/0x00)."
Word8
0x40 -> do
Int64
len <- (Integer -> Int64) -> Get Integer -> Get Int64
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Get Integer
getPacketLength
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString Int64
len
(Word8, ByteString) -> Get (Word8, ByteString)
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8
tag Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x3f, ByteString
bs)
Word8
_ -> String -> Get (Word8, ByteString)
forall a. HasCallStack => String -> a
error String
"This should never happen (getPacketTypeAndPayload/???)."
getPkt :: Get Pkt
getPkt :: Get Pkt
getPkt = do
(Word8
t, ByteString
pl) <- Get (Word8, ByteString)
getPacketTypeAndPayload
case Get Pkt
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Word8 -> Int64 -> Get Pkt
getPkt' Word8
t (ByteString -> Int64
BL.length ByteString
pl)) ByteString
pl of
Left (ByteString
_, Int64
_, String
e) -> Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$! String -> Word8 -> ByteString -> Pkt
BrokenPacketPkt String
e Word8
t ByteString
pl
Right (ByteString
_, Int64
_, Pkt
p) -> Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Pkt
p
where
getPkt' :: Word8 -> ByteOffset -> Get Pkt
getPkt' :: Word8 -> Int64 -> Get Pkt
getPkt' Word8
t Int64
len
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
1 = do
Word8
pv <- Get Word8
getWord8
ByteString
eokeyid <- Int64 -> Get ByteString
getLazyByteString Int64
8
Word8
pka <- Get Word8
getWord8
ByteString
mpib <- Get ByteString
getRemainingLazyByteString
case Get [MPI]
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, [MPI])
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Get MPI -> Get [MPI]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Get MPI
getMPI) ByteString
mpib of
Left (ByteString
_, Int64
_, String
e) -> String -> Get Pkt
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"PKESK MPIs " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
e)
Right (ByteString
_, Int64
_, [MPI]
sk) ->
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$
Word8 -> EightOctetKeyId -> PubKeyAlgorithm -> NonEmpty MPI -> Pkt
PKESKPkt Word8
pv (ByteString -> EightOctetKeyId
EightOctetKeyId ByteString
eokeyid) (Word8 -> PubKeyAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
pka) ([MPI] -> NonEmpty MPI
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [MPI]
sk)
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
2 = do
ByteString
bs <- Get ByteString
getRemainingLazyByteString
case Get SignaturePayload
-> ByteString
-> Either
(ByteString, Int64, String) (ByteString, Int64, SignaturePayload)
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail Get SignaturePayload
forall t. Binary t => Get t
get ByteString
bs of
Left (ByteString
_, Int64
_, String
e) -> String -> Get Pkt
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"signature packet " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
e)
Right (ByteString
_, Int64
_, SignaturePayload
sp) -> Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ SignaturePayload -> Pkt
SignaturePkt SignaturePayload
sp
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
3 = do
Word8
pv <- Get Word8
getWord8
Word8
symalgo <- Get Word8
getWord8
S2K
s2k <- Get S2K
getS2K
ByteString
esk <- Get ByteString
getRemainingLazyByteString
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$
Word8 -> SymmetricAlgorithm -> S2K -> Maybe ByteString -> Pkt
SKESKPkt
Word8
pv
(Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
symalgo)
S2K
s2k
(if ByteString -> Exportability
BL.null ByteString
esk
then Maybe ByteString
forall a. Maybe a
Nothing
else ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
esk)
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
4 = do
Word8
pv <- Get Word8
getWord8
Word8
sigtype <- Get Word8
getWord8
Word8
ha <- Get Word8
getWord8
Word8
pka <- Get Word8
getWord8
ByteString
skeyid <- Int64 -> Get ByteString
getLazyByteString Int64
8
Word8
nested <- Get Word8
getWord8
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$
Word8
-> SigType
-> HashAlgorithm
-> PubKeyAlgorithm
-> EightOctetKeyId
-> Exportability
-> Pkt
OnePassSignaturePkt
Word8
pv
(Word8 -> SigType
forall a. FutureVal a => Word8 -> a
toFVal Word8
sigtype)
(Word8 -> HashAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
ha)
(Word8 -> PubKeyAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
pka)
(ByteString -> EightOctetKeyId
EightOctetKeyId ByteString
skeyid)
(Word8
nested Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
0)
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
5 = do
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString Int64
len
let ps :: Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
ps =
(Get Pkt
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt))
-> ByteString
-> Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Get Pkt
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail ByteString
bs (Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt))
-> Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a b. (a -> b) -> a -> b
$ do
PKPayload
pkp <- Get PKPayload
getPKPayload
SKAddendum
ska <- PKPayload -> Get SKAddendum
getSKAddendum PKPayload
pkp
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ PKPayload -> SKAddendum -> Pkt
SecretKeyPkt PKPayload
pkp SKAddendum
ska
case Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
ps of
Left (ByteString
_, Int64
_, String
err) -> String -> Get Pkt
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"secret key " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err)
Right (ByteString
_, Int64
_, Pkt
key) -> Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Pkt
key
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
6 = do
PKPayload
pkp <- Get PKPayload
getPKPayload
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ PKPayload -> Pkt
PublicKeyPkt PKPayload
pkp
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
7 = do
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString Int64
len
let ps :: Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
ps =
(Get Pkt
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt))
-> ByteString
-> Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Get Pkt
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail ByteString
bs (Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt))
-> Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a b. (a -> b) -> a -> b
$ do
PKPayload
pkp <- Get PKPayload
getPKPayload
SKAddendum
ska <- PKPayload -> Get SKAddendum
getSKAddendum PKPayload
pkp
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ PKPayload -> SKAddendum -> Pkt
SecretSubkeyPkt PKPayload
pkp SKAddendum
ska
case Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
ps of
Left (ByteString
_, Int64
_, String
err) -> String -> Get Pkt
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"secret subkey " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err)
Right (ByteString
_, Int64
_, Pkt
key) -> Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Pkt
key
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
8 = do
Word8
ca <- Get Word8
getWord8
ByteString
cdata <- Int64 -> Get ByteString
getLazyByteString (Int64
len Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ CompressionAlgorithm -> ByteString -> Pkt
CompressedDataPkt (Word8 -> CompressionAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
ca) ByteString
cdata
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
9 = do
ByteString
sdata <- Int64 -> Get ByteString
getLazyByteString Int64
len
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ ByteString -> Pkt
SymEncDataPkt ByteString
sdata
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
10 = do
ByteString
marker <- Int64 -> Get ByteString
getLazyByteString Int64
len
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ ByteString -> Pkt
MarkerPkt ByteString
marker
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
11 = do
Word8
dt <- Get Word8
getWord8
Word8
flen <- Get Word8
getWord8
ByteString
fn <- Int64 -> Get ByteString
getLazyByteString (Word8 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
flen)
ThirtyTwoBitTimeStamp
ts <- (Word32 -> ThirtyTwoBitTimeStamp)
-> Get Word32 -> Get ThirtyTwoBitTimeStamp
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> ThirtyTwoBitTimeStamp
ThirtyTwoBitTimeStamp Get Word32
getWord32be
ByteString
ldata <- Int64 -> Get ByteString
getLazyByteString (Int64
len Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- (Int64
6 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Word8 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
flen))
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ DataType
-> ByteString -> ThirtyTwoBitTimeStamp -> ByteString -> Pkt
LiteralDataPkt (Word8 -> DataType
forall a. FutureVal a => Word8 -> a
toFVal Word8
dt) ByteString
fn ThirtyTwoBitTimeStamp
ts ByteString
ldata
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
12 = do
ByteString
tdata <- Int64 -> Get ByteString
getLazyByteString Int64
len
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ ByteString -> Pkt
TrustPkt ByteString
tdata
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
13 = do
ByteString
udata <- Int -> Get ByteString
getByteString (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
len)
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> (ByteString -> Pkt) -> ByteString -> Get Pkt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Pkt
UserIdPkt (Text -> Pkt) -> (ByteString -> Text) -> ByteString -> Pkt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
decodeUtf8With OnDecodeError
lenientDecode (ByteString -> Get Pkt) -> ByteString -> Get Pkt
forall a b. (a -> b) -> a -> b
$ ByteString
udata
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
14 = do
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString Int64
len
let ps :: Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
ps =
(Get Pkt
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt))
-> ByteString
-> Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Get Pkt
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail ByteString
bs (Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt))
-> Get Pkt
-> Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
forall a b. (a -> b) -> a -> b
$ do
PKPayload
pkp <- Get PKPayload
getPKPayload
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ PKPayload -> Pkt
PublicSubkeyPkt PKPayload
pkp
case Either (ByteString, Int64, String) (ByteString, Int64, Pkt)
ps of
Left (ByteString
_, Int64
_, String
err) -> String -> Get Pkt
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"public subkey " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err)
Right (ByteString
_, Int64
_, Pkt
key) -> Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Pkt
key
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
17 = do
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString Int64
len
case Get [UserAttrSubPacket]
-> ByteString
-> Either
(ByteString, Int64, String)
(ByteString, Int64, [UserAttrSubPacket])
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Get UserAttrSubPacket -> Get [UserAttrSubPacket]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Get UserAttrSubPacket
getUserAttrSubPacket) ByteString
bs of
Left (ByteString
_, Int64
_, String
err) -> String -> Get Pkt
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"user attribute " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err)
Right (ByteString
_, Int64
_, [UserAttrSubPacket]
uas) -> Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ [UserAttrSubPacket] -> Pkt
UserAttributePkt [UserAttrSubPacket]
uas
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
18 = do
Word8
pv <- Get Word8
getWord8
ByteString
b <- Int64 -> Get ByteString
getLazyByteString (Int64
len Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString -> Pkt
SymEncIntegrityProtectedDataPkt Word8
pv ByteString
b
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
19 = do
ByteString
hash <- Int64 -> Get ByteString
getLazyByteString Int64
20
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ ByteString -> Pkt
ModificationDetectionCodePkt ByteString
hash
| Exportability
otherwise = do
ByteString
payload <- Int64 -> Get ByteString
getLazyByteString Int64
len
Pkt -> Get Pkt
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pkt -> Get Pkt) -> Pkt -> Get Pkt
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString -> Pkt
OtherPacketPkt Word8
t ByteString
payload
getUserAttrSubPacket :: Get UserAttrSubPacket
getUserAttrSubPacket :: Get UserAttrSubPacket
getUserAttrSubPacket = do
Int64
l <- (Word32 -> Int64) -> Get Word32 -> Get Int64
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Get Word32
getSubPacketLength
Word8
t <- Get Word8
getWord8
Word8 -> Int64 -> Get UserAttrSubPacket
getUserAttrSubPacket' Word8
t Int64
l
where
getUserAttrSubPacket' :: Word8 -> ByteOffset -> Get UserAttrSubPacket
getUserAttrSubPacket' :: Word8 -> Int64 -> Get UserAttrSubPacket
getUserAttrSubPacket' Word8
t Int64
l
| Word8
t Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
1 = do
Word16
_ <- Get Word16
getWord16le
Word8
hver <- Get Word8
getWord8
Word8
iformat <- Get Word8
getWord8
ByteString
nuls <- Int64 -> Get ByteString
getLazyByteString Int64
12
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
17)
if Word8
hver Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
/= Word8
1 Exportability -> Exportability -> Exportability
|| ByteString
nuls ByteString -> ByteString -> Exportability
forall a. Eq a => a -> a -> Exportability
/= [Word8] -> ByteString
BL.pack (Int -> Word8 -> [Word8]
forall a. Int -> a -> [a]
replicate Int
12 Word8
0)
then String -> Get UserAttrSubPacket
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Corrupt UAt subpacket"
else UserAttrSubPacket -> Get UserAttrSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (UserAttrSubPacket -> Get UserAttrSubPacket)
-> UserAttrSubPacket -> Get UserAttrSubPacket
forall a b. (a -> b) -> a -> b
$ ImageHeader -> ByteString -> UserAttrSubPacket
ImageAttribute (ImageFormat -> ImageHeader
ImageHV1 (Word8 -> ImageFormat
forall a. FutureVal a => Word8 -> a
toFVal Word8
iformat)) ByteString
bs
| Exportability
otherwise = do
ByteString
bs <- Int64 -> Get ByteString
getLazyByteString (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
1)
UserAttrSubPacket -> Get UserAttrSubPacket
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (UserAttrSubPacket -> Get UserAttrSubPacket)
-> UserAttrSubPacket -> Get UserAttrSubPacket
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString -> UserAttrSubPacket
OtherUASub Word8
t ByteString
bs
putUserAttrSubPacket :: UserAttrSubPacket -> Put
putUserAttrSubPacket :: UserAttrSubPacket -> Put
putUserAttrSubPacket UserAttrSubPacket
ua = do
let sp :: ByteString
sp = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ UserAttrSubPacket -> Put
putUserAttrSubPacket' UserAttrSubPacket
ua
Word32 -> Put
putSubPacketLength (Word32 -> Put) -> (ByteString -> Word32) -> ByteString -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word32) -> (ByteString -> Int64) -> ByteString -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
BL.length (ByteString -> Put) -> ByteString -> Put
forall a b. (a -> b) -> a -> b
$ ByteString
sp
ByteString -> Put
putLazyByteString ByteString
sp
where
putUserAttrSubPacket' :: UserAttrSubPacket -> Put
putUserAttrSubPacket' (ImageAttribute (ImageHV1 ImageFormat
iformat) ByteString
idata) = do
Word8 -> Put
putWord8 Word8
1
Word16 -> Put
putWord16le Word16
16
Word8 -> Put
putWord8 Word8
1
Word8 -> Put
putWord8 (ImageFormat -> Word8
forall a. FutureVal a => a -> Word8
fromFVal ImageFormat
iformat)
Int -> Put -> Put
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
12 (Put -> Put) -> Put -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Put
putWord8 Word8
0
ByteString -> Put
putLazyByteString ByteString
idata
putUserAttrSubPacket' (OtherUASub Word8
t ByteString
bs) = do
Word8 -> Put
putWord8 Word8
t
ByteString -> Put
putLazyByteString ByteString
bs
putPkt :: Pkt -> Put
putPkt :: Pkt -> Put
putPkt (PKESKPkt Word8
pv EightOctetKeyId
eokeyid PubKeyAlgorithm
pka NonEmpty MPI
mpis) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
1)
let bsk :: ByteString
bsk = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ (MPI -> Put) -> NonEmpty MPI -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
F.mapM_ MPI -> Put
forall t. Binary t => t -> Put
put NonEmpty MPI
mpis
Integer -> Put
putPacketLength (Integer -> Put) -> (Int64 -> Integer) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ Int64
10 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
bsk
Word8 -> Put
putWord8 Word8
pv
ByteString -> Put
putLazyByteString (EightOctetKeyId -> ByteString
unEOKI EightOctetKeyId
eokeyid)
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (PubKeyAlgorithm -> Word8) -> PubKeyAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PubKeyAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (PubKeyAlgorithm -> Word8) -> PubKeyAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ PubKeyAlgorithm
pka
ByteString -> Put
putLazyByteString ByteString
bsk
putPkt (SignaturePkt SignaturePayload
sp) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
2)
let bs :: ByteString
bs = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ SignaturePayload -> Put
forall t. Binary t => t -> Put
put SignaturePayload
sp
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (SKESKPkt Word8
pv SymmetricAlgorithm
symalgo S2K
s2k Maybe ByteString
mesk) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
3)
let bs2k :: ByteString
bs2k = S2K -> ByteString
fromS2K S2K
s2k
let bsk :: ByteString
bsk = ByteString -> Maybe ByteString -> ByteString
forall a. a -> Maybe a -> a
fromMaybe ByteString
BL.empty Maybe ByteString
mesk
Integer -> Put
putPacketLength (Integer -> Put) -> (Int64 -> Integer) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ Int64
2 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
bs2k Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ ByteString -> Int64
BL.length ByteString
bsk
Word8 -> Put
putWord8 Word8
pv
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (SymmetricAlgorithm -> Word8) -> SymmetricAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (SymmetricAlgorithm -> Word8) -> SymmetricAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ SymmetricAlgorithm
symalgo
ByteString -> Put
putLazyByteString ByteString
bs2k
ByteString -> Put
putLazyByteString ByteString
bsk
putPkt (OnePassSignaturePkt Word8
pv SigType
sigtype HashAlgorithm
ha PubKeyAlgorithm
pka EightOctetKeyId
skeyid Exportability
nested) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
4)
let bs :: ByteString
bs =
Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ do
Word8 -> Put
putWord8 Word8
pv
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8) -> (SigType -> Word8) -> SigType -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SigType -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (SigType -> Word8) -> SigType -> Word8
forall a b. (a -> b) -> a -> b
$ SigType
sigtype
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (HashAlgorithm -> Word8) -> HashAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ HashAlgorithm
ha
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (PubKeyAlgorithm -> Word8) -> PubKeyAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PubKeyAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (PubKeyAlgorithm -> Word8) -> PubKeyAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ PubKeyAlgorithm
pka
ByteString -> Put
putLazyByteString (EightOctetKeyId -> ByteString
unEOKI EightOctetKeyId
skeyid)
Word8 -> Put
putWord8 (Word8 -> Put) -> (Exportability -> Word8) -> Exportability -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (Exportability -> Int) -> Exportability -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Exportability -> Int
forall a. Enum a => a -> Int
fromEnum (Exportability -> Put) -> Exportability -> Put
forall a b. (a -> b) -> a -> b
$ Exportability -> Exportability
not Exportability
nested
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (SecretKeyPkt PKPayload
pkp SKAddendum
ska) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
5)
let bs :: ByteString
bs = Put -> ByteString
runPut (PKPayload -> Put
putPKPayload PKPayload
pkp Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SKAddendum -> Put
putSKAddendum SKAddendum
ska)
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (PublicKeyPkt PKPayload
pkp) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
6)
let bs :: ByteString
bs = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ PKPayload -> Put
putPKPayload PKPayload
pkp
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (SecretSubkeyPkt PKPayload
pkp SKAddendum
ska) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
7)
let bs :: ByteString
bs = Put -> ByteString
runPut (PKPayload -> Put
putPKPayload PKPayload
pkp Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SKAddendum -> Put
putSKAddendum SKAddendum
ska)
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (CompressedDataPkt CompressionAlgorithm
ca ByteString
cdata) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
8)
let bs :: ByteString
bs =
Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ do
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8)
-> (CompressionAlgorithm -> Word8) -> CompressionAlgorithm -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompressionAlgorithm -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (CompressionAlgorithm -> Word8) -> CompressionAlgorithm -> Word8
forall a b. (a -> b) -> a -> b
$ CompressionAlgorithm
ca
ByteString -> Put
putLazyByteString ByteString
cdata
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (SymEncDataPkt ByteString
b) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
9)
ByteString -> Put
putLengthThenPayload ByteString
b
putPkt (MarkerPkt ByteString
b) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
10)
ByteString -> Put
putLengthThenPayload ByteString
b
putPkt (LiteralDataPkt DataType
dt ByteString
fn ThirtyTwoBitTimeStamp
ts ByteString
b) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
11)
let bs :: ByteString
bs =
Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ do
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> Word8) -> (DataType -> Word8) -> DataType -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> Word8
forall a. FutureVal a => a -> Word8
fromFVal (DataType -> Word8) -> DataType -> Word8
forall a b. (a -> b) -> a -> b
$ DataType
dt
Word8 -> Put
putWord8 (Word8 -> Put) -> Word8 -> Put
forall a b. (a -> b) -> a -> b
$ Int64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word8) -> (ByteString -> Int64) -> ByteString -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
BL.length (ByteString -> Word8) -> ByteString -> Word8
forall a b. (a -> b) -> a -> b
$ ByteString
fn
ByteString -> Put
putLazyByteString ByteString
fn
Word32 -> Put
putWord32be (Word32 -> Put)
-> (ThirtyTwoBitTimeStamp -> Word32)
-> ThirtyTwoBitTimeStamp
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThirtyTwoBitTimeStamp -> Word32
unThirtyTwoBitTimeStamp (ThirtyTwoBitTimeStamp -> Put) -> ThirtyTwoBitTimeStamp -> Put
forall a b. (a -> b) -> a -> b
$ ThirtyTwoBitTimeStamp
ts
ByteString -> Put
putLazyByteString ByteString
b
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (TrustPkt ByteString
b) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
12)
ByteString -> Put
putLengthThenPayload ByteString
b
putPkt (UserIdPkt Text
u) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
13)
let bs :: ByteString
bs = Text -> ByteString
encodeUtf8 Text
u
Integer -> Put
putPacketLength (Integer -> Put) -> (Int -> Integer) -> Int -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Put) -> Int -> Put
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
bs
ByteString -> Put
putByteString ByteString
bs
putPkt (PublicSubkeyPkt PKPayload
pkp) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
14)
let bs :: ByteString
bs = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ PKPayload -> Put
putPKPayload PKPayload
pkp
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (UserAttributePkt [UserAttrSubPacket]
us) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
17)
let bs :: ByteString
bs = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ (UserAttrSubPacket -> Put) -> [UserAttrSubPacket] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ UserAttrSubPacket -> Put
forall t. Binary t => t -> Put
put [UserAttrSubPacket]
us
ByteString -> Put
putLengthThenPayload ByteString
bs
putPkt (SymEncIntegrityProtectedDataPkt Word8
pv ByteString
b) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
18)
Integer -> Put
putPacketLength (Integer -> Put) -> (Int64 -> Integer) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ ByteString -> Int64
BL.length ByteString
b Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
1
Word8 -> Put
putWord8 Word8
pv
ByteString -> Put
putLazyByteString ByteString
b
putPkt (ModificationDetectionCodePkt ByteString
hash) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
19)
ByteString -> Put
putLengthThenPayload ByteString
hash
putPkt (OtherPacketPkt Word8
t ByteString
payload) = do
Word8 -> Put
putWord8 (Word8
0xc0 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. Word8
t)
ByteString -> Put
putLengthThenPayload ByteString
payload
putPkt (BrokenPacketPkt String
_ Word8
t ByteString
payload) = Pkt -> Put
putPkt (Word8 -> ByteString -> Pkt
OtherPacketPkt Word8
t ByteString
payload)
putLengthThenPayload :: ByteString -> Put
putLengthThenPayload :: ByteString -> Put
putLengthThenPayload ByteString
bs = do
Integer -> Put
putPacketLength (Integer -> Put) -> (Int64 -> Integer) -> Int64 -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Put) -> Int64 -> Put
forall a b. (a -> b) -> a -> b
$ ByteString -> Int64
BL.length ByteString
bs
ByteString -> Put
putLazyByteString ByteString
bs
getMPI :: Get MPI
getMPI :: Get MPI
getMPI = do
Word16
mpilen <- Get Word16
getWord16be
ByteString
bs <- Int -> Get ByteString
getByteString (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16
mpilen Word16 -> Word16 -> Word16
forall a. Num a => a -> a -> a
+ Word16
7) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8)
MPI -> Get MPI
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (MPI -> Get MPI) -> MPI -> Get MPI
forall a b. (a -> b) -> a -> b
$ Integer -> MPI
MPI (ByteString -> Integer
forall ba. ByteArrayAccess ba => ba -> Integer
os2ip ByteString
bs)
getPubkey :: PubKeyAlgorithm -> Get PKey
getPubkey :: PubKeyAlgorithm -> Get PKey
getPubkey PubKeyAlgorithm
RSA = do
MPI Integer
n <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
e <- Get MPI
forall t. Binary t => Get t
get
PKey -> Get PKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKey -> Get PKey) -> PKey -> Get PKey
forall a b. (a -> b) -> a -> b
$
RSA_PublicKey -> PKey
RSAPubKey
(PublicKey -> RSA_PublicKey
RSA_PublicKey (Int -> Integer -> Integer -> PublicKey
R.PublicKey (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int) -> (Integer -> Int) -> Integer -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
B.length (ByteString -> Int) -> (Integer -> ByteString) -> Integer -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> ByteString
forall ba. ByteArray ba => Integer -> ba
i2osp (Integer -> Int) -> Integer -> Int
forall a b. (a -> b) -> a -> b
$ Integer
n) Integer
n Integer
e))
getPubkey PubKeyAlgorithm
DeprecatedRSAEncryptOnly = PubKeyAlgorithm -> Get PKey
getPubkey PubKeyAlgorithm
RSA
getPubkey PubKeyAlgorithm
DeprecatedRSASignOnly = PubKeyAlgorithm -> Get PKey
getPubkey PubKeyAlgorithm
RSA
getPubkey PubKeyAlgorithm
DSA = do
MPI Integer
p <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
q <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
g <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
y <- Get MPI
forall t. Binary t => Get t
get
PKey -> Get PKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKey -> Get PKey) -> PKey -> Get PKey
forall a b. (a -> b) -> a -> b
$ DSA_PublicKey -> PKey
DSAPubKey (PublicKey -> DSA_PublicKey
DSA_PublicKey (Params -> Integer -> PublicKey
D.PublicKey (Integer -> Integer -> Integer -> Params
D.Params Integer
p Integer
g Integer
q) Integer
y))
getPubkey PubKeyAlgorithm
ElgamalEncryptOnly = PubKeyAlgorithm -> Get PKey
getPubkey PubKeyAlgorithm
ForbiddenElgamal
getPubkey PubKeyAlgorithm
ForbiddenElgamal = do
MPI Integer
p <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
g <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
y <- Get MPI
forall t. Binary t => Get t
get
PKey -> Get PKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKey -> Get PKey) -> PKey -> Get PKey
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> Integer -> PKey
ElGamalPubKey Integer
p Integer
g Integer
y
getPubkey PubKeyAlgorithm
ECDSA = do
Word8
curvelength <- Get Word8
getWord8
ByteString
curveoid <- Int -> Get ByteString
getByteString (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
curvelength)
MPI Integer
mpi <- Get MPI
getMPI
case ByteString -> Either String ECCCurve
curveoidBSToCurve ByteString
curveoid of
Left String
e -> String -> Get PKey
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
e
Right ECCCurve
Curve25519 -> PKey -> Get PKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKey -> Get PKey) -> PKey -> Get PKey
forall a b. (a -> b) -> a -> b
$ EdSigningCurve -> EPoint -> PKey
EdDSAPubKey EdSigningCurve
Ed25519 (Integer -> EPoint
EPoint Integer
mpi)
Right ECCCurve
curve ->
case ByteString -> Either String PublicPoint
bs2Point (Integer -> ByteString
forall ba. ByteArray ba => Integer -> ba
i2osp Integer
mpi) of
Left String
e -> String -> Get PKey
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
e
Right PublicPoint
point ->
PKey -> Get PKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKey -> Get PKey)
-> (PublicPoint -> PKey) -> PublicPoint -> Get PKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ECDSA_PublicKey -> PKey
ECDSAPubKey (ECDSA_PublicKey -> PKey)
-> (PublicPoint -> ECDSA_PublicKey) -> PublicPoint -> PKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PublicKey -> ECDSA_PublicKey
ECDSA_PublicKey (PublicKey -> ECDSA_PublicKey)
-> (PublicPoint -> PublicKey) -> PublicPoint -> ECDSA_PublicKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Curve -> PublicPoint -> PublicKey
ECDSA.PublicKey (ECCCurve -> Curve
curve2Curve ECCCurve
curve) (PublicPoint -> Get PKey) -> PublicPoint -> Get PKey
forall a b. (a -> b) -> a -> b
$
PublicPoint
point
getPubkey PubKeyAlgorithm
ECDH = do
PKey
ed <- PubKeyAlgorithm -> Get PKey
getPubkey PubKeyAlgorithm
ECDSA
Word8
kdflen <- Get Word8
getWord8
Word8
one <- Get Word8
getWord8
HashAlgorithm
kdfHA <- Get HashAlgorithm
forall t. Binary t => Get t
get
SymmetricAlgorithm
kdfSA <- Get SymmetricAlgorithm
forall t. Binary t => Get t
get
PKey -> Get PKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKey -> Get PKey) -> PKey -> Get PKey
forall a b. (a -> b) -> a -> b
$ PKey -> HashAlgorithm -> SymmetricAlgorithm -> PKey
ECDHPubKey PKey
ed HashAlgorithm
kdfHA SymmetricAlgorithm
kdfSA
getPubkey PubKeyAlgorithm
EdDSA = do
Word8
curvelength <- Get Word8
getWord8
ByteString
curveoid <- Int -> Get ByteString
getByteString (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
curvelength)
MPI Integer
mpi <- Get MPI
getMPI
case ByteString -> Either String EdSigningCurve
curveoidBSToEdSigningCurve ByteString
curveoid of
Left String
e -> String -> Get PKey
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
e
Right EdSigningCurve
Ed25519 -> PKey -> Get PKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKey -> Get PKey) -> (EPoint -> PKey) -> EPoint -> Get PKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EdSigningCurve -> EPoint -> PKey
EdDSAPubKey EdSigningCurve
Ed25519 (EPoint -> Get PKey) -> EPoint -> Get PKey
forall a b. (a -> b) -> a -> b
$ Integer -> EPoint
EPoint Integer
mpi
getPubkey PubKeyAlgorithm
_ = ByteString -> PKey
UnknownPKey (ByteString -> PKey) -> Get ByteString -> Get PKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get ByteString
getRemainingLazyByteString
bs2Point :: B.ByteString -> Either String ECDSA.PublicPoint
bs2Point :: ByteString -> Either String PublicPoint
bs2Point ByteString
bs =
let xy :: ByteString
xy = Int -> ByteString -> ByteString
B.drop Int
1 ByteString
bs
in let l :: Int
l = ByteString -> Int
B.length ByteString
xy
in if HasCallStack => ByteString -> Word8
ByteString -> Word8
B.head ByteString
bs Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
0x04
then PublicPoint -> Either String PublicPoint
forall a. a -> Either String a
forall (m :: * -> *) a. Monad m => a -> m a
return
((Integer -> Integer -> PublicPoint)
-> (Integer, Integer) -> PublicPoint
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry
Integer -> Integer -> PublicPoint
ECCT.Point
((ByteString -> Integer)
-> (ByteString -> Integer)
-> (ByteString, ByteString)
-> (Integer, Integer)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ByteString -> Integer
forall ba. ByteArrayAccess ba => ba -> Integer
os2ip ByteString -> Integer
forall ba. ByteArrayAccess ba => ba -> Integer
os2ip (Int -> ByteString -> (ByteString, ByteString)
B.splitAt (Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
l Int
2) ByteString
xy)))
else String -> Either String PublicPoint
forall a b. a -> Either a b
Left (String -> Either String PublicPoint)
-> String -> Either String PublicPoint
forall a b. (a -> b) -> a -> b
$ String
"unknown type of point: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Word8] -> String
forall a. Show a => a -> String
show (ByteString -> [Word8]
B.unpack ByteString
bs)
putPubkey :: PKey -> Put
putPubkey :: PKey -> Put
putPubkey (UnknownPKey ByteString
bs) = ByteString -> Put
putLazyByteString ByteString
bs
putPubkey p :: PKey
p@(ECDSAPubKey (ECDSA_PublicKey (ECDSA.PublicKey Curve
curve PublicPoint
_))) =
let Right ByteString
curveoidbs = ECCCurve -> Either String ByteString
curveToCurveoidBS (Curve -> ECCCurve
curveFromCurve Curve
curve)
in Word8 -> Put
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
B.length ByteString
curveoidbs)) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
putByteString ByteString
curveoidbs Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
(MPI -> Put) -> [MPI] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ MPI -> Put
forall t. Binary t => t -> Put
put (PKey -> [MPI]
pubkeyToMPIs PKey
p)
putPubkey p :: PKey
p@(ECDHPubKey (ECDSAPubKey (ECDSA_PublicKey (ECDSA.PublicKey Curve
curve PublicPoint
_))) HashAlgorithm
kha SymmetricAlgorithm
ksa) =
let Right ByteString
curveoidbs = ECCCurve -> Either String ByteString
curveToCurveoidBS (Curve -> ECCCurve
curveFromCurve Curve
curve)
in Word8 -> Put
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
B.length ByteString
curveoidbs)) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
putByteString ByteString
curveoidbs Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
(MPI -> Put) -> [MPI] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ MPI -> Put
forall t. Binary t => t -> Put
put (PKey -> [MPI]
pubkeyToMPIs PKey
p) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Word8 -> Put
putWord8 Word8
0x03 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Word8 -> Put
putWord8 Word8
0x01 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
HashAlgorithm -> Put
forall t. Binary t => t -> Put
put HashAlgorithm
kha Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
SymmetricAlgorithm -> Put
forall t. Binary t => t -> Put
put SymmetricAlgorithm
ksa
putPubkey p :: PKey
p@(ECDHPubKey (EdDSAPubKey EdSigningCurve
curve EPoint
_) HashAlgorithm
kha SymmetricAlgorithm
ksa) =
let Right ByteString
curveoidbs = ECCCurve -> Either String ByteString
curveToCurveoidBS (EdSigningCurve -> ECCCurve
ed2ec EdSigningCurve
curve)
in Word8 -> Put
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
B.length ByteString
curveoidbs)) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
putByteString ByteString
curveoidbs Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
(MPI -> Put) -> [MPI] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ MPI -> Put
forall t. Binary t => t -> Put
put (PKey -> [MPI]
pubkeyToMPIs PKey
p) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Word8 -> Put
putWord8 Word8
0x03 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Word8 -> Put
putWord8 Word8
0x01 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
HashAlgorithm -> Put
forall t. Binary t => t -> Put
put HashAlgorithm
kha Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
SymmetricAlgorithm -> Put
forall t. Binary t => t -> Put
put SymmetricAlgorithm
ksa
where
ed2ec :: EdSigningCurve -> ECCCurve
ed2ec EdSigningCurve
Ed25519 = ECCCurve
Curve25519
putPubkey p :: PKey
p@(EdDSAPubKey EdSigningCurve
curve EPoint
_) =
let Right ByteString
curveoidbs = EdSigningCurve -> Either String ByteString
edSigningCurveToCurveoidBS EdSigningCurve
curve
in Word8 -> Put
putWord8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
B.length ByteString
curveoidbs)) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
putByteString ByteString
curveoidbs Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
(MPI -> Put) -> [MPI] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ MPI -> Put
forall t. Binary t => t -> Put
put (PKey -> [MPI]
pubkeyToMPIs PKey
p)
putPubkey PKey
p = (MPI -> Put) -> [MPI] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ MPI -> Put
forall t. Binary t => t -> Put
put (PKey -> [MPI]
pubkeyToMPIs PKey
p)
getSecretKey :: PKPayload -> Get SKey
getSecretKey :: PKPayload -> Get SKey
getSecretKey PKPayload
pkp
| PKPayload -> PubKeyAlgorithm
_pkalgo PKPayload
pkp PubKeyAlgorithm -> [PubKeyAlgorithm] -> Exportability
forall a. Eq a => a -> [a] -> Exportability
forall (t :: * -> *) a.
(Foldable t, Eq a) =>
a -> t a -> Exportability
`elem` [PubKeyAlgorithm
RSA, PubKeyAlgorithm
DeprecatedRSAEncryptOnly, PubKeyAlgorithm
DeprecatedRSASignOnly] = do
MPI Integer
d <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
p <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
q <- Get MPI
forall t. Binary t => Get t
get
MPI Integer
_ <- Get MPI
forall t. Binary t => Get t
get
let dP :: Integer
dP = Integer
0
dQ :: Integer
dQ = Integer
0
qinv :: Integer
qinv = Integer
0
pub :: PublicKey
pub = (\(RSAPubKey (RSA_PublicKey PublicKey
x)) -> PublicKey
x) (PKPayload
pkp PKPayload -> Getting PKey PKPayload PKey -> PKey
forall s a. s -> Getting a s a -> a
^. Getting PKey PKPayload PKey
Lens' PKPayload PKey
pubkey)
SKey -> Get SKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKey -> Get SKey) -> SKey -> Get SKey
forall a b. (a -> b) -> a -> b
$ RSA_PrivateKey -> SKey
RSAPrivateKey (PrivateKey -> RSA_PrivateKey
RSA_PrivateKey (PublicKey
-> Integer
-> Integer
-> Integer
-> Integer
-> Integer
-> Integer
-> PrivateKey
R.PrivateKey PublicKey
pub Integer
d Integer
p Integer
q Integer
dP Integer
dQ Integer
qinv))
| PKPayload -> PubKeyAlgorithm
_pkalgo PKPayload
pkp PubKeyAlgorithm -> PubKeyAlgorithm -> Exportability
forall a. Eq a => a -> a -> Exportability
== PubKeyAlgorithm
DSA = do
MPI Integer
x <- Get MPI
forall t. Binary t => Get t
get
SKey -> Get SKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKey -> Get SKey) -> SKey -> Get SKey
forall a b. (a -> b) -> a -> b
$ DSA_PrivateKey -> SKey
DSAPrivateKey (PrivateKey -> DSA_PrivateKey
DSA_PrivateKey (Params -> Integer -> PrivateKey
D.PrivateKey (Integer -> Integer -> Integer -> Params
D.Params Integer
0 Integer
0 Integer
0) Integer
x))
| PKPayload -> PubKeyAlgorithm
_pkalgo PKPayload
pkp PubKeyAlgorithm -> [PubKeyAlgorithm] -> Exportability
forall a. Eq a => a -> [a] -> Exportability
forall (t :: * -> *) a.
(Foldable t, Eq a) =>
a -> t a -> Exportability
`elem` [PubKeyAlgorithm
ElgamalEncryptOnly, PubKeyAlgorithm
ForbiddenElgamal] = do
MPI Integer
x <- Get MPI
forall t. Binary t => Get t
get
SKey -> Get SKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKey -> Get SKey) -> SKey -> Get SKey
forall a b. (a -> b) -> a -> b
$ Integer -> SKey
ElGamalPrivateKey Integer
x
| PKPayload -> PubKeyAlgorithm
_pkalgo PKPayload
pkp PubKeyAlgorithm -> PubKeyAlgorithm -> Exportability
forall a. Eq a => a -> a -> Exportability
== PubKeyAlgorithm
ECDSA = do
MPI Integer
pn <- Get MPI
forall t. Binary t => Get t
get
let pubcurve :: Curve
pubcurve =
(\(ECDSAPubKey (ECDSA_PublicKey PublicKey
p)) -> PublicKey -> Curve
ECDSA.public_curve PublicKey
p)
(PKPayload
pkp PKPayload -> Getting PKey PKPayload PKey -> PKey
forall s a. s -> Getting a s a -> a
^. Getting PKey PKPayload PKey
Lens' PKPayload PKey
pubkey)
SKey -> Get SKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKey -> Get SKey) -> SKey -> Get SKey
forall a b. (a -> b) -> a -> b
$ ECDSA_PrivateKey -> SKey
ECDSAPrivateKey (PrivateKey -> ECDSA_PrivateKey
ECDSA_PrivateKey (Curve -> Integer -> PrivateKey
ECDSA.PrivateKey Curve
pubcurve Integer
pn))
| PKPayload -> PubKeyAlgorithm
_pkalgo PKPayload
pkp PubKeyAlgorithm -> PubKeyAlgorithm -> Exportability
forall a. Eq a => a -> a -> Exportability
== PubKeyAlgorithm
ECDH
= do
MPI Integer
pn <- Get MPI
forall t. Binary t => Get t
get
let pubcurve :: Curve
pubcurve =
(\(ECDSAPubKey (ECDSA_PublicKey PublicKey
p)) -> PublicKey -> Curve
ECDSA.public_curve PublicKey
p)
(PKPayload
pkp PKPayload -> Getting PKey PKPayload PKey -> PKey
forall s a. s -> Getting a s a -> a
^. Getting PKey PKPayload PKey
Lens' PKPayload PKey
pubkey)
SKey -> Get SKey
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKey -> Get SKey) -> SKey -> Get SKey
forall a b. (a -> b) -> a -> b
$ ECDSA_PrivateKey -> SKey
ECDHPrivateKey (PrivateKey -> ECDSA_PrivateKey
ECDSA_PrivateKey (Curve -> Integer -> PrivateKey
ECDSA.PrivateKey Curve
pubcurve Integer
pn))
putSKey :: SKey -> Put
putSKey :: SKey -> Put
putSKey (RSAPrivateKey (RSA_PrivateKey (R.PrivateKey PublicKey
_ Integer
d Integer
p Integer
q Integer
_ Integer
_ Integer
_))) =
MPI -> Put
forall t. Binary t => t -> Put
put (Integer -> MPI
MPI Integer
d) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MPI -> Put
forall t. Binary t => t -> Put
put (Integer -> MPI
MPI Integer
p) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MPI -> Put
forall t. Binary t => t -> Put
put (Integer -> MPI
MPI Integer
q) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MPI -> Put
forall t. Binary t => t -> Put
put (Integer -> MPI
MPI Integer
u)
where
u :: Integer
u = Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
multiplicativeInverse Integer
q Integer
p
putMPI :: MPI -> Put
putMPI :: MPI -> Put
putMPI (MPI Integer
i) = do
let bs :: ByteString
bs = Integer -> ByteString
forall ba. ByteArray ba => Integer -> ba
i2osp Integer
i
Word16 -> Put
putWord16be (Word16 -> Put) -> (Integer -> Word16) -> Integer -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word16) -> (Integer -> Int) -> Integer -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Int
numBits (Integer -> Put) -> Integer -> Put
forall a b. (a -> b) -> a -> b
$ Integer
i
ByteString -> Put
putByteString ByteString
bs
getPKPayload :: Get PKPayload
getPKPayload :: Get PKPayload
getPKPayload = do
Word8
version <- Get Word8
getWord8
ThirtyTwoBitTimeStamp
ctime <- (Word32 -> ThirtyTwoBitTimeStamp)
-> Get Word32 -> Get ThirtyTwoBitTimeStamp
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> ThirtyTwoBitTimeStamp
ThirtyTwoBitTimeStamp Get Word32
getWord32be
if Word8
version Word8 -> [Word8] -> Exportability
forall a. Eq a => a -> [a] -> Exportability
forall (t :: * -> *) a.
(Foldable t, Eq a) =>
a -> t a -> Exportability
`elem` [Word8
2, Word8
3]
then do
Word16
v3e <- Get Word16
getWord16be
PubKeyAlgorithm
pka <- Get PubKeyAlgorithm
forall t. Binary t => Get t
get
PKey
pk <- PubKeyAlgorithm -> Get PKey
getPubkey PubKeyAlgorithm
pka
PKPayload -> Get PKPayload
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKPayload -> Get PKPayload) -> PKPayload -> Get PKPayload
forall a b. (a -> b) -> a -> b
$! KeyVersion
-> ThirtyTwoBitTimeStamp
-> Word16
-> PubKeyAlgorithm
-> PKey
-> PKPayload
PKPayload KeyVersion
DeprecatedV3 ThirtyTwoBitTimeStamp
ctime Word16
v3e PubKeyAlgorithm
pka PKey
pk
else do
PubKeyAlgorithm
pka <- Get PubKeyAlgorithm
forall t. Binary t => Get t
get
PKey
pk <- PubKeyAlgorithm -> Get PKey
getPubkey PubKeyAlgorithm
pka
PKPayload -> Get PKPayload
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (PKPayload -> Get PKPayload) -> PKPayload -> Get PKPayload
forall a b. (a -> b) -> a -> b
$! KeyVersion
-> ThirtyTwoBitTimeStamp
-> Word16
-> PubKeyAlgorithm
-> PKey
-> PKPayload
PKPayload KeyVersion
V4 ThirtyTwoBitTimeStamp
ctime Word16
0 PubKeyAlgorithm
pka PKey
pk
putPKPayload :: PKPayload -> Put
putPKPayload :: PKPayload -> Put
putPKPayload (PKPayload KeyVersion
DeprecatedV3 ThirtyTwoBitTimeStamp
ctime Word16
v3e PubKeyAlgorithm
pka PKey
pk) = do
Word8 -> Put
putWord8 Word8
3
Word32 -> Put
putWord32be (Word32 -> Put)
-> (ThirtyTwoBitTimeStamp -> Word32)
-> ThirtyTwoBitTimeStamp
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThirtyTwoBitTimeStamp -> Word32
unThirtyTwoBitTimeStamp (ThirtyTwoBitTimeStamp -> Put) -> ThirtyTwoBitTimeStamp -> Put
forall a b. (a -> b) -> a -> b
$ ThirtyTwoBitTimeStamp
ctime
Word16 -> Put
putWord16be Word16
v3e
PubKeyAlgorithm -> Put
forall t. Binary t => t -> Put
put PubKeyAlgorithm
pka
PKey -> Put
putPubkey PKey
pk
putPKPayload (PKPayload KeyVersion
V4 ThirtyTwoBitTimeStamp
ctime Word16
_ PubKeyAlgorithm
pka PKey
pk) = do
Word8 -> Put
putWord8 Word8
4
Word32 -> Put
putWord32be (Word32 -> Put)
-> (ThirtyTwoBitTimeStamp -> Word32)
-> ThirtyTwoBitTimeStamp
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThirtyTwoBitTimeStamp -> Word32
unThirtyTwoBitTimeStamp (ThirtyTwoBitTimeStamp -> Put) -> ThirtyTwoBitTimeStamp -> Put
forall a b. (a -> b) -> a -> b
$ ThirtyTwoBitTimeStamp
ctime
PubKeyAlgorithm -> Put
forall t. Binary t => t -> Put
put PubKeyAlgorithm
pka
PKey -> Put
putPubkey PKey
pk
getSKAddendum :: PKPayload -> Get SKAddendum
getSKAddendum :: PKPayload -> Get SKAddendum
getSKAddendum PKPayload
pkp = do
Word8
s2kusage <- Get Word8
getWord8
case Word8
s2kusage of
Word8
0 -> do
SKey
sk <- PKPayload -> Get SKey
getSecretKey PKPayload
pkp
Word16
checksum <- Get Word16
getWord16be
SKAddendum -> Get SKAddendum
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKAddendum -> Get SKAddendum) -> SKAddendum -> Get SKAddendum
forall a b. (a -> b) -> a -> b
$ SKey -> Word16 -> SKAddendum
SUUnencrypted SKey
sk Word16
checksum
Word8
255 -> do
Word8
symenc <- Get Word8
getWord8
S2K
s2k <- Get S2K
getS2K
case S2K
s2k
of
OtherS2K Word8
_ ByteString
_ -> SKAddendum -> Get SKAddendum
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKAddendum -> Get SKAddendum) -> SKAddendum -> Get SKAddendum
forall a b. (a -> b) -> a -> b
$ SymmetricAlgorithm -> S2K -> IV -> ByteString -> SKAddendum
SUS16bit (Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
symenc) S2K
s2k IV
forall a. Monoid a => a
mempty ByteString
BL.empty
S2K
_ -> do
ByteString
iv <- Int -> Get ByteString
getByteString (SymmetricAlgorithm -> Int
symEncBlockSize (SymmetricAlgorithm -> Int)
-> (Word8 -> SymmetricAlgorithm) -> Word8 -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> Int) -> Word8 -> Int
forall a b. (a -> b) -> a -> b
$ Word8
symenc)
ByteString
encryptedblock <- Get ByteString
getRemainingLazyByteString
SKAddendum -> Get SKAddendum
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKAddendum -> Get SKAddendum) -> SKAddendum -> Get SKAddendum
forall a b. (a -> b) -> a -> b
$ SymmetricAlgorithm -> S2K -> IV -> ByteString -> SKAddendum
SUS16bit (Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
symenc) S2K
s2k (ByteString -> IV
IV ByteString
iv) ByteString
encryptedblock
Word8
254 -> do
Word8
symenc <- Get Word8
getWord8
S2K
s2k <- Get S2K
getS2K
case S2K
s2k
of
OtherS2K Word8
_ ByteString
_ -> SKAddendum -> Get SKAddendum
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKAddendum -> Get SKAddendum) -> SKAddendum -> Get SKAddendum
forall a b. (a -> b) -> a -> b
$ SymmetricAlgorithm -> S2K -> IV -> ByteString -> SKAddendum
SUSSHA1 (Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
symenc) S2K
s2k IV
forall a. Monoid a => a
mempty ByteString
BL.empty
S2K
_ -> do
ByteString
iv <- Int -> Get ByteString
getByteString (SymmetricAlgorithm -> Int
symEncBlockSize (SymmetricAlgorithm -> Int)
-> (Word8 -> SymmetricAlgorithm) -> Word8 -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> Int) -> Word8 -> Int
forall a b. (a -> b) -> a -> b
$ Word8
symenc)
ByteString
encryptedblock <- Get ByteString
getRemainingLazyByteString
SKAddendum -> Get SKAddendum
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKAddendum -> Get SKAddendum) -> SKAddendum -> Get SKAddendum
forall a b. (a -> b) -> a -> b
$ SymmetricAlgorithm -> S2K -> IV -> ByteString -> SKAddendum
SUSSHA1 (Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
symenc) S2K
s2k (ByteString -> IV
IV ByteString
iv) ByteString
encryptedblock
Word8
symenc -> do
ByteString
iv <- Int -> Get ByteString
getByteString (SymmetricAlgorithm -> Int
symEncBlockSize (SymmetricAlgorithm -> Int)
-> (Word8 -> SymmetricAlgorithm) -> Word8 -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal (Word8 -> Int) -> Word8 -> Int
forall a b. (a -> b) -> a -> b
$ Word8
symenc)
ByteString
encryptedblock <- Get ByteString
getRemainingLazyByteString
SKAddendum -> Get SKAddendum
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SKAddendum -> Get SKAddendum) -> SKAddendum -> Get SKAddendum
forall a b. (a -> b) -> a -> b
$ SymmetricAlgorithm -> IV -> ByteString -> SKAddendum
SUSym (Word8 -> SymmetricAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
symenc) (ByteString -> IV
IV ByteString
iv) ByteString
encryptedblock
putSKAddendum :: SKAddendum -> Put
putSKAddendum :: SKAddendum -> Put
putSKAddendum (SUSSHA1 SymmetricAlgorithm
symenc S2K
s2k IV
iv ByteString
encryptedblock) = do
Word8 -> Put
putWord8 Word8
254
SymmetricAlgorithm -> Put
forall t. Binary t => t -> Put
put SymmetricAlgorithm
symenc
S2K -> Put
forall t. Binary t => t -> Put
put S2K
s2k
ByteString -> Put
putByteString (IV -> ByteString
unIV IV
iv)
ByteString -> Put
putLazyByteString ByteString
encryptedblock
putSKAddendum (SUUnencrypted SKey
sk Word16
checksum) = do
Word8 -> Put
putWord8 Word8
0
let skb :: ByteString
skb = Put -> ByteString
runPut (SKey -> Put
putSKey SKey
sk)
ByteString -> Put
putLazyByteString ByteString
skb
Word16 -> Put
putWord16be
(if Word16
checksum Word16 -> Word16 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word16
0
then (Word16 -> Word8 -> Word16) -> Word16 -> ByteString -> Word16
forall a. (a -> Word8 -> a) -> a -> ByteString -> a
BL.foldl (\Word16
a Word8
b -> Word16 -> Word16 -> Word16
forall a. Integral a => a -> a -> a
mod (Word16
a Word16 -> Word16 -> Word16
forall a. Num a => a -> a -> a
+ Word8 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b) Word16
0xffff) (Word16
0 :: Word16) ByteString
skb
else Word16
checksum)
putSKAddendum SKAddendum
_ = String -> Put
forall a. HasCallStack => String -> a
error String
"Type not supported"
symEncBlockSize :: SymmetricAlgorithm -> Int
symEncBlockSize :: SymmetricAlgorithm -> Int
symEncBlockSize SymmetricAlgorithm
Plaintext = Int
0
symEncBlockSize SymmetricAlgorithm
IDEA = Int
8
symEncBlockSize SymmetricAlgorithm
TripleDES = Int
8
symEncBlockSize SymmetricAlgorithm
CAST5 = Int
8
symEncBlockSize SymmetricAlgorithm
Blowfish = Int
8
symEncBlockSize SymmetricAlgorithm
AES128 = Int
16
symEncBlockSize SymmetricAlgorithm
AES192 = Int
16
symEncBlockSize SymmetricAlgorithm
AES256 = Int
16
symEncBlockSize SymmetricAlgorithm
Twofish = Int
16
symEncBlockSize SymmetricAlgorithm
Camellia128 = Int
16
symEncBlockSize SymmetricAlgorithm
_ = Int
8
decodeIterationCount :: Word8 -> IterationCount
decodeIterationCount :: Word8 -> IterationCount
decodeIterationCount Word8
c =
Int -> IterationCount
IterationCount
((Int
16 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
c Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. Int
15)) Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftL` ((Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
c Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` Int
4) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6))
encodeIterationCount :: IterationCount -> Word8
encodeIterationCount :: IterationCount -> Word8
encodeIterationCount IterationCount
1024 = Word8
0
encodeIterationCount IterationCount
1088 = Word8
1
encodeIterationCount IterationCount
1152 = Word8
2
encodeIterationCount IterationCount
1216 = Word8
3
encodeIterationCount IterationCount
1280 = Word8
4
encodeIterationCount IterationCount
1344 = Word8
5
encodeIterationCount IterationCount
1408 = Word8
6
encodeIterationCount IterationCount
1472 = Word8
7
encodeIterationCount IterationCount
1536 = Word8
8
encodeIterationCount IterationCount
1600 = Word8
9
encodeIterationCount IterationCount
1664 = Word8
10
encodeIterationCount IterationCount
1728 = Word8
11
encodeIterationCount IterationCount
1792 = Word8
12
encodeIterationCount IterationCount
1856 = Word8
13
encodeIterationCount IterationCount
1920 = Word8
14
encodeIterationCount IterationCount
1984 = Word8
15
encodeIterationCount IterationCount
2048 = Word8
16
encodeIterationCount IterationCount
2176 = Word8
17
encodeIterationCount IterationCount
2304 = Word8
18
encodeIterationCount IterationCount
2432 = Word8
19
encodeIterationCount IterationCount
2560 = Word8
20
encodeIterationCount IterationCount
2688 = Word8
21
encodeIterationCount IterationCount
2816 = Word8
22
encodeIterationCount IterationCount
2944 = Word8
23
encodeIterationCount IterationCount
3072 = Word8
24
encodeIterationCount IterationCount
3200 = Word8
25
encodeIterationCount IterationCount
3328 = Word8
26
encodeIterationCount IterationCount
3456 = Word8
27
encodeIterationCount IterationCount
3584 = Word8
28
encodeIterationCount IterationCount
3712 = Word8
29
encodeIterationCount IterationCount
3840 = Word8
30
encodeIterationCount IterationCount
3968 = Word8
31
encodeIterationCount IterationCount
4096 = Word8
32
encodeIterationCount IterationCount
4352 = Word8
33
encodeIterationCount IterationCount
4608 = Word8
34
encodeIterationCount IterationCount
4864 = Word8
35
encodeIterationCount IterationCount
5120 = Word8
36
encodeIterationCount IterationCount
5376 = Word8
37
encodeIterationCount IterationCount
5632 = Word8
38
encodeIterationCount IterationCount
5888 = Word8
39
encodeIterationCount IterationCount
6144 = Word8
40
encodeIterationCount IterationCount
6400 = Word8
41
encodeIterationCount IterationCount
6656 = Word8
42
encodeIterationCount IterationCount
6912 = Word8
43
encodeIterationCount IterationCount
7168 = Word8
44
encodeIterationCount IterationCount
7424 = Word8
45
encodeIterationCount IterationCount
7680 = Word8
46
encodeIterationCount IterationCount
7936 = Word8
47
encodeIterationCount IterationCount
8192 = Word8
48
encodeIterationCount IterationCount
8704 = Word8
49
encodeIterationCount IterationCount
9216 = Word8
50
encodeIterationCount IterationCount
9728 = Word8
51
encodeIterationCount IterationCount
10240 = Word8
52
encodeIterationCount IterationCount
10752 = Word8
53
encodeIterationCount IterationCount
11264 = Word8
54
encodeIterationCount IterationCount
11776 = Word8
55
encodeIterationCount IterationCount
12288 = Word8
56
encodeIterationCount IterationCount
12800 = Word8
57
encodeIterationCount IterationCount
13312 = Word8
58
encodeIterationCount IterationCount
13824 = Word8
59
encodeIterationCount IterationCount
14336 = Word8
60
encodeIterationCount IterationCount
14848 = Word8
61
encodeIterationCount IterationCount
15360 = Word8
62
encodeIterationCount IterationCount
15872 = Word8
63
encodeIterationCount IterationCount
16384 = Word8
64
encodeIterationCount IterationCount
17408 = Word8
65
encodeIterationCount IterationCount
18432 = Word8
66
encodeIterationCount IterationCount
19456 = Word8
67
encodeIterationCount IterationCount
20480 = Word8
68
encodeIterationCount IterationCount
21504 = Word8
69
encodeIterationCount IterationCount
22528 = Word8
70
encodeIterationCount IterationCount
23552 = Word8
71
encodeIterationCount IterationCount
24576 = Word8
72
encodeIterationCount IterationCount
25600 = Word8
73
encodeIterationCount IterationCount
26624 = Word8
74
encodeIterationCount IterationCount
27648 = Word8
75
encodeIterationCount IterationCount
28672 = Word8
76
encodeIterationCount IterationCount
29696 = Word8
77
encodeIterationCount IterationCount
30720 = Word8
78
encodeIterationCount IterationCount
31744 = Word8
79
encodeIterationCount IterationCount
32768 = Word8
80
encodeIterationCount IterationCount
34816 = Word8
81
encodeIterationCount IterationCount
36864 = Word8
82
encodeIterationCount IterationCount
38912 = Word8
83
encodeIterationCount IterationCount
40960 = Word8
84
encodeIterationCount IterationCount
43008 = Word8
85
encodeIterationCount IterationCount
45056 = Word8
86
encodeIterationCount IterationCount
47104 = Word8
87
encodeIterationCount IterationCount
49152 = Word8
88
encodeIterationCount IterationCount
51200 = Word8
89
encodeIterationCount IterationCount
53248 = Word8
90
encodeIterationCount IterationCount
55296 = Word8
91
encodeIterationCount IterationCount
57344 = Word8
92
encodeIterationCount IterationCount
59392 = Word8
93
encodeIterationCount IterationCount
61440 = Word8
94
encodeIterationCount IterationCount
63488 = Word8
95
encodeIterationCount IterationCount
65536 = Word8
96
encodeIterationCount IterationCount
69632 = Word8
97
encodeIterationCount IterationCount
73728 = Word8
98
encodeIterationCount IterationCount
77824 = Word8
99
encodeIterationCount IterationCount
81920 = Word8
100
encodeIterationCount IterationCount
86016 = Word8
101
encodeIterationCount IterationCount
90112 = Word8
102
encodeIterationCount IterationCount
94208 = Word8
103
encodeIterationCount IterationCount
98304 = Word8
104
encodeIterationCount IterationCount
102400 = Word8
105
encodeIterationCount IterationCount
106496 = Word8
106
encodeIterationCount IterationCount
110592 = Word8
107
encodeIterationCount IterationCount
114688 = Word8
108
encodeIterationCount IterationCount
118784 = Word8
109
encodeIterationCount IterationCount
122880 = Word8
110
encodeIterationCount IterationCount
126976 = Word8
111
encodeIterationCount IterationCount
131072 = Word8
112
encodeIterationCount IterationCount
139264 = Word8
113
encodeIterationCount IterationCount
147456 = Word8
114
encodeIterationCount IterationCount
155648 = Word8
115
encodeIterationCount IterationCount
163840 = Word8
116
encodeIterationCount IterationCount
172032 = Word8
117
encodeIterationCount IterationCount
180224 = Word8
118
encodeIterationCount IterationCount
188416 = Word8
119
encodeIterationCount IterationCount
196608 = Word8
120
encodeIterationCount IterationCount
204800 = Word8
121
encodeIterationCount IterationCount
212992 = Word8
122
encodeIterationCount IterationCount
221184 = Word8
123
encodeIterationCount IterationCount
229376 = Word8
124
encodeIterationCount IterationCount
237568 = Word8
125
encodeIterationCount IterationCount
245760 = Word8
126
encodeIterationCount IterationCount
253952 = Word8
127
encodeIterationCount IterationCount
262144 = Word8
128
encodeIterationCount IterationCount
278528 = Word8
129
encodeIterationCount IterationCount
294912 = Word8
130
encodeIterationCount IterationCount
311296 = Word8
131
encodeIterationCount IterationCount
327680 = Word8
132
encodeIterationCount IterationCount
344064 = Word8
133
encodeIterationCount IterationCount
360448 = Word8
134
encodeIterationCount IterationCount
376832 = Word8
135
encodeIterationCount IterationCount
393216 = Word8
136
encodeIterationCount IterationCount
409600 = Word8
137
encodeIterationCount IterationCount
425984 = Word8
138
encodeIterationCount IterationCount
442368 = Word8
139
encodeIterationCount IterationCount
458752 = Word8
140
encodeIterationCount IterationCount
475136 = Word8
141
encodeIterationCount IterationCount
491520 = Word8
142
encodeIterationCount IterationCount
507904 = Word8
143
encodeIterationCount IterationCount
524288 = Word8
144
encodeIterationCount IterationCount
557056 = Word8
145
encodeIterationCount IterationCount
589824 = Word8
146
encodeIterationCount IterationCount
622592 = Word8
147
encodeIterationCount IterationCount
655360 = Word8
148
encodeIterationCount IterationCount
688128 = Word8
149
encodeIterationCount IterationCount
720896 = Word8
150
encodeIterationCount IterationCount
753664 = Word8
151
encodeIterationCount IterationCount
786432 = Word8
152
encodeIterationCount IterationCount
819200 = Word8
153
encodeIterationCount IterationCount
851968 = Word8
154
encodeIterationCount IterationCount
884736 = Word8
155
encodeIterationCount IterationCount
917504 = Word8
156
encodeIterationCount IterationCount
950272 = Word8
157
encodeIterationCount IterationCount
983040 = Word8
158
encodeIterationCount IterationCount
1015808 = Word8
159
encodeIterationCount IterationCount
1048576 = Word8
160
encodeIterationCount IterationCount
1114112 = Word8
161
encodeIterationCount IterationCount
1179648 = Word8
162
encodeIterationCount IterationCount
1245184 = Word8
163
encodeIterationCount IterationCount
1310720 = Word8
164
encodeIterationCount IterationCount
1376256 = Word8
165
encodeIterationCount IterationCount
1441792 = Word8
166
encodeIterationCount IterationCount
1507328 = Word8
167
encodeIterationCount IterationCount
1572864 = Word8
168
encodeIterationCount IterationCount
1638400 = Word8
169
encodeIterationCount IterationCount
1703936 = Word8
170
encodeIterationCount IterationCount
1769472 = Word8
171
encodeIterationCount IterationCount
1835008 = Word8
172
encodeIterationCount IterationCount
1900544 = Word8
173
encodeIterationCount IterationCount
1966080 = Word8
174
encodeIterationCount IterationCount
2031616 = Word8
175
encodeIterationCount IterationCount
2097152 = Word8
176
encodeIterationCount IterationCount
2228224 = Word8
177
encodeIterationCount IterationCount
2359296 = Word8
178
encodeIterationCount IterationCount
2490368 = Word8
179
encodeIterationCount IterationCount
2621440 = Word8
180
encodeIterationCount IterationCount
2752512 = Word8
181
encodeIterationCount IterationCount
2883584 = Word8
182
encodeIterationCount IterationCount
3014656 = Word8
183
encodeIterationCount IterationCount
3145728 = Word8
184
encodeIterationCount IterationCount
3276800 = Word8
185
encodeIterationCount IterationCount
3407872 = Word8
186
encodeIterationCount IterationCount
3538944 = Word8
187
encodeIterationCount IterationCount
3670016 = Word8
188
encodeIterationCount IterationCount
3801088 = Word8
189
encodeIterationCount IterationCount
3932160 = Word8
190
encodeIterationCount IterationCount
4063232 = Word8
191
encodeIterationCount IterationCount
4194304 = Word8
192
encodeIterationCount IterationCount
4456448 = Word8
193
encodeIterationCount IterationCount
4718592 = Word8
194
encodeIterationCount IterationCount
4980736 = Word8
195
encodeIterationCount IterationCount
5242880 = Word8
196
encodeIterationCount IterationCount
5505024 = Word8
197
encodeIterationCount IterationCount
5767168 = Word8
198
encodeIterationCount IterationCount
6029312 = Word8
199
encodeIterationCount IterationCount
6291456 = Word8
200
encodeIterationCount IterationCount
6553600 = Word8
201
encodeIterationCount IterationCount
6815744 = Word8
202
encodeIterationCount IterationCount
7077888 = Word8
203
encodeIterationCount IterationCount
7340032 = Word8
204
encodeIterationCount IterationCount
7602176 = Word8
205
encodeIterationCount IterationCount
7864320 = Word8
206
encodeIterationCount IterationCount
8126464 = Word8
207
encodeIterationCount IterationCount
8388608 = Word8
208
encodeIterationCount IterationCount
8912896 = Word8
209
encodeIterationCount IterationCount
9437184 = Word8
210
encodeIterationCount IterationCount
9961472 = Word8
211
encodeIterationCount IterationCount
10485760 = Word8
212
encodeIterationCount IterationCount
11010048 = Word8
213
encodeIterationCount IterationCount
11534336 = Word8
214
encodeIterationCount IterationCount
12058624 = Word8
215
encodeIterationCount IterationCount
12582912 = Word8
216
encodeIterationCount IterationCount
13107200 = Word8
217
encodeIterationCount IterationCount
13631488 = Word8
218
encodeIterationCount IterationCount
14155776 = Word8
219
encodeIterationCount IterationCount
14680064 = Word8
220
encodeIterationCount IterationCount
15204352 = Word8
221
encodeIterationCount IterationCount
15728640 = Word8
222
encodeIterationCount IterationCount
16252928 = Word8
223
encodeIterationCount IterationCount
16777216 = Word8
224
encodeIterationCount IterationCount
17825792 = Word8
225
encodeIterationCount IterationCount
18874368 = Word8
226
encodeIterationCount IterationCount
19922944 = Word8
227
encodeIterationCount IterationCount
20971520 = Word8
228
encodeIterationCount IterationCount
22020096 = Word8
229
encodeIterationCount IterationCount
23068672 = Word8
230
encodeIterationCount IterationCount
24117248 = Word8
231
encodeIterationCount IterationCount
25165824 = Word8
232
encodeIterationCount IterationCount
26214400 = Word8
233
encodeIterationCount IterationCount
27262976 = Word8
234
encodeIterationCount IterationCount
28311552 = Word8
235
encodeIterationCount IterationCount
29360128 = Word8
236
encodeIterationCount IterationCount
30408704 = Word8
237
encodeIterationCount IterationCount
31457280 = Word8
238
encodeIterationCount IterationCount
32505856 = Word8
239
encodeIterationCount IterationCount
33554432 = Word8
240
encodeIterationCount IterationCount
35651584 = Word8
241
encodeIterationCount IterationCount
37748736 = Word8
242
encodeIterationCount IterationCount
39845888 = Word8
243
encodeIterationCount IterationCount
41943040 = Word8
244
encodeIterationCount IterationCount
44040192 = Word8
245
encodeIterationCount IterationCount
46137344 = Word8
246
encodeIterationCount IterationCount
48234496 = Word8
247
encodeIterationCount IterationCount
50331648 = Word8
248
encodeIterationCount IterationCount
52428800 = Word8
249
encodeIterationCount IterationCount
54525952 = Word8
250
encodeIterationCount IterationCount
56623104 = Word8
251
encodeIterationCount IterationCount
58720256 = Word8
252
encodeIterationCount IterationCount
60817408 = Word8
253
encodeIterationCount IterationCount
62914560 = Word8
254
encodeIterationCount IterationCount
65011712 = Word8
255
encodeIterationCount IterationCount
n = String -> Word8
forall a. HasCallStack => String -> a
error (String
"invalid iteration count" String -> String -> String
forall a. [a] -> [a] -> [a]
++ IterationCount -> String
forall a. Show a => a -> String
show IterationCount
n)
getSignaturePayload :: Get SignaturePayload
getSignaturePayload :: Get SignaturePayload
getSignaturePayload = do
Word8
pv <- Get Word8
getWord8
case Word8
pv of
Word8
3 -> do
Word8
hashlen <- Get Word8
getWord8
Exportability -> Get ()
forall (f :: * -> *). Alternative f => Exportability -> f ()
guard (Word8
hashlen Word8 -> Word8 -> Exportability
forall a. Eq a => a -> a -> Exportability
== Word8
5)
Word8
st <- Get Word8
getWord8
ThirtyTwoBitTimeStamp
ctime <- (Word32 -> ThirtyTwoBitTimeStamp)
-> Get Word32 -> Get ThirtyTwoBitTimeStamp
forall a b. (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> ThirtyTwoBitTimeStamp
ThirtyTwoBitTimeStamp Get Word32
getWord32be
ByteString
eok <- Int64 -> Get ByteString
getLazyByteString Int64
8
Word8
pka <- Get Word8
forall t. Binary t => Get t
get
Word8
ha <- Get Word8
forall t. Binary t => Get t
get
Word16
left16 <- Get Word16
getWord16be
ByteString
mpib <- Get ByteString
getRemainingLazyByteString
case Get [MPI]
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, [MPI])
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Get MPI -> Get [MPI]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Get MPI
getMPI) ByteString
mpib of
Left (ByteString
_, Int64
_, String
e) -> String -> Get SignaturePayload
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"v3 sig MPIs " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
e)
Right (ByteString
_, Int64
_, [MPI]
mpis) ->
SignaturePayload -> Get SignaturePayload
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SignaturePayload -> Get SignaturePayload)
-> SignaturePayload -> Get SignaturePayload
forall a b. (a -> b) -> a -> b
$
SigType
-> ThirtyTwoBitTimeStamp
-> EightOctetKeyId
-> PubKeyAlgorithm
-> HashAlgorithm
-> Word16
-> NonEmpty MPI
-> SignaturePayload
SigV3
(Word8 -> SigType
forall a. FutureVal a => Word8 -> a
toFVal Word8
st)
ThirtyTwoBitTimeStamp
ctime
(ByteString -> EightOctetKeyId
EightOctetKeyId ByteString
eok)
(Word8 -> PubKeyAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
pka)
(Word8 -> HashAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
ha)
Word16
left16
([MPI] -> NonEmpty MPI
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [MPI]
mpis)
Word8
4 -> do
Word8
st <- Get Word8
getWord8
Word8
pka <- Get Word8
forall t. Binary t => Get t
get
Word8
ha <- Get Word8
forall t. Binary t => Get t
get
Word16
hlen <- Get Word16
getWord16be
ByteString
hb <- Int64 -> Get ByteString
getLazyByteString (Word16 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
hlen)
let hashed :: [SigSubPacket]
hashed =
case Get [SigSubPacket]
-> ByteString
-> Either
(ByteString, Int64, String) (ByteString, Int64, [SigSubPacket])
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Get SigSubPacket -> Get [SigSubPacket]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Get SigSubPacket
getSigSubPacket) ByteString
hb of
Left (ByteString
_, Int64
_, String
err) -> String -> [SigSubPacket]
forall a. String -> [a]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"v4 sig hasheds " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err)
Right (ByteString
_, Int64
_, [SigSubPacket]
h) -> [SigSubPacket]
h
Word16
ulen <- Get Word16
getWord16be
ByteString
ub <- Int64 -> Get ByteString
getLazyByteString (Word16 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
ulen)
let unhashed :: [SigSubPacket]
unhashed =
case Get [SigSubPacket]
-> ByteString
-> Either
(ByteString, Int64, String) (ByteString, Int64, [SigSubPacket])
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Get SigSubPacket -> Get [SigSubPacket]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Get SigSubPacket
getSigSubPacket) ByteString
ub of
Left (ByteString
_, Int64
_, String
err) -> String -> [SigSubPacket]
forall a. String -> [a]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"v4 sig unhasheds " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err)
Right (ByteString
_, Int64
_, [SigSubPacket]
u) -> [SigSubPacket]
u
Word16
left16 <- Get Word16
getWord16be
ByteString
mpib <- Get ByteString
getRemainingLazyByteString
case Get [MPI]
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, [MPI])
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Get MPI -> Get [MPI]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Get MPI
getMPI) ByteString
mpib of
Left (ByteString
_, Int64
_, String
e) -> String -> Get SignaturePayload
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"v4 sig MPIs " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
e)
Right (ByteString
_, Int64
_, [MPI]
mpis) ->
SignaturePayload -> Get SignaturePayload
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SignaturePayload -> Get SignaturePayload)
-> SignaturePayload -> Get SignaturePayload
forall a b. (a -> b) -> a -> b
$
SigType
-> PubKeyAlgorithm
-> HashAlgorithm
-> [SigSubPacket]
-> [SigSubPacket]
-> Word16
-> NonEmpty MPI
-> SignaturePayload
SigV4
(Word8 -> SigType
forall a. FutureVal a => Word8 -> a
toFVal Word8
st)
(Word8 -> PubKeyAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
pka)
(Word8 -> HashAlgorithm
forall a. FutureVal a => Word8 -> a
toFVal Word8
ha)
[SigSubPacket]
hashed
[SigSubPacket]
unhashed
Word16
left16
([MPI] -> NonEmpty MPI
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [MPI]
mpis)
Word8
_ -> do
ByteString
bs <- Get ByteString
getRemainingLazyByteString
SignaturePayload -> Get SignaturePayload
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (SignaturePayload -> Get SignaturePayload)
-> SignaturePayload -> Get SignaturePayload
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString -> SignaturePayload
SigVOther Word8
pv ByteString
bs
putSignaturePayload :: SignaturePayload -> Put
putSignaturePayload :: SignaturePayload -> Put
putSignaturePayload (SigV3 SigType
st ThirtyTwoBitTimeStamp
ctime EightOctetKeyId
eok PubKeyAlgorithm
pka HashAlgorithm
ha Word16
left16 NonEmpty MPI
mpis) = do
Word8 -> Put
putWord8 Word8
3
Word8 -> Put
putWord8 Word8
5
SigType -> Put
forall t. Binary t => t -> Put
put SigType
st
Word32 -> Put
putWord32be (Word32 -> Put)
-> (ThirtyTwoBitTimeStamp -> Word32)
-> ThirtyTwoBitTimeStamp
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThirtyTwoBitTimeStamp -> Word32
unThirtyTwoBitTimeStamp (ThirtyTwoBitTimeStamp -> Put) -> ThirtyTwoBitTimeStamp -> Put
forall a b. (a -> b) -> a -> b
$ ThirtyTwoBitTimeStamp
ctime
ByteString -> Put
putLazyByteString (EightOctetKeyId -> ByteString
unEOKI EightOctetKeyId
eok)
PubKeyAlgorithm -> Put
forall t. Binary t => t -> Put
put PubKeyAlgorithm
pka
HashAlgorithm -> Put
forall t. Binary t => t -> Put
put HashAlgorithm
ha
Word16 -> Put
putWord16be Word16
left16
(MPI -> Put) -> NonEmpty MPI -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
F.mapM_ MPI -> Put
forall t. Binary t => t -> Put
put NonEmpty MPI
mpis
putSignaturePayload (SigV4 SigType
st PubKeyAlgorithm
pka HashAlgorithm
ha [SigSubPacket]
hashed [SigSubPacket]
unhashed Word16
left16 NonEmpty MPI
mpis) = do
Word8 -> Put
putWord8 Word8
4
SigType -> Put
forall t. Binary t => t -> Put
put SigType
st
PubKeyAlgorithm -> Put
forall t. Binary t => t -> Put
put PubKeyAlgorithm
pka
HashAlgorithm -> Put
forall t. Binary t => t -> Put
put HashAlgorithm
ha
let hb :: ByteString
hb = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ (SigSubPacket -> Put) -> [SigSubPacket] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ SigSubPacket -> Put
forall t. Binary t => t -> Put
put [SigSubPacket]
hashed
Word16 -> Put
putWord16be (Word16 -> Put) -> (ByteString -> Word16) -> ByteString -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word16) -> (ByteString -> Int64) -> ByteString -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
BL.length (ByteString -> Put) -> ByteString -> Put
forall a b. (a -> b) -> a -> b
$ ByteString
hb
ByteString -> Put
putLazyByteString ByteString
hb
let ub :: ByteString
ub = Put -> ByteString
runPut (Put -> ByteString) -> Put -> ByteString
forall a b. (a -> b) -> a -> b
$ (SigSubPacket -> Put) -> [SigSubPacket] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ SigSubPacket -> Put
forall t. Binary t => t -> Put
put [SigSubPacket]
unhashed
Word16 -> Put
putWord16be (Word16 -> Put) -> (ByteString -> Word16) -> ByteString -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word16) -> (ByteString -> Int64) -> ByteString -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
BL.length (ByteString -> Put) -> ByteString -> Put
forall a b. (a -> b) -> a -> b
$ ByteString
ub
ByteString -> Put
putLazyByteString ByteString
ub
Word16 -> Put
putWord16be Word16
left16
(MPI -> Put) -> NonEmpty MPI -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
F.mapM_ MPI -> Put
forall t. Binary t => t -> Put
put NonEmpty MPI
mpis
putSignaturePayload (SigVOther Word8
pv ByteString
bs) = do
Word8 -> Put
putWord8 Word8
pv
ByteString -> Put
putLazyByteString ByteString
bs
putTK :: TK -> Put
putTK :: TK -> Put
putTK TK
key = do
let pkp :: PKPayload
pkp = TK
key TK -> Getting PKPayload TK PKPayload -> PKPayload
forall s a. s -> Getting a s a -> a
^. ((PKPayload, Maybe SKAddendum)
-> Const PKPayload (PKPayload, Maybe SKAddendum))
-> TK -> Const PKPayload TK
Lens' TK (PKPayload, Maybe SKAddendum)
tkKey (((PKPayload, Maybe SKAddendum)
-> Const PKPayload (PKPayload, Maybe SKAddendum))
-> TK -> Const PKPayload TK)
-> ((PKPayload -> Const PKPayload PKPayload)
-> (PKPayload, Maybe SKAddendum)
-> Const PKPayload (PKPayload, Maybe SKAddendum))
-> Getting PKPayload TK PKPayload
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PKPayload -> Const PKPayload PKPayload)
-> (PKPayload, Maybe SKAddendum)
-> Const PKPayload (PKPayload, Maybe SKAddendum)
forall s t a b. Field1 s t a b => Lens s t a b
Lens
(PKPayload, Maybe SKAddendum)
(PKPayload, Maybe SKAddendum)
PKPayload
PKPayload
_1
Put -> (SKAddendum -> Put) -> Maybe SKAddendum -> Put
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
(PublicKey -> Put
forall t. Binary t => t -> Put
put (PKPayload -> PublicKey
PublicKey PKPayload
pkp))
(\SKAddendum
ska -> SecretKey -> Put
forall t. Binary t => t -> Put
put (PKPayload -> SKAddendum -> SecretKey
SecretKey PKPayload
pkp SKAddendum
ska))
((PKPayload, Maybe SKAddendum) -> Maybe SKAddendum
forall a b. (a, b) -> b
snd (TK
key TK
-> Getting
(PKPayload, Maybe SKAddendum) TK (PKPayload, Maybe SKAddendum)
-> (PKPayload, Maybe SKAddendum)
forall s a. s -> Getting a s a -> a
^. Getting
(PKPayload, Maybe SKAddendum) TK (PKPayload, Maybe SKAddendum)
Lens' TK (PKPayload, Maybe SKAddendum)
tkKey))
(SignaturePayload -> Put) -> [SignaturePayload] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Signature -> Put
forall t. Binary t => t -> Put
put (Signature -> Put)
-> (SignaturePayload -> Signature) -> SignaturePayload -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SignaturePayload -> Signature
Signature) (TK -> [SignaturePayload]
_tkRevs TK
key)
((Text, [SignaturePayload]) -> Put)
-> [(Text, [SignaturePayload])] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Text, [SignaturePayload]) -> Put
forall {t :: * -> *}.
Foldable t =>
(Text, t SignaturePayload) -> Put
putUid' (TK -> [(Text, [SignaturePayload])]
_tkUIDs TK
key)
(([UserAttrSubPacket], [SignaturePayload]) -> Put)
-> [([UserAttrSubPacket], [SignaturePayload])] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ([UserAttrSubPacket], [SignaturePayload]) -> Put
forall {t :: * -> *}.
Foldable t =>
([UserAttrSubPacket], t SignaturePayload) -> Put
putUat' (TK -> [([UserAttrSubPacket], [SignaturePayload])]
_tkUAts TK
key)
((Pkt, [SignaturePayload]) -> Put)
-> [(Pkt, [SignaturePayload])] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Pkt, [SignaturePayload]) -> Put
forall {t} {t :: * -> *}.
(Binary t, Foldable t) =>
(t, t SignaturePayload) -> Put
putSub' (TK -> [(Pkt, [SignaturePayload])]
_tkSubs TK
key)
where
putUid' :: (Text, t SignaturePayload) -> Put
putUid' (Text
u, t SignaturePayload
sps) = UserId -> Put
forall t. Binary t => t -> Put
put (Text -> UserId
UserId Text
u) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SignaturePayload -> Put) -> t SignaturePayload -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Signature -> Put
forall t. Binary t => t -> Put
put (Signature -> Put)
-> (SignaturePayload -> Signature) -> SignaturePayload -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SignaturePayload -> Signature
Signature) t SignaturePayload
sps
putUat' :: ([UserAttrSubPacket], t SignaturePayload) -> Put
putUat' ([UserAttrSubPacket]
us, t SignaturePayload
sps) = UserAttribute -> Put
forall t. Binary t => t -> Put
put ([UserAttrSubPacket] -> UserAttribute
UserAttribute [UserAttrSubPacket]
us) Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SignaturePayload -> Put) -> t SignaturePayload -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Signature -> Put
forall t. Binary t => t -> Put
put (Signature -> Put)
-> (SignaturePayload -> Signature) -> SignaturePayload -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SignaturePayload -> Signature
Signature) t SignaturePayload
sps
putSub' :: (t, t SignaturePayload) -> Put
putSub' (t
p, t SignaturePayload
sps) = t -> Put
forall t. Binary t => t -> Put
put t
p Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (SignaturePayload -> Put) -> t SignaturePayload -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Signature -> Put
forall t. Binary t => t -> Put
put (Signature -> Put)
-> (SignaturePayload -> Signature) -> SignaturePayload -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SignaturePayload -> Signature
Signature) t SignaturePayload
sps
parsePkts :: ByteString -> [Pkt]
parsePkts :: ByteString -> [Pkt]
parsePkts ByteString
lbs =
case Get [Pkt]
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, [Pkt])
forall a.
Get a
-> ByteString
-> Either (ByteString, Int64, String) (ByteString, Int64, a)
runGetOrFail (Get Pkt -> Get [Pkt]
forall a. Get a -> Get [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Get Pkt
getPkt) ByteString
lbs of
Left (ByteString
_, Int64
_, String
e) -> []
Right (ByteString
_, Int64
_, [Pkt]
p) -> [Pkt]
p