-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hash should serialize as byte string #412
Comments
Agreed. What do you think of dd0afd6? (https://github.com/BLAKE3-team/BLAKE3/compare/serde_bytes) |
Looks awesome! Nice test too, 0x58 (decimal 88) indicates a CBOR byte string with a byte length, and 32 is the length. And great that |
Two notes from someone who wrote a CBOR serialization library in the past:
|
This mostly reverts commits 8416b16 and dd0afd6. Changing the serialization of Hash can only be backwards-compatible in self-describing formats like CBOR. In non-self-describing formats like bincode, the deserializer has to know in advance which serialization format was used. Fixes #414. Reopens #412.
#414 pointed out that this change was backwards-incompatible for non-self-describing serialization formats. I've published v1.5.3 to revert it. Does anyone have ideas for a change along these lines that wouldn't break formats like bincode? |
This mostly reverts commits 8416b16 and dd0afd6. Changing the serialization of Hash can only be backwards-compatible in self-describing formats like CBOR. In non-self-describing formats like bincode, the deserializer has to know in advance which serialization format was used. Fixes BLAKE3-team#414. Reopens BLAKE3-team#412.
It's a nice example of serde's shortcomings. Afaik, crypto crates typically either avoid serde entirely, thus serde to serde users only care about one or two formats, or else define their serialization as bytes, preferably fixed length, and provide optional serde wrappers which do bytes, as fixed length if possible. You'll need some new type here, with |
Currently,
Hash
serializes as a sequence of integers, which is inefficient if the underlying codec supports a more compact byte string type. For example, serializingHash
to CBOR will produce an up-to 66 byte integer sequence (the precise size of the sequence will depend on the value of the hash) instead of a fixed size 34 byte byte string.Serializing to and deserializing from a byte string can be accomplished with serde_bytes:
The text was updated successfully, but these errors were encountered: