Skip to content

Commit

Permalink
Add ToForm
Browse files Browse the repository at this point in the history
  • Loading branch information
cotrone committed Dec 27, 2023
1 parent a622e8b commit bf4235e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Web/WebPush.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import qualified Network.URI as URI
import System.Random (randomRIO)
import Web.FormUrlEncoded
import Web.HttpApiData
import qualified Data.HashMap.Strict as HM

-- | Configuration for VAPID server identification
data VAPIDConfig = VAPIDConfig {
Expand Down Expand Up @@ -260,6 +261,13 @@ instance FromForm Subscription where
, subscriptionP256dh = p256
, subscriptionAuth = auth'
}

instance ToForm Subscription where
toForm sub = Form $ HM.fromList [
("endpoint", [T.pack $ URI.uriToString id (subscriptionEndpoint sub) ""])
, ("p256dh", [subscriptionP256dh sub])
, ("auth", [subscriptionAuth sub])
]

-- | Web push notification expiration and message to send
data PushNotification msg = PushNotification {
Expand Down
2 changes: 1 addition & 1 deletion src/Web/WebPush/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ webPushEncrypt EncryptionInput{..} = do -- TODO remove record wildcards
-- tag length 16 bytes (maximum), anything less than 16 bytes may not be secure enough
-- spec says final encrypted size is 16 bits longer than the padded text
-- NOTE: the final encrypted message must be sent as raw binary data
authTag = ByteArray.convert $ Cipher.unAuthTag authTagBytes
(authTagBytes, cipherText) = Cipher.aeadSimpleEncrypt aeadGcmCipher BS.empty paddedPlainText 16
authTag = ByteArray.convert $ Cipher.unAuthTag authTagBytes
encryptedMessage = cipherText <> authTag
-- HMAC a doesn't have Show instance needed for test suite
-- so we extract the bytes and store that in WebPushEncryptionOutput
Expand Down
1 change: 1 addition & 0 deletions web-push.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ library
, binary >= 0.7.5 && < 0.9
, bytestring >= 0.9 && < 0.13
, containers >= 0.6 && < 0.7
, unordered-containers >= 0.2 && < 0.3
, crypton >= 0.30 && < 1.0
, crypton-x509 >= 1.7 && < 1.8
, crypton-x509-store >= 1.6 && < 1.7
Expand Down

0 comments on commit bf4235e

Please sign in to comment.