diff options
author | Benjamin Barenblat <bbaren@google.com> | 2018-08-02 17:41:48 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2018-08-02 17:41:48 -0400 |
commit | fd9f2a18eeaa5361660caa4c23384ea38973b021 (patch) | |
tree | b91bb69368664de23a1119ce625ba80aa1baccfd /src/BTLS/Types.hs | |
parent | 786d272fdf723987e582da16e511f067abf671a5 (diff) |
Eliminate Data.Digest.Internal
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.
Diffstat (limited to 'src/BTLS/Types.hs')
-rw-r--r-- | src/BTLS/Types.hs | 26 |
1 files changed, 21 insertions, 5 deletions
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) |