Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cardano-crypto-class/src/Cardano/Crypto/PinnedSizedBytes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ module Cardano.Crypto.PinnedSizedBytes (
psbToBytes,
psbFromByteString,
psbFromByteStringCheck,
psbFromByteStringM,
psbToByteString,
psbToByteArray,

-- * C usage
psbUseAsCPtr,
Expand Down Expand Up @@ -238,6 +240,14 @@ psbFromByteStringCheck bs
size :: Int
size = fromInteger (natVal (Proxy :: Proxy n))

psbFromByteStringM :: (KnownNat n, MonadFail f) => BS.ByteString -> f (PinnedSizedBytes n)
psbFromByteStringM bs = case psbFromByteStringCheck bs of
Just psb -> pure psb
Nothing -> fail $ "psbFromByteStringM: size mismatch, expected " ++ show (BS.length bs) ++ " bytes"

psbToByteArray :: PinnedSizedBytes n -> ByteArray
psbToByteArray (PSB ba) = ba

{-# DEPRECATED psbZero "This is not referentially transparent" #-}
psbZero :: KnownNat n => PinnedSizedBytes n
psbZero = psbFromBytes []
Expand Down