cardano-crypto-class-2.2.0.0: Type classes abstracting over cryptography primitives for Cardano
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Crypto.DirectSerialise

Description

Direct (de-)serialisation to / from raw memory.

The purpose of the typeclasses in this module is to abstract over data structures that can expose the data they store as one or more raw Ptrs, without any additional memory copying or conversion to intermediate data structures.

This is useful for transmitting data like KES SignKeys over a socket connection: by accessing the memory directly and copying it into or out of a file descriptor, without going through an intermediate ByteString representation (or other data structure that resides in the GHC heap), we can more easily assure that the data is never written to disk, including swap, which is an important requirement for KES.

Synopsis

Documentation

sizeCheckFailedIntInt → m () Source #

class DirectDeserialise a where Source #

Direct deserialization from raw memory.

directDeserialise f should allocate a new value of type a, and call f with a pointer to the raw memory to be filled. f may be called multiple times, for data structures that store their data in multiple non-contiguous blocks of memory.

The order in which memory blocks are visited matters.

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m a Source #

Instances

Instances details
DirectDeserialise (SignKeyDSIGNM Ed25519DSIGN) Source # 
Instance details

Defined in Cardano.Crypto.DSIGN.Ed25519

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (SignKeyDSIGNM Ed25519DSIGN) Source #

DirectDeserialise (VerKeyDSIGN Ed25519DSIGN) Source # 
Instance details

Defined in Cardano.Crypto.DSIGN.Ed25519

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (VerKeyDSIGN Ed25519DSIGN) Source #

DirectDeserialise (SignKeyDSIGNM d) ⇒ DirectDeserialise (SignKeyKES (CompactSingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (SignKeyKES (CompactSingleKES d)) Source #

(DirectDeserialise (SignKeyKES d), DirectDeserialise (VerKeyKES d), KESAlgorithm d) ⇒ DirectDeserialise (SignKeyKES (CompactSumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSum

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (SignKeyKES (CompactSumKES h d)) Source #

KnownNat t ⇒ DirectDeserialise (SignKeyKES (MockKES t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Mock

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (SignKeyKES (MockKES t)) Source #

(DirectDeserialise (SignKeyDSIGNM d), KnownNat t) ⇒ DirectDeserialise (SignKeyKES (SimpleKES d t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Simple

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (SignKeyKES (SimpleKES d t)) Source #

DirectDeserialise (SignKeyDSIGNM d) ⇒ DirectDeserialise (SignKeyKES (SingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Single

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (SignKeyKES (SingleKES d)) Source #

(DirectDeserialise (SignKeyKES d), DirectDeserialise (VerKeyKES d), KESAlgorithm d) ⇒ DirectDeserialise (SignKeyKES (SumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Sum

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (SignKeyKES (SumKES h d)) Source #

DirectDeserialise (VerKeyDSIGN d) ⇒ DirectDeserialise (VerKeyKES (CompactSingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (VerKeyKES (CompactSingleKES d)) Source #

HashAlgorithm h ⇒ DirectDeserialise (VerKeyKES (CompactSumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSum

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (VerKeyKES (CompactSumKES h d)) Source #

KnownNat t ⇒ DirectDeserialise (VerKeyKES (MockKES t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Mock

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (VerKeyKES (MockKES t)) Source #

(DirectDeserialise (VerKeyDSIGN d), KnownNat t) ⇒ DirectDeserialise (VerKeyKES (SimpleKES d t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Simple

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (VerKeyKES (SimpleKES d t)) Source #

DirectDeserialise (VerKeyDSIGN d) ⇒ DirectDeserialise (VerKeyKES (SingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Single

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (VerKeyKES (SingleKES d)) Source #

HashAlgorithm h ⇒ DirectDeserialise (VerKeyKES (SumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Sum

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (VerKeyKES (SumKES h d)) Source #

KnownNat n ⇒ DirectDeserialise (MLockedSeed n) Source # 
Instance details

Defined in Cardano.Crypto.Libsodium.MLockedSeed

Methods

directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → m (MLockedSeed n) Source #

class DirectSerialise a where Source #

Direct serialization to raw memory.

directSerialise f x should call f to expose the raw memory underyling x. For data types that store their data in multiple non-contiguous blocks of memory, f may be called multiple times, once for each block.

The order in which memory blocks are visited matters.

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → a → m () Source #

Instances

Instances details
DirectSerialise (SignKeyDSIGNM Ed25519DSIGN) Source # 
Instance details

Defined in Cardano.Crypto.DSIGN.Ed25519

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → SignKeyDSIGNM Ed25519DSIGN → m () Source #

DirectSerialise (VerKeyDSIGN Ed25519DSIGN) Source # 
Instance details

Defined in Cardano.Crypto.DSIGN.Ed25519

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → VerKeyDSIGN Ed25519DSIGN → m () Source #

DirectSerialise (SignKeyDSIGNM d) ⇒ DirectSerialise (SignKeyKES (CompactSingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → SignKeyKES (CompactSingleKES d) → m () Source #

(DirectSerialise (SignKeyKES d), DirectSerialise (VerKeyKES d), KESAlgorithm d) ⇒ DirectSerialise (SignKeyKES (CompactSumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSum

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → SignKeyKES (CompactSumKES h d) → m () Source #

KnownNat t ⇒ DirectSerialise (SignKeyKES (MockKES t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Mock

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → SignKeyKES (MockKES t) → m () Source #

DirectSerialise (SignKeyDSIGNM d) ⇒ DirectSerialise (SignKeyKES (SimpleKES d t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Simple

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → SignKeyKES (SimpleKES d t) → m () Source #

DirectSerialise (SignKeyDSIGNM d) ⇒ DirectSerialise (SignKeyKES (SingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Single

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → SignKeyKES (SingleKES d) → m () Source #

(DirectSerialise (SignKeyKES d), DirectSerialise (VerKeyKES d), KESAlgorithm d) ⇒ DirectSerialise (SignKeyKES (SumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Sum

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → SignKeyKES (SumKES h d) → m () Source #

DirectSerialise (VerKeyDSIGN d) ⇒ DirectSerialise (VerKeyKES (CompactSingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → VerKeyKES (CompactSingleKES d) → m () Source #

DirectSerialise (VerKeyKES (CompactSumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.CompactSum

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → VerKeyKES (CompactSumKES h d) → m () Source #

KnownNat t ⇒ DirectSerialise (VerKeyKES (MockKES t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Mock

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → VerKeyKES (MockKES t) → m () Source #

DirectSerialise (VerKeyDSIGN d) ⇒ DirectSerialise (VerKeyKES (SimpleKES d t)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Simple

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → VerKeyKES (SimpleKES d t) → m () Source #

DirectSerialise (VerKeyDSIGN d) ⇒ DirectSerialise (VerKeyKES (SingleKES d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Single

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → VerKeyKES (SingleKES d) → m () Source #

DirectSerialise (VerKeyKES (SumKES h d)) Source # 
Instance details

Defined in Cardano.Crypto.KES.Sum

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → VerKeyKES (SumKES h d) → m () Source #

KnownNat n ⇒ DirectSerialise (MLockedSeed n) Source # 
Instance details

Defined in Cardano.Crypto.Libsodium.MLockedSeed

Methods

directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CCharCSize → m ()) → MLockedSeed n → m () Source #

directSerialiseTo ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (IntPtr CCharCSize → m ()) → Int → a → m Int Source #

Helper function for bounds-checked serialization. Verifies that no more than the maximum number of bytes are written, and returns the actual number of bytes written.

directSerialiseToChecked ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (IntPtr CCharCSize → m ()) → Int → a → m () Source #

Helper function for size-checked serialization. Verifies that exactly the specified number of bytes are written.

directSerialiseBuf ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CCharInt → a → m Int Source #

Helper function for the common use case of serializing to an in-memory buffer. Verifies that no more than the maximum number of bytes are written, and returns the actual number of bytes written.

directSerialiseBufChecked ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CCharInt → a → m () Source #

Helper function for size-checked serialization to an in-memory buffer. Verifies that exactly the specified number of bytes are written.

directDeserialiseFrom ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (IntPtr CCharCSize → m ()) → Int → m (a, Int) Source #

Helper function for size-checked deserialization. Verifies that no more than the maximum number of bytes are read, and returns the actual number of bytes read.

directDeserialiseFromChecked ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (IntPtr CCharCSize → m ()) → Int → m a Source #

Helper function for size-checked deserialization. Verifies that exactly the specified number of bytes are read.

directDeserialiseBuf ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CCharInt → m (a, Int) Source #

Helper function for the common use case of deserializing from an in-memory buffer. Verifies that no more than the maximum number of bytes are read, and returns the actual number of bytes read.

directDeserialiseBufChecked ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CCharInt → m a Source #

Helper function for size-checked deserialization from an in-memory buffer. Verifies that exactly the specified number of bytes are read.