Change from_bytes methods to take fixed-size array argument#230
Change from_bytes methods to take fixed-size array argument#230tarcieri merged 1 commit intodalek-cryptography:release/2.0from
Conversation
|
In general I'd suggest holding off on this until #225 is addressed, since that proposes to change the public APIs for keys |
|
This was also an interesting read on the actual costs of length checks: https://blog.readyset.io/bounds-checks/ tl;dr: not much, especially in cases like this |
|
The main thing is that creation of SecretKey is now infallible. Another is that the expected length is now expressed in type system. Performance isn’t really my main concern. |
|
I'd probably suggest making the |
|
I can change |
|
So I’m looking at ed25519::Signature::from_bytes from a preview ed25519 crate and it has |
|
I'd be open to changing that method |
|
Updated as per suggestion. Happy to wait till #225 gets resolved. |
|
#225 is resolved |
|
@mina86 you need to change the base to |
Change from_bytes methods to take `&[u8; N]` argument (with `N` appropriate for given type) rather than `&[u8]`. This harmonises the convention with SigningKey and ed25519::Signature; helps type inference; and allows users to assert bytes size to be asserted at compile time. Creating from a slice is still possible via `TryFrom<&[u8]>` trait. This is an API breaking change. The simplest way to update existing code is to replace Foo::from_bytes with Foo::try_from. This should cover majority of uses.
Change from_bytes methods of all the types to take
&[u8; N]argument(with
Nappropriate for given type) rather than&[u8]. This doesa few things:
sites (if the call site already has properly-sized array),
and
means that users can assert it at compile time.
To still allow creating the objects from a slice whose size is checked
at run time, introduce
TryFrom<&[u8]>implementations for affectedpublic types.
This is an API breaking change. The simplest way to update existing
code is to replace Foo::from_bytes with Foo::try_from. This should
cover majority of uses.