-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Direct serialisation from/to raw memory - SignKeyWithPeriodKES wrapper
- Loading branch information
Showing
9 changed files
with
255 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
cardano-crypto-class/src/Cardano/Crypto/DirectSerialise.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- | 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 'Ptr's, | ||
-- 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. | ||
module Cardano.Crypto.DirectSerialise | ||
where | ||
|
||
import Foreign.Ptr | ||
import Foreign.C.Types | ||
|
||
-- | 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. | ||
class DirectDeserialise a where | ||
directDeserialise :: (Ptr CChar -> CSize -> IO ()) -> IO a | ||
|
||
-- | 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. | ||
class DirectSerialise a where | ||
directSerialise :: (Ptr CChar -> CSize -> IO ()) -> a -> IO () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters