hOpenPGP-3.0.1.1: native Haskell implementation of OpenPGP (RFC9580)
Safe HaskellNone
LanguageHaskell2010

Codec.Encryption.OpenPGP.Subpackets

Synopsis

Safe subpacket construction

mkSafeSubpacket :: Bool -> SigSubPacketPayload -> Either String SafeSubpacket Source #

Create a safe subpacket from a payload and criticality flag Basic validation that the payload is well-formed

safePayload :: SafeSubpacket -> SigSubPacketPayload Source #

Extract the payload from a safe subpacket

safeSubpacket :: SafeSubpacket -> SigSubPacket Source #

Extract the underlying SigSubPacket from a safe subpacket

Critical subpacket handling

mkCritical :: SigSubPacketPayload -> Either String CriticalSubpacket Source #

Create a critical subpacket only if the payload type allows it RFC9580 section 5.2.3.5: only certain subpacket types can be marked critical

canBeCritical :: SigSubPacketPayload -> Bool Source #

RFC9580 §5.2.3.5 lists which subpacket types can be marked critical

Text normalization mode

data TextNormalizationMode Source #

Controls how text payload is normalized for CanonicalTextSig.

RFC 9580 §5.2.1.2 requires only CRLF normalization for type 0x01 signatures. Trailing-whitespace stripping is only mandated by §7 (Cleartext Signature Framework). Use CleartextCompat for GnuPG-compatible behaviour when producing cleartext-armored signatures; use RFC9580Strict for inline text signatures.

Constructors

RFC9580Strict

CRLF normalization only; no trailing-whitespace stripping. Correct for inline type 0x01 document signatures.

CleartextCompat

CRLF normalization *plus* per-line trailing-whitespace stripping. Required by the Cleartext Signature Framework (RFC 9580 §7).

Builder API for signature composition

data SigBuilder hashedness v (algo :: PubKeyAlgorithm) Source #

Staged signature builder that enforces completion order

Usage pattern: builder <- sigBuilderInit SigTypeBinary RSA SHA256 builder' <- addHashedSubs hashedList builder finalPayload <- buildSigV4 sigMPIs (addUnhashedSubs unhashedList builder')

data LegalSubpacket h v where Source #

Legal subpackets encoded by placement and signature-version constraints. This expands compile-time legality beyond bare hashed/unhashed staging.

sbSigType :: SigBuilder hashedness v algo -> SigType Source #

sbPubKeyAlgo :: forall hashedness v (algo :: PubKeyAlgorithm). KnownPubKeyAlgorithm algo => SigBuilder hashedness v algo -> PubKeyAlgorithm Source #

sbHashAlgo :: SigBuilder hashedness v algo -> HashAlgorithm Source #

sbHashedSubs :: SigBuilder hashedness v algo -> [SigSubPacket] Source #

sbUnhashedSubs :: SigBuilder hashedness v algo -> [SigSubPacket] Source #

sbSalt :: SigBuilder hashedness v algo -> BuilderSalt v Source #

sbTextNormMode :: SigBuilder hashedness v algo -> TextNormalizationMode Source #

Normalization mode for CanonicalTextSig payloads. Defaults to CleartextCompat for backward compatibility.

buildSigV4 :: forall (algo :: PubKeyAlgorithm). KnownPubKeyAlgorithm algo => SigBuilder Unhashed V4Sig algo -> Word16 -> NonEmpty MPI -> SignaturePayload Source #

Build a v4 signature from a completed builder and MPI values

buildSigV6 :: forall (algo :: PubKeyAlgorithm). KnownPubKeyAlgorithm algo => SigBuilder Unhashed V6Sig algo -> Word16 -> NonEmpty MPI -> SignaturePayload Source #

Build a v6 signature from a completed builder and MPI values

sigBuilderInit :: forall (algo :: PubKeyAlgorithm). KnownPubKeyAlgorithm algo => SigType -> HashAlgorithm -> SigBuilder Hashed V4Sig algo Source #

Initialize a builder for a v4 signature Starts with no subpackets and must call addHashedSubs and addUnhashedSubs

sigBuilderInitTyped :: forall (algo :: PubKeyAlgorithm) (rfc :: OpenPGPRFC) (h :: HashAlgorithm). (KnownPubKeyAlgorithm algo, HashAlgoAllowedFor rfc h) => OpenPGPRFCW rfc -> SigType -> HashAlgorithmW h -> SigBuilder Hashed V4Sig algo Source #

Initialize a builder for a v4 signature with compile-time RFC/hash policy enforcement.

sigBuilderInitRuntime :: forall (algo :: PubKeyAlgorithm). KnownPubKeyAlgorithm algo => OpenPGPRFC -> SigType -> HashAlgorithm -> Either String (SigBuilder Hashed V4Sig algo) Source #

Initialize a v4 builder from runtime RFC/hash inputs with policy validation and witness promotion at the API boundary.

sigBuilderInitV6 :: forall (algo :: PubKeyAlgorithm). KnownPubKeyAlgorithm algo => SigType -> HashAlgorithm -> SignatureSalt -> SigBuilder Hashed V6Sig algo Source #

Initialize a builder for a v6 signature

sigBuilderInitV6Typed :: forall (algo :: PubKeyAlgorithm) (rfc :: OpenPGPRFC) (h :: HashAlgorithm). (KnownPubKeyAlgorithm algo, HashAlgoAllowedFor rfc h) => OpenPGPRFCW rfc -> SigType -> HashAlgorithmW h -> SignatureSalt -> SigBuilder Hashed V6Sig algo Source #

Initialize a builder for a v6 signature with compile-time RFC/hash policy enforcement.

sigBuilderInitV6Runtime :: forall (algo :: PubKeyAlgorithm). KnownPubKeyAlgorithm algo => OpenPGPRFC -> SigType -> HashAlgorithm -> SignatureSalt -> Either String (SigBuilder Hashed V6Sig algo) Source #

Initialize a v6 builder from runtime RFC/hash inputs with policy validation and witness promotion at the API boundary.

addHashedSubs :: forall v (algo :: PubKeyAlgorithm). HashedSubpackets v -> SigBuilder Hashed v algo -> SigBuilder Unhashed v algo Source #

Add hashed subpackets to a builder Must be called before addUnhashedSubs

addUnhashedSubs :: forall v (algo :: PubKeyAlgorithm). UnhashedSubpackets v -> SigBuilder Unhashed v algo -> SigBuilder Unhashed v algo Source #

Add unhashed subpackets to a builder Must be called after addHashedSubs

Private key wrapper (algorithm-specific)

data PrivateKeyFor (algo :: PubKeyAlgorithm) where Source #

Wrapper GADT for algorithm-specific private keys Encodes the algorithm at the type level to ensure type-safe key/builder matching

Subpacket list utilities

type HashedSubpackets v = SubpacketList Hashed v Source #

Type alias for readability: hashed subpacket list

type UnhashedSubpackets v = SubpacketList Unhashed v Source #

Type alias for readability: unhashed subpacket list

consHashedSub :: SigSubPacket -> HashedSubpackets v -> HashedSubpackets v Source #

Prepend a subpacket to a hashed subpacket list

singleHashedSub :: SigSubPacket -> HashedSubpackets v Source #

Construct a single hashed subpacket into a hashed subpacket list

singleUnhashedSub :: SigSubPacket -> UnhashedSubpackets v Source #

Construct a single unhashed subpacket into an unhashed subpacket list

listToHashedSubs :: [SigSubPacket] -> HashedSubpackets v Source #

Convert a list to a hashed subpacket list Used to bridge between list-based and phantom-typed APIs

listToUnhashedSubs :: [SigSubPacket] -> UnhashedSubpackets v Source #

Convert a list to an unhashed subpacket list Used to bridge between list-based and phantom-typed APIs