[Internal] add a function to convert bytearray and apply a hexadecimal transformation
This commit is contained in:
parent
a3b444e36f
commit
12ddffe4df
@ -27,6 +27,7 @@ module Crypto.Internal.ByteArray
|
|||||||
, copy
|
, copy
|
||||||
, take
|
, take
|
||||||
, convert
|
, convert
|
||||||
|
, convertHex
|
||||||
, copyRet
|
, copyRet
|
||||||
, copyAndFreeze
|
, copyAndFreeze
|
||||||
, split
|
, split
|
||||||
@ -48,6 +49,7 @@ 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, bufSet)
|
import Crypto.Internal.Bytes (bufXor, bufCopy, bufSet)
|
||||||
|
import Crypto.Internal.Hex
|
||||||
import Crypto.Internal.Words
|
import Crypto.Internal.Words
|
||||||
import Crypto.Internal.Imports hiding (empty)
|
import Crypto.Internal.Imports hiding (empty)
|
||||||
import Foreign.Ptr
|
import Foreign.Ptr
|
||||||
@ -57,7 +59,7 @@ import Data.ByteString (ByteString)
|
|||||||
import qualified Data.ByteString as B (length)
|
import qualified Data.ByteString as B (length)
|
||||||
import qualified Data.ByteString.Internal as B
|
import qualified Data.ByteString.Internal as B
|
||||||
|
|
||||||
import Prelude (flip, return, div, (-), ($), (==), (/=), (<=), (>=), Int, Bool(..), IO, otherwise, sum, map, fmap, snd, (.), min)
|
import Prelude (flip, return, div, (*), (-), ($), (==), (/=), (<=), (>=), Int, Bool(..), IO, otherwise, sum, map, fmap, snd, (.), min)
|
||||||
|
|
||||||
data MemView = MemView !(Ptr Word8) !Int
|
data MemView = MemView !(Ptr Word8) !Int
|
||||||
|
|
||||||
@ -265,3 +267,9 @@ mapAsWord64 f bs =
|
|||||||
|
|
||||||
convert :: (ByteArrayAccess bin, ByteArray bout) => bin -> bout
|
convert :: (ByteArrayAccess bin, ByteArray bout) => bin -> bout
|
||||||
convert = flip copyAndFreeze (\_ -> return ())
|
convert = flip copyAndFreeze (\_ -> return ())
|
||||||
|
|
||||||
|
convertHex :: (ByteArrayAccess bin, ByteArray bout) => bin -> bout
|
||||||
|
convertHex b =
|
||||||
|
allocAndFreeze (length b * 2) $ \bout ->
|
||||||
|
withByteArray b $ \bin ->
|
||||||
|
toHexadecimal bout bin (length b)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user