[Internal] Add a function to create a initialized to 0 bytearray
This commit is contained in:
parent
09365a745f
commit
38b7f6ad73
@ -16,6 +16,7 @@ module Crypto.Internal.ByteArray
|
|||||||
, byteArrayAlloc
|
, byteArrayAlloc
|
||||||
, byteArrayAllocAndFreeze
|
, byteArrayAllocAndFreeze
|
||||||
, empty
|
, empty
|
||||||
|
, byteArrayZero
|
||||||
, byteArrayCopy
|
, byteArrayCopy
|
||||||
, byteArrayCopyRet
|
, byteArrayCopyRet
|
||||||
, byteArrayCopyAndFreeze
|
, byteArrayCopyAndFreeze
|
||||||
@ -39,7 +40,7 @@ import Data.SecureMem
|
|||||||
import Crypto.Internal.Memory
|
import Crypto.Internal.Memory
|
||||||
import Crypto.Internal.Compat
|
import Crypto.Internal.Compat
|
||||||
import Crypto.Internal.Endian
|
import Crypto.Internal.Endian
|
||||||
import Crypto.Internal.Bytes (bufXor, bufCopy)
|
import Crypto.Internal.Bytes (bufXor, bufCopy, bufSet)
|
||||||
import Crypto.Internal.Words
|
import Crypto.Internal.Words
|
||||||
import Foreign.Ptr
|
import Foreign.Ptr
|
||||||
import Foreign.Storable
|
import Foreign.Storable
|
||||||
@ -147,6 +148,9 @@ byteArrayCopyAndFreeze bs f =
|
|||||||
withByteArray bs $ \s -> bufCopy d s (byteArrayLength bs)
|
withByteArray bs $ \s -> bufCopy d s (byteArrayLength bs)
|
||||||
f (castPtr d)
|
f (castPtr d)
|
||||||
|
|
||||||
|
byteArrayZero :: ByteArray ba => Int -> ba
|
||||||
|
byteArrayZero n = byteArrayAllocAndFreeze n $ \ptr -> bufSet ptr 0 n
|
||||||
|
|
||||||
byteArrayEq :: (ByteArrayAccess bs1, ByteArrayAccess bs2) => bs1 -> bs2 -> Bool
|
byteArrayEq :: (ByteArrayAccess bs1, ByteArrayAccess bs2) => bs1 -> bs2 -> Bool
|
||||||
byteArrayEq b1 b2
|
byteArrayEq b1 b2
|
||||||
| l1 /= l2 = False
|
| l1 /= l2 = False
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user