aboutsummaryrefslogtreecommitdiff
path: root/src/BTLS/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/BTLS/Types.hs')
-rw-r--r--src/BTLS/Types.hs14
1 files changed, 13 insertions, 1 deletions
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 "<algorithm>" else unsafeLocalState (peekCString sn)
+
-- | Context or application-specific information. Equality comparisons on this
-- type are variable-time.
newtype AssociatedData = AssociatedData ByteString