-
Notifications
You must be signed in to change notification settings - Fork 280
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
Passing array reference instead of owned array #780
Comments
Agreed, this feels un-Rust-like and we should pass 32-byte arrays by value. Same with 64/65-byte arrays. I don't think there are larger ones used by this library. |
FTR if people are worried about performance we can slap |
I could update the existing methods to take |
We don't mind doing breaking changes. |
Yeah, the API in rust-secp is a real mess right now. We are also at a good time right now to make sweeping API changes because in rust-bitcoin we're focused on non-crypto stuff and won't be pressured to cut a new incomplete release of rust-secp anytime soon. |
Frankly, I'm really looking forward to the MuSig stuff, I just also don't have that much time for it yet. |
The coexistence of |
> git grep '&\[u8;'
src/ecdsa/mod.rs: noncedata: Option<&[u8; 32]>,
src/ecdsa/mod.rs: noncedata: &[u8; 32],
src/ecdsa/recovery.rs: noncedata: &[u8; 32],
src/ellswift.rs: pub const fn as_secret_bytes(&self) -> &[u8; 32] { &self.0 }
src/key.rs: fn as_ref(&self) -> &[u8; constants::SECRET_KEY_SIZE] {
src/lib.rs: pub fn seeded_randomize(&mut self, seed: &[u8; 32]) {
src/scalar.rs: pub(crate) fn as_be_bytes(&self) -> &[u8; 32] { &self.0 }
src/schnorr.rs: pub fn as_byte_array(&self) -> &[u8; constants::SCHNORR_SIGNATURE_SIZE] { &self.0 }
src/schnorr.rs: aux_rand: &[u8; 32], |
Yeah, I think we should drop (deprecate) |
Definitely not. It's useful when you need to cast a reference to something to a slice reference without dealing with the temporary value causing borrowing issues. |
Ahh that's a great point. |
That sounds like |
@uncomputable yes, but having a method too is idiomatic and helpful in some cases. The cost of having the method is near zero. |
59cf7bd refactor: Create keys from owned array values (Christian Lewe) e7eea32 feat: KeyPair::from_seckey_byte_array (Christian Lewe) e723d80 refactor: Parse byte array instead of byte slice (Christian Lewe) Pull request description: Construct KeyPair directly from [u8; 32]. I can change the parameter to &[u8; 32] depending on the discussion in #780. ACKs for top commit: Kixunil: ACK 59cf7bd apoelstra: ACK 59cf7bd; successfully ran local tests; nice! the old function signatures were super weird. and the docs were wrong lol tcharding: ACK 59cf7bd Tree-SHA512: 64e3026984c79b2491b83775bd50b203ad0723f97ac02b4aa84bc5d0e1135c7fabb660a7d242beaa3f2799f16b169c6bbe3f24e31668518b59ed01839bb86c69
The
from_byte_array
methods take as parameter an array reference&[u8; LEN]
instead of an owned array[u8; LEN]
.Looking at the implementation, the input bytes are converted into a C pointer
as_c_ptr()
and passed to a C function. From that perspective, an array reference seems fitting because it is easy to convert to a C pointer. However, passing an array reference seems like uncanonical Rust code to me. Copying 32 bytes is not a problem on any system.Affected functions:
SecretKey::from_byte_array
,XOnlyPublicKey::from_byte_array
,PublicKey::from_byte_array_compressed
,PublicKey::from_byte_array_uncompressed
.The text was updated successfully, but these errors were encountered: