From 58151b9965199f39d3090e3d25219edc91354bb9 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 30 Nov 2016 15:10:48 +0900 Subject: [PATCH] making PRK an instance of ByteArrayAccess and removing fromPRK/toPRK. --- Crypto/KDF/HKDF.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Crypto/KDF/HKDF.hs b/Crypto/KDF/HKDF.hs index 3d15a2b..e9d0b4c 100644 --- a/Crypto/KDF/HKDF.hs +++ b/Crypto/KDF/HKDF.hs @@ -15,8 +15,6 @@ module Crypto.KDF.HKDF , extract , extractSkip , expand - , fromPRK - , toPRK ) where import Data.Word @@ -29,12 +27,11 @@ import qualified Crypto.Internal.ByteArray as B data PRK a = PRK (HMAC a) | PRK_NoExpand ScrubbedBytes deriving (Eq) -fromPRK :: ByteArray b => PRK a -> b -fromPRK (PRK hm) = B.convert hm -fromPRK (PRK_NoExpand sb) = B.convert sb - -toPRK :: ByteArrayAccess b => b -> PRK a -toPRK = extractSkip +instance ByteArrayAccess (PRK a) where + length (PRK hm) = B.length hm + length (PRK_NoExpand sb) = B.length sb + withByteArray (PRK hm) = B.withByteArray hm + withByteArray (PRK_NoExpand sb) = B.withByteArray sb -- | Extract a Pseudo Random Key using the parameter and the underlaying hash mechanism extract :: (HashAlgorithm a, ByteArrayAccess salt, ByteArrayAccess ikm)