RLP 1.1.0 → 1.1.1
raw patch · 4 files changed
+20/−15 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- RLP.cabal +1/−1
- src/Data/Serialize/RLP.hs +8/−10
- src/Data/Serialize/RLP/Internal.hs +7/−4
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for RLP +## 1.1.1 -- 2018-12-10++* Added error when leading zeroes on integer decoding+ ## 1.1.0 -- 2018-12-10 * Added error handling support. Check the generated haddock documentation where examples have been placed.
RLP.cabal view
@@ -1,5 +1,5 @@ Name: RLP-Version: 1.1.0+Version: 1.1.1 Author: Javier Sagredo <jasataco@gmail.com> Maintainer: Javier Sagredo <jasataco@gmail.com> License: LGPL-3
src/Data/Serialize/RLP.hs view
@@ -46,6 +46,7 @@ import qualified Data.ByteString as DBS import qualified Data.ByteString.Lazy as DBSL+import qualified Data.ByteString.Char8 as DBSC -------------------------------------------------------------------------------- @@ -139,9 +140,12 @@ instance RLPSerialize Int where toRLP = toRLP . toBigEndianS - fromRLP = maybe Nothing (\s -> case fromBigEndianS s of- Left _ -> Nothing- Right v -> Just v ) . (fromRLP :: RLPT -> Maybe DBS.ByteString)+ fromRLP = maybe Nothing (\s -> if DBSC.head s == '\NUL'+ then Nothing+ else case fromBigEndianS s of+ Left _ -> Nothing+ Right v -> Just v ) .+ (fromRLP :: RLPT -> Maybe DBS.ByteString) -- Serializing lists implies making a list with the serialization -- of each element@@ -319,13 +323,7 @@ -- > -- Left "RLPT value couldn't ve transformed into the required type" -- -- If a ByteString is the result of the concatenation of more than one serialized RLPT structure,--- only the first one would be decoded:------ > rlpDecode $ rlpEncode $ RLPB $ toByteStringS "\STX" :: Either String Bool--- > -- Left "RLPT value couldn't ve transformed into the required type"------ If a ByteString is the result of the concatenation of more than one serialized RLPT structure,--- only the first one would be decoded:+-- only the first one would be decoded. This isn't quite specified in the Yellow Paper although it is possible that an error should be thrown when finding trailing bytes: -- -- > a = rlpEncode $ RLPL [ RLPB $ toByteStringS "John", RLPB $ toByteStringS "Snow" ] -- > b = DBSL.append a a
src/Data/Serialize/RLP/Internal.hs view
@@ -254,7 +254,10 @@ rlpDecodeI' = do b <- rlpDecodeI' :: Get DBS.ByteString- let k = fromBigEndianS b- case k of- Left m -> fail m- Right v -> return v+ case DBSC.head b of+ '\NUL' -> fail "leading zeroes found when decoding an integer"+ _ -> do+ let k = fromBigEndianS b+ case k of+ Left m -> fail m+ Right v -> return v