aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Digest.chs1
-rw-r--r--src/Data/Digest/Internal.chs29
-rw-r--r--src/Data/Hmac.chs4
-rw-r--r--src/Internal/Base.chs38
-rw-r--r--src/Internal/Digest.chs28
5 files changed, 73 insertions, 27 deletions
diff --git a/src/Data/Digest.chs b/src/Data/Digest.chs
index 09ab518..0ed24d2 100644
--- a/src/Data/Digest.chs
+++ b/src/Data/Digest.chs
@@ -27,6 +27,7 @@ module Data.Digest
import Foreign (Ptr)
{#import Data.Digest.Internal#}
+{#import Internal.Base#}
#include <openssl/digest.h>
diff --git a/src/Data/Digest/Internal.chs b/src/Data/Digest/Internal.chs
index 86cea65..6478810 100644
--- a/src/Data/Digest/Internal.chs
+++ b/src/Data/Digest/Internal.chs
@@ -12,8 +12,6 @@
-- License for the specific language governing permissions and limitations under
-- the License.
-{-# OPTIONS_GHC -Wno-missing-methods #-}
-
module Data.Digest.Internal where
import Data.Bits (Bits((.&.)), shiftR)
@@ -24,13 +22,14 @@ import qualified Data.ByteString.Unsafe as ByteString
import Data.Char (intToDigit)
import Data.Word (Word8)
import Foreign
- (FinalizerPtr, ForeignPtr, Ptr, Storable(alignment, peek, sizeOf),
- addForeignPtrFinalizer, alloca, allocaArray, mallocForeignPtr,
- nullPtr, withForeignPtr)
+ (FinalizerPtr, ForeignPtr, Ptr, Storable(peek), addForeignPtrFinalizer,
+ alloca, allocaArray, mallocForeignPtr, withForeignPtr)
import Foreign.C.Types
import Foreign.Marshal.Unsafe (unsafeLocalState)
import Unsafe.Coerce (unsafeCoerce)
+{#import Internal.Base#}
+{#import Internal.Digest#} ()
import Foreign.Ptr.Cast (asVoidPtr)
import Result
@@ -40,26 +39,6 @@ type LazyByteString = ByteString.Lazy.ByteString
-- First, we build basic bindings to the BoringSSL EVP interface.
--- | The BoringSSL @ENGINE@ type.
-data Engine
-{#pointer *ENGINE as 'Ptr Engine' -> Engine nocode#}
-
-noEngine :: Ptr Engine
-noEngine = nullPtr
-
--- | The BoringSSL @EVP_MD@ type, representing a hash algorithm.
-data EvpMd
-{#pointer *EVP_MD as 'Ptr EvpMd' -> EvpMd nocode#}
-
--- | The BoringSSL @EVP_MD_CTX@ type, representing the state of a pending
--- hashing operation.
-data EvpMdCtx
-{#pointer *EVP_MD_CTX as 'Ptr EvpMdCtx' -> EvpMdCtx nocode#}
-
-instance Storable EvpMdCtx where
- sizeOf _ = {#sizeof EVP_MD_CTX#}
- alignment _ = {#alignof EVP_MD_CTX#}
-
-- Imported functions from BoringSSL. See
-- https://commondatastorage.googleapis.com/chromium-boringssl-docs/digest.h.html
-- for documentation.
diff --git a/src/Data/Hmac.chs b/src/Data/Hmac.chs
index 907c352..e78c1af 100644
--- a/src/Data/Hmac.chs
+++ b/src/Data/Hmac.chs
@@ -33,10 +33,10 @@ import Foreign.Marshal.Unsafe (unsafeLocalState)
import Unsafe.Coerce (unsafeCoerce)
{#import Data.Digest.Internal#}
- (Algorithm(Algorithm), Digest(Digest), Engine, EvpMd, evpMaxMdSize,
- noEngine)
+ (Algorithm(Algorithm), Digest(Digest), evpMaxMdSize)
import Foreign.Ptr.Cast (asVoidPtr)
{#import Foreign.Ptr.ConstantTimeEquals#} (constantTimeEquals)
+{#import Internal.Base#}
import Result
type LazyByteString = ByteString.Lazy.ByteString
diff --git a/src/Internal/Base.chs b/src/Internal/Base.chs
new file mode 100644
index 0000000..552e76b
--- /dev/null
+++ b/src/Internal/Base.chs
@@ -0,0 +1,38 @@
+-- Copyright 2018 Google LLC
+--
+-- Licensed under the Apache License, Version 2.0 (the "License"); you may not
+-- use this file except in compliance with the License. You may obtain a copy of
+-- the License at
+--
+-- https://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+-- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+-- License for the specific language governing permissions and limitations under
+-- the License.
+
+{-# OPTIONS_GHC -Wno-missing-methods #-}
+{-# OPTIONS_GHC -Wno-unused-imports #-}
+
+module Internal.Base where
+
+import Foreign (Ptr, nullPtr)
+
+#include <openssl/base.h>
+
+-- | The BoringSSL @ENGINE@ type.
+data Engine
+{#pointer *ENGINE as 'Ptr Engine' -> Engine nocode#}
+
+noEngine :: Ptr Engine
+noEngine = nullPtr
+
+-- | The BoringSSL @EVP_MD_CTX@ type, representing the state of a pending
+-- hashing operation.
+data EvpMdCtx
+{#pointer *EVP_MD_CTX as 'Ptr EvpMdCtx' -> EvpMdCtx nocode#}
+
+-- | The BoringSSL @EVP_MD@ type, representing a hash algorithm.
+data EvpMd
+{#pointer *EVP_MD as 'Ptr EvpMd' -> EvpMd nocode#}
diff --git a/src/Internal/Digest.chs b/src/Internal/Digest.chs
new file mode 100644
index 0000000..46b497e
--- /dev/null
+++ b/src/Internal/Digest.chs
@@ -0,0 +1,28 @@
+-- Copyright 2018 Google LLC
+--
+-- Licensed under the Apache License, Version 2.0 (the "License"); you may not
+-- use this file except in compliance with the License. You may obtain a copy of
+-- the License at
+--
+-- https://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+-- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+-- License for the specific language governing permissions and limitations under
+-- the License.
+
+{-# OPTIONS_GHC -Wno-missing-methods #-}
+{-# OPTIONS_GHC -Wno-orphans #-}
+
+module Internal.Digest where
+
+import Foreign (Storable(alignment, sizeOf))
+
+{#import Internal.Base#}
+
+#include <openssl/digest.h>
+
+instance Storable EvpMdCtx where
+ sizeOf _ = {#sizeof EVP_MD_CTX#}
+ alignment _ = {#alignof EVP_MD_CTX#}