-
Notifications
You must be signed in to change notification settings - Fork 230
Description
This is a tracking ticket for potential breaking changes to the signature crate which target a 2.0 release. There's no planned release date for this besides "some time after a minimum viable implementation of const generics in stable Rust", so this issue is mostly for brainstorming and tracking current defects/issues which require SemVer breaking changes to address.
As a bit of background, the impetus for stabilizing an initial 1.0 release was to also allow for a 1.0 release of the ed25519 crate. The signature and ed25519 crates together allow for writing code which is generic over how Ed25519 signing and/or verification is implemented. These traits and signature types are now used by ed25519-dalek as well as the signatory crates.
This stabilization, while providing a useful 1.0 for Ed25519, made a number of compromises (see #78). Most notably, while there are many ways it could benefit from either generic-array or const generics, the public API avoided them both, mainly to avoid having every generic-array bump be a SemVer breaking change and get to a reasonably useful 1.0 quickly.
All of that said, it seems the minimum viable implementation of const generics may be coming sooner than we think, potentially in 2020. This issue is intended to track potential proposals that could use them, as well as existing API defects it'd be nice to fix in a SemVer breaking release.
Replace AsRef<[u8]> bound on Signature trait with associated const SIZE and Into<[u8; Self::SIZE]> bound
The AsRef bound provides a common API for converting a signature into a byte slice, but has the following limitations:
- Requires "bag-of-bytes" signature types as opposed to ones with internal structure: the current API requires that all signature types provide a simple reference conversion to a byte slice, which precludes an intermediate parsing step to e.g. well-structured scalar or group element types. With const generics, this can be replaced with an
Intoconversion to a byte array, allowing an intermediate serialization step from these well-structured types to a "bag-of-bytes" wire representation. - No way to bound on signature size: by not providing type-level information about the signature size at all, the type system can't reason about signature sizes. This would mainly be useful for doing type-level calculations of the sizes of messages that incorporate signatures in a way that's generic over the signature size.
Disable std Cargo feature by default
This is a notable inconsistency with the other RustCrypto/traits crates, and since all of these crates have a no_std focus, it's nice to have this off-by-default.
The std feature is used entirely for the purposes of error handling to gate a std::error::Error impl which, when std is available, can provide a Box-ed source.
Error improvements
Presently in any no_std context, including ones with alloc, the error source is lost. It seems like some middle ground is possible in the alloc case, like retaining the source, but exposing it through an inherent method rather than std::error::Error. This could even be defined in a way that's purely additive by having the std::error::Error impl invoke the inherent Error::source method.
Stabilization of *-preview features.
Since many features of the signature crate are also blocked on const generics for a 1.0 release, they were shipped as *-preview features, with a SemVer guarantee that breaking changes to *-preview features would come with a minor version bump (more or less the same way it works with 0.x versions).
There are open tracking issues for each of these features:
digest-preview: providesDigestSigner,DigestVerifier, andDigestSignature(signature: tracking issue fordigeststabilization (DigestSigner, DigestVerifier, and DigestSignature) #92)rand-preview: providesRandomizedSigner; blocked onrand_core1.0 (signature: tracking issue forrand_core(RandomizedSigner) stabilization #94)
It would probably make sense to stabilize the digest feature first via a const generics-based digest 1.0 crate, then have signature 2.0 depend on digest 1.0 (See #238).