Skip to content
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

refactor(identity): call Into::into instead of copying the slice #5788

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions identity/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,7 @@ impl SecretKey {
///
/// [RFC3278]: https://tools.ietf.org/html/rfc3278#section-8.2
pub fn sign(&self, msg: &[u8]) -> Vec<u8> {
let generic_array = Sha256::digest(msg);

// FIXME: Once `generic-array` hits 1.0, we should be able to just use `Into` here.
let mut array = [0u8; 32];
array.copy_from_slice(generic_array.as_slice());

let message = Message::parse(&array);
let message = Message::parse(&Sha256::digest(msg).into());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have it in separate variables before passing it to Message::parse

eg

Suggested change
let message = Message::parse(&Sha256::digest(msg).into());
let digest = Sha256::digest(msg);
let message = Message::parse(&digest.into());

Thoughts? Not that it should impact anything from a glance over, but just thinking about readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the information is sufficient since the method is called digest. Calling into introduces some ambiguity but I don't think it matters.


libsecp256k1::sign(&message, &self.0)
.0
Expand Down
Loading