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

Allow infallible construction of Signature #730

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

yukibtc
Copy link
Contributor

@yukibtc yukibtc commented Sep 2, 2024

Hi! This PR add 1 constructor and 2 methods to Signature struct:

  • Add Signature::from_byte_array constructor
  • Add Signature::to_byte_array and Signature::as_byte_array methods
  • Deprecate Signature::serialize method

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Wow, I haven't noticed that signatures actually don't have any invariants (other than length). Concept ACK though I'm not sure about the renaming of serialize.

@Kixunil
Copy link
Collaborator

Kixunil commented Sep 2, 2024

Also the title is misleading since this is not what "zero copy" means. "Zero copy" is just a stupid name for "zero heap allocations" and the original code didn't do any heap allocations in the first place. Further, in hashes we use from_byte_array for array-accepting constructors.

What I believe is non-controversial about this PR: we want some infallible method that accepts an array. I wanted to suggest you to make just that change first but then I remembered about from_byte_array thing.

@apoelstra
Copy link
Member

Neat! Concept ACK.

I would like to use to_byte_array and from_byte_array to be consistent with hashes. (I have proposed the same thing for SecretKey in #724.)

* Add `Signature::from_byte_array` constructor
* Add `Signature::to_byte_array` and `Signature::as_byte_array` methods
* Deprecate `Signature::serialize` method

Signed-off-by: Yuki Kishimoto <[email protected]>
@yukibtc yukibtc changed the title Allow zero copy Signature construction Allow infallible construction of Signature Sep 2, 2024
@yukibtc
Copy link
Contributor Author

yukibtc commented Sep 2, 2024

Also the title is misleading since this is not what "zero copy" means. "Zero copy" is just a stupid name for "zero heap allocations" and the original code didn't do any heap allocations in the first place

Ahh, thanks for the clarification


I've done the changes as suggested.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 23b87a6

@@ -88,9 +91,17 @@ impl Signature {
}

/// Returns a signature as a byte array.
#[inline]
#[deprecated(since = "0.30.0", note = "Use `to_byte_array` instead.")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We usually use TBD in since and mass-replace it during release but there isn't anything wrong with this.

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 23b87a6 successfully ran local tests

@apoelstra apoelstra merged commit e9c959d into rust-bitcoin:master Sep 2, 2024
29 checks passed
@yukibtc yukibtc deleted the sig branch September 2, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants