Add must_use for mut self key manipulation methods
We recently added a bunch of key tweaking methods that take `mut self` and return the tweaked/negated keys. These functions are pure and as such the returned result is expected to be used. To help downstream users use the API correctly add `must_use` attributes with a descriptive error string for each of the methods that takes `mut self`.
This commit is contained in:
parent
5b86e38aea
commit
56f18430ff
|
@ -243,6 +243,7 @@ impl SecretKey {
|
||||||
|
|
||||||
/// Negates the secret key.
|
/// Negates the secret key.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "you forgot to use the negated secret key"]
|
||||||
pub fn negate(mut self) -> SecretKey {
|
pub fn negate(mut self) -> SecretKey {
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = ffi::secp256k1_ec_seckey_negate(
|
let res = ffi::secp256k1_ec_seckey_negate(
|
||||||
|
@ -272,6 +273,7 @@ impl SecretKey {
|
||||||
///
|
///
|
||||||
/// Returns an error if the resulting key would be invalid.
|
/// Returns an error if the resulting key would be invalid.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "you forgot to use the tweaked secret key"]
|
||||||
pub fn add_tweak(mut self, tweak: &Scalar) -> Result<SecretKey, Error> {
|
pub fn add_tweak(mut self, tweak: &Scalar) -> Result<SecretKey, Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if ffi::secp256k1_ec_seckey_tweak_add(
|
if ffi::secp256k1_ec_seckey_tweak_add(
|
||||||
|
@ -302,6 +304,7 @@ impl SecretKey {
|
||||||
///
|
///
|
||||||
/// Returns an error if the resulting key would be invalid.
|
/// Returns an error if the resulting key would be invalid.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "you forgot to use the tweaked secret key"]
|
||||||
pub fn mul_tweak(mut self, tweak: &Scalar) -> Result<SecretKey, Error> {
|
pub fn mul_tweak(mut self, tweak: &Scalar) -> Result<SecretKey, Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if ffi::secp256k1_ec_seckey_tweak_mul(
|
if ffi::secp256k1_ec_seckey_tweak_mul(
|
||||||
|
@ -536,6 +539,7 @@ impl PublicKey {
|
||||||
|
|
||||||
/// Negates the public key.
|
/// Negates the public key.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "you forgot to use the negated public key"]
|
||||||
pub fn negate<C: Verification>(mut self, secp: &Secp256k1<C>) -> PublicKey {
|
pub fn negate<C: Verification>(mut self, secp: &Secp256k1<C>) -> PublicKey {
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = ffi::secp256k1_ec_pubkey_negate(secp.ctx, &mut self.0);
|
let res = ffi::secp256k1_ec_pubkey_negate(secp.ctx, &mut self.0);
|
||||||
|
@ -566,6 +570,7 @@ impl PublicKey {
|
||||||
///
|
///
|
||||||
/// Returns an error if the resulting key would be invalid.
|
/// Returns an error if the resulting key would be invalid.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "you forgot to use the tweaked public key"]
|
||||||
pub fn add_exp_tweak<C: Verification>(
|
pub fn add_exp_tweak<C: Verification>(
|
||||||
mut self,
|
mut self,
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
|
@ -602,6 +607,7 @@ impl PublicKey {
|
||||||
///
|
///
|
||||||
/// Returns an error if the resulting key would be invalid.
|
/// Returns an error if the resulting key would be invalid.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "you forgot to use the tweaked public key"]
|
||||||
pub fn mul_tweak<C: Verification>(
|
pub fn mul_tweak<C: Verification>(
|
||||||
mut self,
|
mut self,
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
|
@ -971,6 +977,7 @@ impl KeyPair {
|
||||||
/// ```
|
/// ```
|
||||||
// TODO: Add checked implementation
|
// TODO: Add checked implementation
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "you forgot to use the tweaked key pair"]
|
||||||
pub fn add_xonly_tweak<C: Verification>(
|
pub fn add_xonly_tweak<C: Verification>(
|
||||||
mut self,
|
mut self,
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
|
@ -1270,6 +1277,7 @@ impl XOnlyPublicKey {
|
||||||
/// let tweaked = xonly.add_tweak(&secp, &tweak).expect("Improbable to fail with a randomly generated tweak");
|
/// let tweaked = xonly.add_tweak(&secp, &tweak).expect("Improbable to fail with a randomly generated tweak");
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use = "you forgot to use the tweaked xonly pubkey"]
|
||||||
pub fn add_tweak<V: Verification>(
|
pub fn add_tweak<V: Verification>(
|
||||||
mut self,
|
mut self,
|
||||||
secp: &Secp256k1<V>,
|
secp: &Secp256k1<V>,
|
||||||
|
|
Loading…
Reference in New Issue