Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop cryptohash #30

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ A template is provided:
- Describe change #2
- Indicate if changes are major, minor, or patch changes.
```
- [#30](https://github.com/jhickner/smtp-mail/pull/30) @typetetris
- Replace `cryptohash` dependency with `cryptonite`.
`cryptohash` is deprecated and `cryptonite` offers HMAC MD5
directly.

## 0.2.0.0

Expand Down
16 changes: 6 additions & 10 deletions Network/Mail/SMTP/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ module Network.Mail.SMTP.Auth (
auth,
) where

import Crypto.Hash.MD5 (hash)
import Crypto.MAC.HMAC (hmac, HMAC)
import Crypto.Hash.Algorithms (MD5)
import Data.ByteArray (copyAndFreeze)
import qualified Data.ByteString.Base16 as B16 (encode)
import qualified Data.ByteString.Base64 as B64 (encode)

import Data.ByteString (ByteString)
import Data.List
import Data.Bits
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B8 (unwords)

Expand All @@ -39,14 +40,9 @@ b64Encode :: String -> ByteString
b64Encode = B64.encode . toAscii

hmacMD5 :: ByteString -> ByteString -> ByteString
hmacMD5 text key = hash (okey <> hash (ikey <> text))
where key' = if B.length key > 64
then hash key <> B.replicate 48 0
else key <> B.replicate (64-B.length key) 0
ipad = B.replicate 64 0x36
opad = B.replicate 64 0x5c
ikey = B.pack $ B.zipWith xor key' ipad
okey = B.pack $ B.zipWith xor key' opad
hmacMD5 text key =
let mac = hmac key text :: HMAC MD5
in copyAndFreeze mac (const $ return ())

encodePlain :: UserName -> Password -> ByteString
encodePlain user pass = b64Encode $ intercalate "\0" [user, user, pass]
Expand Down
5 changes: 3 additions & 2 deletions smtp-mail.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: smtp-mail
version: 0.2.0.0
version: 0.2.0.1
synopsis: Simple email sending via SMTP
description: This packages provides a simple interface for mail over SMTP. PLease see the README for more information.
homepage: http://github.com/jhickner/smtp-mail
Expand Down Expand Up @@ -34,11 +34,12 @@ library
, base64-bytestring
, bytestring
, connection
, cryptohash
, filepath
, mime-mail
, network
, network-bsd
, text
, cryptonite
, memory

ghc-options: -Wall -fwarn-tabs