cardano-crypto-class-2.0.0: Type classes abstracting over cryptography primitives for Cardano
Safe HaskellNone
LanguageHaskell2010

Cardano.Crypto.PinnedSizedBytes

Synopsis

Documentation

data PinnedSizedBytes (n :: Nat) Source #

n bytes. Storable.

We have two *Bytes types:

  • PinnedSizedBytes is backed by pinned ByteArray.
  • MLockedSizedBytes is backed by ForeignPtr to mlock-ed memory region.

The ByteString is pinned datatype, but it's represented by ForeignPtr + offset (and size).

I'm sorry for adding more types for bytes. :(

Instances

Instances details
KnownNat n => Eq (PinnedSizedBytes n) Source #

The comparison is done in constant time for a given size n.

Instance details

Defined in Cardano.Crypto.PinnedSizedBytes

KnownNat n => Ord (PinnedSizedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PinnedSizedBytes

Show (PinnedSizedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PinnedSizedBytes

KnownNat n => IsString (PinnedSizedBytes n) Source #

If given String is too long, it is truncated, If it is too short, it is padded with zeros.

Padding and truncation make it behave like an integer mod n*8.

>>> "abcdef" :: PinnedSizedBytes 4
"63646566"
>>> "foo" :: PinnedSizedBytes 8
"0000000000666f6f"

Non-ASCII codepoints are silently truncated to 0..255 range.

>>> "\x1234\x5678" :: PinnedSizedBytes 2
"3478"

PinnedSizedBytes created with fromString contains unpinned ByteArray.

Instance details

Defined in Cardano.Crypto.PinnedSizedBytes

KnownNat n => Storable (PinnedSizedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PinnedSizedBytes

NFData (PinnedSizedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PinnedSizedBytes

Methods

rnf :: PinnedSizedBytes n -> () #

NoThunks (PinnedSizedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PinnedSizedBytes

Initialization

Conversions

psbFromBytes :: forall n. KnownNat n => [Word8] -> PinnedSizedBytes n Source #

See IsString (PinnedSizedBytes n) instance.

>>> psbToBytes . (id @(PinnedSizedBytes 4)) . psbFromBytes $ [1,2,3,4]
[1,2,3,4]
>>> psbToBytes . (id @(PinnedSizedBytes 4)) . psbFromBytes $ [1,2]
[0,0,1,2]
>>> psbToBytes . (id @(PinnedSizedBytes 4)) . psbFromBytes $ [1,2,3,4,5,6]
[3,4,5,6]

C usage

psbCreate :: forall n. KnownNat n => (Ptr Word8 -> IO ()) -> IO (PinnedSizedBytes n) Source #

psbCreateSized :: forall n. KnownNat n => (SizedPtr n -> IO ()) -> IO (PinnedSizedBytes n) Source #