From 100fc7dc0c7ce85aad0e413b97a90b98185326ef Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Tue, 25 Sep 2018 18:13:26 -0400 Subject: Give `Algorithm` a `Show` instance --- src/BTLS/Types.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/BTLS/Types.hs') diff --git a/src/BTLS/Types.hs b/src/BTLS/Types.hs index 4a4e518..6abd632 100644 --- a/src/BTLS/Types.hs +++ b/src/BTLS/Types.hs @@ -18,13 +18,25 @@ import Data.ByteString (ByteString) import qualified Data.ByteString as ByteString import qualified Data.ByteString.Base16 as ByteString.Base16 import qualified Data.ByteString.Char8 as ByteString.Char8 -import Foreign (Ptr) +import Foreign (Ptr, nullPtr) +import Foreign.C (peekCString) +import Foreign.Marshal.Unsafe (unsafeLocalState) import BTLS.BoringSSL.Base (EVPMD) +import BTLS.BoringSSL.Digest (evpMDType) +import BTLS.BoringSSL.Obj (objNID2SN) -- | A cryptographic hash function. newtype Algorithm = Algorithm (Ptr EVPMD) +instance Eq Algorithm where + Algorithm a == Algorithm b = evpMDType a == evpMDType b + +instance Show Algorithm where + show (Algorithm md) = + let sn = objNID2SN (evpMDType md) in + if sn == nullPtr then "" else unsafeLocalState (peekCString sn) + -- | Context or application-specific information. Equality comparisons on this -- type are variable-time. newtype AssociatedData = AssociatedData ByteString -- cgit v1.2.3