rust-crypto
rust-crypto copied to clipboard
Api for ed25519::keypair could benefit from a newtype
pub fn keypair(seed: &[u8]) -> ([u8; 64], [u8; 32])
=>
pub fn keypair(seed: &[u8]) -> (Secret, Public)
let foo = keypair(..); .. foo.0 ..
can be non obvious for readers.
It's more intended to be used in the destructured tuple form:
let (priv, pub) = keypair(seed);
... but yeah, a struct for PKC keypairs would probably be a good idea. Similarly with symmetric keys, actually, as keys should be made different to arrays of bytes. This is a large-ish undertaking, however, and probably something best decided on as a group or by the maintainer, as it is a question of policy: do we implement this functionality for users, taking an opinionated stance, or let them do it how they (the users) like?
Another notable possible misuse, the size of the seed should be enforced by its type (seed of size different than 32 bytes break the algo(only visible when using verify)). Yet I do not have a practical answer for this ([u8;32] is not really nice to use).