-
Notifications
You must be signed in to change notification settings - Fork 115
[WIP] use base64 over base64-bytestring #1631
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -325,8 +325,7 @@ library | |||||
| , attoparsec >= 0.13 | ||||||
| , base >= 4.12 && < 5 | ||||||
| , base16-bytestring >= 0.1 | ||||||
| , base64-bytestring >= 1.0 && < 1.1 | ||||||
| -- due to change in error message that is inlined in pact | ||||||
| , base64 >= 0.5 && < 0.6 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this known to break with base64 >=0.6? Otherwise please remove, since we don't manually track "soft" upper bounds.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that version 0.5 of base64 hasn't yet been released. The latest version on Hackage is 0.4.2.4. 0.5 is only available as source repository from Github. If 0.5 is actually required, we would have to ask the maintainer (@emilypi?) to release 0.5 on Hackage or include it as source repository package in cabal.project.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It hasn't been released and I"m still working on the PR, which will significantly affect this PR. |
||||||
| , binary >= 0.8 | ||||||
| , bytestring >= 0.10 | ||||||
| , case-insensitive >= 1.2 | ||||||
|
|
@@ -506,8 +505,7 @@ test-suite chainweb-tests | |||||
| , aeson-pretty | ||||||
| , async >= 2.2 | ||||||
| , base >= 4.12 && < 5 | ||||||
| , base64-bytestring >= 1.0 && < 1.1 | ||||||
| -- due to change in error message that is inlined in pact | ||||||
| , base64 >= 0.5 && < 0.6 | ||||||
| , bytestring >= 0.10 | ||||||
| , case-insensitive >= 1.2 | ||||||
| , chainweb-storage >= 0.1 | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| {-# LANGUAGE BangPatterns #-} | ||
| {-# LANGUAGE DeriveAnyClass #-} | ||
| {-# LANGUAGE DataKinds #-} | ||
| {-# LANGUAGE DeriveGeneric #-} | ||
| {-# LANGUAGE DerivingStrategies #-} | ||
| {-# LANGUAGE FlexibleContexts #-} | ||
|
|
@@ -98,9 +99,11 @@ import Crypto.Hash (hash) | |
| import Crypto.Hash.Algorithms (SHA512t_256) | ||
|
|
||
| import Data.Aeson | ||
| import Data.Bifunctor (first) | ||
| import Data.Bits (bit, shiftL, shiftR, (.&.)) | ||
| import Data.ByteArray (convert) | ||
| import qualified Data.ByteString.Base64.URL as B64 | ||
| import qualified Data.Base64.Types as B64 | ||
| import qualified Data.ByteString.Base64.URL as B64U | ||
| import Data.ByteString.Char8 (ByteString) | ||
| import qualified Data.ByteString.Char8 as B | ||
| import qualified Data.ByteString.Short as SB | ||
|
|
@@ -703,7 +706,8 @@ mockCodec = Codec mockEncode mockDecode | |
|
|
||
| mockEncode :: MockTx -> ByteString | ||
| mockEncode (MockTx nonce (GasPrice (ParsedDecimal price)) limit meta) = | ||
| B64.encode $ | ||
| B64.extractBase64 $ | ||
| B64U.encodeBase64' $ | ||
| runPutS $ do | ||
| putWord64le $ fromIntegral nonce | ||
| putDecimal price | ||
|
|
@@ -746,7 +750,7 @@ getDecimal = do | |
|
|
||
| mockDecode :: ByteString -> Either String MockTx | ||
| mockDecode s = do | ||
| s' <- B64.decode s | ||
| s' <- first T.unpack $ B64U.decodeBase64 $ B64.assertBase64 @'B64.UrlPadded @_ s | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit concerned about |
||
| runGetEitherS (MockTx <$> getI64 <*> getPrice <*> getGL <*> getMeta) s' | ||
| where | ||
| getPrice = GasPrice . ParsedDecimal <$> getDecimal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| {-# LANGUAGE AllowAmbiguousTypes #-} | ||
| {-# LANGUAGE BangPatterns #-} | ||
| {-# LANGUAGE DataKinds #-} | ||
| {-# LANGUAGE DefaultSignatures #-} | ||
| {-# LANGUAGE DeriveAnyClass #-} | ||
| {-# LANGUAGE DeriveGeneric #-} | ||
|
|
@@ -242,6 +243,7 @@ import Data.ByteString (ByteString) | |
| import qualified Data.ByteString as B | ||
| import qualified Data.ByteString.Char8 as B8 | ||
| import qualified Data.ByteString.Base64 as B64 | ||
| import qualified Data.Base64.Types as B64 | ||
| import qualified Data.ByteString.Base64.URL as B64U | ||
| import qualified Data.ByteString.Builder as BB | ||
| import qualified Data.ByteString.Lazy as BL | ||
|
|
@@ -604,15 +606,16 @@ iso8601DateTimeFormat = iso8601DateFormat (Just "%H:%M:%SZ") | |
| -- | ||
| decodeB64Text :: MonadThrow m => T.Text -> m B.ByteString | ||
| decodeB64Text = fromEitherM | ||
| . first (Base64DecodeException . T.pack) | ||
| . B64.decode | ||
| . first Base64DecodeException | ||
| . B64.decodeBase64 | ||
| . B64.assertBase64 @'B64.StdPadded @_ | ||
|
Comment on lines
-607
to
+611
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the functions for the unpadded (and non-url) variants used anywhere in the code? If not we should consider removing them, so that nobody uses them. This is to keep used encodings simple and consistent. |
||
| . T.encodeUtf8 | ||
| {-# INLINE decodeB64Text #-} | ||
|
|
||
| -- | Encode a binary value to a textual base64 representation. | ||
| -- | ||
| encodeB64Text :: B.ByteString -> T.Text | ||
| encodeB64Text = T.decodeUtf8 . B64.encode | ||
| encodeB64Text = B64.extractBase64 . B64.encodeBase64 | ||
| {-# INLINE encodeB64Text #-} | ||
|
|
||
| -- | Decode a binary value from a textual base64-url representation. A | ||
|
|
@@ -621,15 +624,16 @@ encodeB64Text = T.decodeUtf8 . B64.encode | |
| -- | ||
| decodeB64UrlText :: MonadThrow m => T.Text -> m B.ByteString | ||
| decodeB64UrlText = fromEitherM | ||
| . first (Base64DecodeException . T.pack) | ||
| . B64U.decode | ||
| . first Base64DecodeException | ||
| . B64U.decodeBase64 | ||
| . B64.assertBase64 @'B64.UrlPadded @_ | ||
| . T.encodeUtf8 | ||
| {-# INLINE decodeB64UrlText #-} | ||
|
|
||
| -- | Encode a binary value to a textual base64-url representation. | ||
| -- | ||
| encodeB64UrlText :: B.ByteString -> T.Text | ||
| encodeB64UrlText = T.decodeUtf8 . B64U.encode | ||
| encodeB64UrlText = B64.extractBase64 . B64U.encodeBase64 | ||
| {-# INLINE encodeB64UrlText #-} | ||
|
|
||
| -- | Decode a binary value from a textual base64-url without padding | ||
|
|
@@ -638,8 +642,9 @@ encodeB64UrlText = T.decodeUtf8 . B64U.encode | |
| -- | ||
| decodeB64UrlNoPaddingText :: MonadThrow m => T.Text -> m B.ByteString | ||
| decodeB64UrlNoPaddingText = fromEitherM | ||
| . first (Base64DecodeException . T.pack) | ||
| . B64U.decode | ||
| . first Base64DecodeException | ||
| . B64U.decodeBase64 | ||
| . B64.assertBase64 @'B64.UrlPadded @_ | ||
| . T.encodeUtf8 | ||
| . pad | ||
| where | ||
|
|
@@ -650,14 +655,14 @@ decodeB64UrlNoPaddingText = fromEitherM | |
| -- representation. | ||
| -- | ||
| encodeB64UrlNoPaddingText :: B.ByteString -> T.Text | ||
| encodeB64UrlNoPaddingText = T.dropWhileEnd (== '=') . T.decodeUtf8 . B64U.encode | ||
| encodeB64UrlNoPaddingText = T.dropWhileEnd (== '=') . B64.extractBase64 . B64U.encodeBase64 | ||
| {-# INLINE encodeB64UrlNoPaddingText #-} | ||
|
|
||
| -- | Encode a binary value to a base64-url (without padding) JSON encoding. | ||
| -- | ||
| b64UrlNoPaddingTextEncoding :: B.ByteString -> Encoding | ||
| b64UrlNoPaddingTextEncoding t = | ||
| Aeson.unsafeToEncoding $ BB.char8 '\"' <> BB.byteString (B8.dropWhileEnd (== '=') $ B64U.encode t) <> BB.char8 '\"' | ||
| Aeson.unsafeToEncoding $ BB.char8 '\"' <> BB.byteString (B8.dropWhileEnd (== '=') $ B64.extractBase64 $ B64U.encodeBase64' t) <> BB.char8 '\"' | ||
|
|
||
| -- -------------------------------------------------------------------------- -- | ||
| -- ** JSON | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 the upper bound is tracked in the cabal.project file.