aboutsummaryrefslogtreecommitdiff
path: root/src/BTLS/Types.hs
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-09-25 18:13:26 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-09-25 18:13:26 -0400
commit100fc7dc0c7ce85aad0e413b97a90b98185326ef (patch)
tree4a4fc7e8bc296b0069166fea55fe9456fa994cb0 /src/BTLS/Types.hs
parenta643f96bd1b8048a08277f7992ca7d43ee2423c3 (diff)
Give `Algorithm` a `Show` instance
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