Skip to content

Commit 73f7f1f

Browse files
committed
Add psbFromByteStringM and psbToByteArray to PinnedSizedBytes
These were introduced in a newer commit that the wallet-cbits branch depends on but is not yet present in the tagged base this branch is rebased onto.
1 parent 58a3814 commit 73f7f1f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

cardano-crypto-class/src/Cardano/Crypto/PinnedSizedBytes.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ module Cardano.Crypto.PinnedSizedBytes (
2222
psbToBytes,
2323
psbFromByteString,
2424
psbFromByteStringCheck,
25+
psbFromByteStringM,
2526
psbToByteString,
27+
psbToByteArray,
2628

2729
-- * C usage
2830
psbUseAsCPtr,
@@ -238,6 +240,14 @@ psbFromByteStringCheck bs
238240
size :: Int
239241
size = fromInteger (natVal (Proxy :: Proxy n))
240242

243+
psbFromByteStringM :: (KnownNat n, MonadFail f) => BS.ByteString -> f (PinnedSizedBytes n)
244+
psbFromByteStringM bs = case psbFromByteStringCheck bs of
245+
Just psb -> pure psb
246+
Nothing -> fail $ "psbFromByteStringM: size mismatch, expected " ++ show (BS.length bs) ++ " bytes"
247+
248+
psbToByteArray :: PinnedSizedBytes n -> ByteArray
249+
psbToByteArray (PSB ba) = ba
250+
241251
{-# DEPRECATED psbZero "This is not referentially transparent" #-}
242252
psbZero :: KnownNat n => PinnedSizedBytes n
243253
psbZero = psbFromBytes []

0 commit comments

Comments
 (0)