From 489d8db89aff5a6a0ab1e67ef14bcfb870f4f1f3 Mon Sep 17 00:00:00 2001 From: Viktor Dukhovni Date: Sat, 16 Aug 2025 16:47:30 +1000 Subject: [PATCH] Implemented TH splices for validated ByteString literals literalFromOctetString :: Quote m => String -> Code m ByteString literalFromHex :: Quote m => String -> Code m ByteString The former rejects inputs with non-octet code points above 0xFF. The latter rejects odd-length inputs or inputs with characters other than non-hexadecimal digits. --- Changelog.md | 4 +- Data/ByteString.hs | 2 + Data/ByteString/Internal/Type.hs | 113 ++++++++++++++++++++++++++++++- tests/Lift.hs | 8 +++ 4 files changed, 124 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 5aae20e1..26ef770e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,7 +7,9 @@ * API additions and behavior changes: * Data.ByteString.Short now provides `lazyToShort` and `lazyFromShort`. - + * New TH splices: `Data.ByteString.literalFromOctetString` and `Data.ByteString.literalFromHex` + * These validate input strings prior to generating corresponding + compile-time literal ByteStrings.