[Haskell-cafe] [SOLVED] Writing and testing a Storable instance for a record wrapping ForeignPtrs

Viktor Dukhovni ietf-dane at dukhovni.org
Mon Nov 28 19:34:50 UTC 2022


On Mon, Nov 28, 2022 at 08:14:15PM +0100, Hécate wrote:
> Ah sorry, I misunderstood your question.
> 
> I am writing a high-level interface to my libsodium bindings, and I'm 
> trying to provide implementations of helpful typeclasses.
> 
> I actually don't need Storable to do the FFI stuff, thankfully, but the 
> main case of using this library would involve sending the result of the 
> signing operation to the network (as ByteStrings), with authorization 
> tokens like Biscuit¹ in mind.
> 
> ¹ https://www.biscuitsec.org

For serialisation to external standard formats, like JSON, or binary
JSON, ... you're definitely not looking for `Storable`.  Simply
returning the message as two octet-strings (ByteStrings), one for the
raw data and another for the signature is all you need.  From there,
various higher-level formats are possible.

The main thing to be mindful of is that ByteStrings are limited to 2^31
bytes on 32-bit machines, so very large messages don't fit in a
ByteString on some (increasingly less common) architectures.

Or am I missing some reason why you'd want to create a single binary
blob <length,<$length bytes>,<signature>>?

-- 
    Viktor.


More information about the Haskell-Cafe mailing list