From 021932a9ee2a81435b0a341030f68730dd9abd3b Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Fri, 21 Sep 2018 14:19:10 -0400 Subject: Start using base16-bytestring in btls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’re already using it in tests, so eliminate some hand-rolled hexification code. --- src/BTLS/Types.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/BTLS') diff --git a/src/BTLS/Types.hs b/src/BTLS/Types.hs index 44b29bc..4a4e518 100644 --- a/src/BTLS/Types.hs +++ b/src/BTLS/Types.hs @@ -14,11 +14,10 @@ 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 qualified Data.ByteString.Base16 as ByteString.Base16 +import qualified Data.ByteString.Char8 as ByteString.Char8 import Foreign (Ptr) import BTLS.BoringSSL.Base (EVPMD) @@ -39,11 +38,7 @@ 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 + show (Digest d) = showHex d -- | A salt. Equality comparisons on this type are variable-time. newtype Salt = Salt ByteString @@ -57,3 +52,6 @@ noSalt = Salt ByteString.empty -- this type are variable-time. newtype SecretKey = SecretKey ByteString deriving (Eq, Ord, Show) + +showHex :: ByteString -> String +showHex = ByteString.Char8.unpack . ByteString.Base16.encode \ No newline at end of file -- cgit v1.2.3