implement different serializers #100
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit reviews the serialization approach from the ground to allow using different serializers and deserializers. For instance, this allows avoiding a copy after calling
.serialize(): in the previous version,serialize()was always returning aZeroizing<Vec<u8>>; in this new version,serializetakes an additional type parameter specifying whichSerializerto use and returnsSerializer::Output.Two serializers are implemented:
SecretSerializerwhich returns aZeroizing<Vec<u8>>; calling.serialize<SecretSerializer>()is therefore equivalent to the previous.serialze()call.PublicSerializerwhich returns aVec<u8>and is therefore appropriate to for use in deserialization of values that do not need to be zeroized on drop.Error management is not optimal since the error type of
Serializableis now constrained to beCryptoCoreError. Adding a per-implementation error back throughtype Error: std::error::Errormesses up with error conversion when serializing other types. For example when serializingOption<T>whereT: Serializable, a boolean is serialized to encode option variants and its serialization error must be compatible withT::ErrorandSelf::Error. Finally, since this is a trait, ad-hoc bounds cannot be added easily. All in all, constraining the error type seems and okay and easy solution. I remain open to suggestions.WARNING: this is a breaking change and requires a major version bump.