Skip to content

Commit ea4eb90

Browse files
committed
Parse hex-encoded bytestrings correctly.
1 parent 8d17bcf commit ea4eb90

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

cuddle.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.4
22
name: cuddle
3-
version: 0.1.9.0
3+
version: 0.1.10.0
44
synopsis: CDDL Generator and test utilities
55

66
-- description:
@@ -58,6 +58,7 @@ library
5858
-- other-extensions:
5959
build-depends:
6060
, base ^>=4.14.3.0 || ^>=4.16.3.0 || ^>=4.18.1.0 || ^>=4.19.0.0
61+
, base16-bytestring
6162
, bytestring
6263
, capability
6364
, cborg

src/Codec/CBOR/Cuddle/CBOR/Gen.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import System.Random.Stateful
5454
randomM,
5555
uniformByteStringM,
5656
)
57+
import qualified Data.ByteString.Base16 as Base16
5758

5859
--------------------------------------------------------------------------------
5960
-- Generator infrastructure
@@ -383,7 +384,9 @@ genValue (VFloat16 i) = pure . THalf $ i
383384
genValue (VFloat32 i) = pure . TFloat $ i
384385
genValue (VFloat64 i) = pure . TDouble $ i
385386
genValue (VText t) = pure $ TString t
386-
genValue (VBytes b) = pure $ TBytes b
387+
genValue (VBytes b) = case Base16.decode b of
388+
Right bHex -> pure $ TBytes bHex
389+
Left err -> error $ "Unable to parse hex encoded bytestring: " <> err
387390

388391
--------------------------------------------------------------------------------
389392
-- Generator functions

0 commit comments

Comments
 (0)