From fd9f2a18eeaa5361660caa4c23384ea38973b021 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Thu, 2 Aug 2018 17:41:48 -0400 Subject: Eliminate Data.Digest.Internal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move Data.Digest.Internal’s functions and types into more appropriate modules. There’s now a single BTLS hierarchy that contains all internal modules for the project. --- src/BTLS/Types.hs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/BTLS/Types.hs') diff --git a/src/BTLS/Types.hs b/src/BTLS/Types.hs index dbd806a..06b5173 100644 --- a/src/BTLS/Types.hs +++ b/src/BTLS/Types.hs @@ -12,20 +12,36 @@ -- License for the specific language governing permissions and limitations under -- the License. -module BTLS.Types - ( AssociatedData(AssociatedData) - , Salt(Salt), noSalt - , SecretKey(SecretKey) - ) where +module BTLS.Types where +import Data.Bits (Bits((.&.)), shiftR) import Data.ByteString (ByteString) import qualified Data.ByteString as ByteString +import Data.Char (intToDigit) +import Data.Word (Word8) +import Foreign (Ptr) + +import BTLS.BoringSSL.Base (EVPMD) + +-- | A cryptographic hash function. +newtype Algorithm = Algorithm (Ptr EVPMD) -- | Context or application-specific information. Equality comparisons on this -- type are variable-time. newtype AssociatedData = AssociatedData ByteString deriving (Eq, Ord, Show) +-- | The result of a hash operation. +newtype Digest = Digest ByteString + deriving (Eq, Ord) + +instance Show Digest where + show (Digest d) = ByteString.foldr showHexPadded [] d + where + showHexPadded b xs = + hexit (b `shiftR` 4 .&. 0x0f) : hexit (b .&. 0x0f) : xs + hexit = intToDigit . fromIntegral :: Word8 -> Char + -- | A salt. Equality comparisons on this type are variable-time. newtype Salt = Salt ByteString deriving (Eq, Ord, Show) -- cgit v1.2.3