aboutsummaryrefslogtreecommitdiff
path: root/src/BTLS
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-09-21 14:19:10 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-09-21 14:19:10 -0400
commit021932a9ee2a81435b0a341030f68730dd9abd3b (patch)
treed8f41a370c3cb46750ec51e7c18a1c44ed3972f0 /src/BTLS
parentad7c615864605c8cc8eea7fc7bd6e917404e5562 (diff)
Start using base16-bytestring in btls
We’re already using it in tests, so eliminate some hand-rolled hexification code.
Diffstat (limited to 'src/BTLS')
-rw-r--r--src/BTLS/Types.hs14
1 files changed, 6 insertions, 8 deletions
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