From 3cc6c7e080c6ce3a982ddcf598b449222baeba3c Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Mon, 15 May 2023 13:39:54 +0200 Subject: [PATCH] feat(identity): remove deprecated items Related: https://github.com/libp2p/rust-libp2p/issues/3647. Pull-Request: #3928. --- identity/CHANGELOG.md | 3 ++ identity/src/ecdsa.rs | 27 ------------- identity/src/ed25519.rs | 51 ------------------------- identity/src/keypair.rs | 80 --------------------------------------- identity/src/rsa.rs | 19 ---------- identity/src/secp256k1.rs | 40 -------------------- 6 files changed, 3 insertions(+), 217 deletions(-) diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index cbfb817c..d808b466 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -11,10 +11,13 @@ - Remove `identity::secp256k1::SecretKey::sign_hash` and make `identity::secp256k1::SecretKey::sign` infallible. See [PR 3850]. +- Remove deprecated items. See [PR 3928]. + [PR 3850]: https://github.com/libp2p/rust-libp2p/pull/3850 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 [PR 3863]: https://github.com/libp2p/rust-libp2p/pull/3863 [PR 3866]: https://github.com/libp2p/rust-libp2p/pull/3866 +[PR 3928]: https://github.com/libp2p/rust-libp2p/pull/3928 [protobuf format]: https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#keys ## 0.1.2 diff --git a/identity/src/ecdsa.rs b/identity/src/ecdsa.rs index 90a8c308..21970f2f 100644 --- a/identity/src/ecdsa.rs +++ b/identity/src/ecdsa.rs @@ -109,15 +109,6 @@ impl SecretKey { self.0.to_bytes().to_vec() } - /// Decode a secret key from a byte buffer containing raw scalar of the key. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `SecretKey::try_from_bytes` instead" - )] - pub fn from_bytes(buf: &[u8]) -> Result { - Self::try_from_bytes(buf) - } - /// Try to parse a secret key from a byte buffer containing raw scalar of the key. pub fn try_from_bytes(buf: impl AsRef<[u8]>) -> Result { SigningKey::from_bytes(buf.as_ref().into()) @@ -166,15 +157,6 @@ impl PublicKey { self.0.verify(msg, &sig).is_ok() } - /// Decode a public key from a byte buffer containing raw components of a key with or without compression. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_from_bytes` instead." - )] - pub fn from_bytes(k: &[u8]) -> Result { - Self::try_from_bytes(k) - } - /// Try to parse a public key from a byte buffer containing raw components of a key with or without compression. pub fn try_from_bytes(k: &[u8]) -> Result { let enc_pt = EncodedPoint::from_bytes(k) @@ -196,15 +178,6 @@ impl PublicKey { Self::add_asn1_header(&buf) } - /// Decode a public key into a DER encoded byte buffer as defined by SEC1 standard. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_decode_der` instead." - )] - pub fn decode_der(k: &[u8]) -> Result { - Self::try_decode_der(k) - } - /// Try to decode a public key from a DER encoded byte buffer as defined by SEC1 standard. pub fn try_decode_der(k: &[u8]) -> Result { let buf = Self::del_asn1_header(k).ok_or_else(|| { diff --git a/identity/src/ed25519.rs b/identity/src/ed25519.rs index 90782de3..bcd3eb44 100644 --- a/identity/src/ed25519.rs +++ b/identity/src/ed25519.rs @@ -38,14 +38,6 @@ impl Keypair { Keypair::from(SecretKey::generate()) } - /// Encode the keypair into a byte array by concatenating the bytes - /// of the secret scalar and the compressed public point, - /// an informal standard for encoding Ed25519 keypairs. - #[deprecated(since = "0.2.0", note = "Renamed to `Keypair::to_bytes`")] - pub fn encode(&self) -> [u8; 64] { - self.to_bytes() - } - /// Convert the keypair into a byte array by concatenating the bytes /// of the secret scalar and the compressed public point, /// an informal standard for encoding Ed25519 keypairs. @@ -53,18 +45,6 @@ impl Keypair { self.0.to_bytes() } - /// Decode a keypair from the [binary format](https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.5) - /// produced by [`Keypair::to_bytes`], zeroing the input on success. - /// - /// Note that this binary format is the same as `ed25519_dalek`'s and `ed25519_zebra`'s. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `Keypair::try_from_bytes` instead." - )] - pub fn decode(kp: &mut [u8]) -> Result { - Self::try_from_bytes(kp) - } - /// Try to parse a keypair from the [binary format](https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.5) /// produced by [`Keypair::to_bytes`], zeroing the input on success. /// @@ -182,31 +162,12 @@ impl PublicKey { .is_ok() } - /// Encode the public key into a byte array in compressed form, i.e. - /// where one coordinate is represented by a single bit. - #[deprecated( - since = "0.2.0", - note = "Renamed to `PublicKey::to_bytes` to reflect actual behaviour." - )] - pub fn encode(&self) -> [u8; 32] { - self.to_bytes() - } - /// Convert the public key to a byte array in compressed form, i.e. /// where one coordinate is represented by a single bit. pub fn to_bytes(&self) -> [u8; 32] { self.0.to_bytes() } - /// Decode a public key from a byte array as produced by `to_bytes`. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_from_bytes` instead." - )] - pub fn decode(k: &[u8]) -> Result { - Self::try_from_bytes(k) - } - /// Try to parse a public key from a byte array containing the actual key as produced by `to_bytes`. pub fn try_from_bytes(k: &[u8]) -> Result { ed25519::PublicKey::from_bytes(k) @@ -251,18 +212,6 @@ impl SecretKey { ) } - /// Create an Ed25519 secret key from a byte slice, zeroing the input on success. - /// If the bytes do not constitute a valid Ed25519 secret key, an error is - /// returned. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `SecretKey::try_from_bytes` instead." - )] - #[allow(unused_mut)] - pub fn from_bytes(mut sk_bytes: impl AsMut<[u8]>) -> Result { - Self::try_from_bytes(sk_bytes) - } - /// Try to parse an Ed25519 secret key from a byte slice /// containing the actual key, zeroing the input on success. /// If the bytes do not constitute a valid Ed25519 secret key, an error is diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index 8249cbe9..b31949cf 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -106,53 +106,21 @@ impl Keypair { } } - #[cfg(feature = "ed25519")] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_ed25519` instead." - )] - pub fn into_ed25519(self) -> Option { - self.try_into().ok() - } - #[cfg(feature = "ed25519")] pub fn try_into_ed25519(self) -> Result { self.try_into() } - #[cfg(feature = "secp256k1")] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_secp256k1` instead." - )] - pub fn into_secp256k1(self) -> Option { - self.try_into().ok() - } - #[cfg(feature = "secp256k1")] pub fn try_into_secp256k1(self) -> Result { self.try_into() } - #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_rsa` instead." - )] - pub fn into_rsa(self) -> Option { - self.try_into().ok() - } - #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] pub fn try_into_rsa(self) -> Result { self.try_into() } - #[cfg(feature = "ecdsa")] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_ecdsa` instead." - )] - pub fn into_ecdsa(self) -> Option { - self.try_into().ok() - } - #[cfg(feature = "ecdsa")] pub fn try_into_ecdsa(self) -> Result { self.try_into() @@ -480,65 +448,26 @@ impl PublicKey { } } - #[cfg(feature = "ed25519")] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_ed25519` instead." - )] - pub fn into_ed25519(self) -> Option { - self.try_into().ok() - } - #[cfg(feature = "ed25519")] pub fn try_into_ed25519(self) -> Result { self.try_into() } - #[cfg(feature = "secp256k1")] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_secp256k1` instead." - )] - pub fn into_secp256k1(self) -> Option { - self.try_into().ok() - } - #[cfg(feature = "secp256k1")] pub fn try_into_secp256k1(self) -> Result { self.try_into() } - #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_rsa` instead." - )] - pub fn into_rsa(self) -> Option { - self.try_into().ok() - } - #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] pub fn try_into_rsa(self) -> Result { self.try_into() } - #[cfg(feature = "ecdsa")] - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_ecdsa` instead." - )] - pub fn into_ecdsa(self) -> Option { - self.try_into().ok() - } - #[cfg(feature = "ecdsa")] pub fn try_into_ecdsa(self) -> Result { self.try_into() } - /// Encode the public key into a protobuf structure for storage or - /// exchange with other nodes. - #[deprecated(note = "Renamed to `PublicKey::encode_protobuf`.")] - pub fn to_protobuf_encoding(&self) -> Vec { - Self::encode_protobuf(self) - } - /// Encode the public key into a protobuf structure for storage or /// exchange with other nodes. pub fn encode_protobuf(&self) -> Vec { @@ -570,15 +499,6 @@ impl PublicKey { unreachable!() } - /// Decode a public key from a protobuf structure, e.g. read from storage - /// or received from another node. - #[deprecated( - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_decode_protobuf` instead." - )] - pub fn from_protobuf_encoding(bytes: &[u8]) -> Result { - Self::try_decode_protobuf(bytes) - } - /// Decode a public key from a protobuf structure, e.g. read from storage /// or received from another node. #[allow(unused_variables)] diff --git a/identity/src/rsa.rs b/identity/src/rsa.rs index e4e16af2..05bd5c4c 100644 --- a/identity/src/rsa.rs +++ b/identity/src/rsa.rs @@ -42,15 +42,6 @@ impl std::fmt::Debug for Keypair { } impl Keypair { - /// Decode an RSA keypair from a DER-encoded private key in PKCS#8 PrivateKeyInfo - /// format (i.e. unencrypted) as defined in [RFC5208]. - /// - /// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5 - #[deprecated(since = "0.2.0", note = "Renamed to `Keypair::try_decode_pkcs8`.")] - pub fn from_pkcs8(der: &mut [u8]) -> Result { - Self::try_decode_pkcs8(der) - } - /// Decode an RSA keypair from a DER-encoded private key in PKCS#8 PrivateKeyInfo /// format (i.e. unencrypted) as defined in [RFC5208]. /// @@ -116,16 +107,6 @@ impl PublicKey { .expect("RSA X.509 public key encoding failed.") } - /// Decode an RSA public key from a DER-encoded X.509 SubjectPublicKeyInfo - /// structure. See also `encode_x509`. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_decode_x509` instead." - )] - pub fn decode_x509(pk: &[u8]) -> Result { - Self::try_decode_x509(pk) - } - /// Decode an RSA public key from a DER-encoded X.509 SubjectPublicKeyInfo /// structure. See also `encode_x509`. pub fn try_decode_x509(pk: &[u8]) -> Result { diff --git a/identity/src/secp256k1.rs b/identity/src/secp256k1.rs index 0fe48d38..a32a64e7 100644 --- a/identity/src/secp256k1.rs +++ b/identity/src/secp256k1.rs @@ -92,20 +92,6 @@ impl SecretKey { SecretKey(libsecp256k1::SecretKey::random(&mut rand::thread_rng())) } - /// Create a secret key from a byte slice, zeroing the slice on success. - /// If the bytes do not constitute a valid Secp256k1 secret key, an - /// error is returned. - /// - /// Note that the expected binary format is the same as `libsecp256k1`'s. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `SecretKey::try_from_bytes` instead." - )] - #[allow(unused_mut)] - pub fn from_bytes(mut sk: impl AsMut<[u8]>) -> Result { - Self::try_from_bytes(sk) - } - /// Create a secret key from a byte slice, zeroing the slice on success. /// If the bytes do not constitute a valid Secp256k1 secret key, an /// error is returned. @@ -215,43 +201,17 @@ impl PublicKey { .unwrap_or(false) } - /// Encode the public key in compressed form, i.e. with one coordinate - /// represented by a single bit. - #[deprecated(since = "0.2.0", note = "Renamed to `PublicKey::to_bytes`.")] - pub fn encode(&self) -> [u8; 33] { - self.to_bytes() - } - /// Convert the public key to a byte buffer in compressed form, i.e. with one coordinate /// represented by a single bit. pub fn to_bytes(&self) -> [u8; 33] { self.0.serialize_compressed() } - /// Encode the public key in uncompressed form. - #[deprecated( - since = "0.2.0", - note = "Renamed to `PublicKey::to_bytes_uncompressed`." - )] - pub fn encode_uncompressed(&self) -> [u8; 65] { - self.to_bytes_uncompressed() - } - /// Convert the public key to a byte buffer in uncompressed form. pub fn to_bytes_uncompressed(&self) -> [u8; 65] { self.0.serialize() } - /// Decode a public key from a byte slice in the the format produced - /// by `encode`. - #[deprecated( - since = "0.2.0", - note = "This method name does not follow Rust naming conventions, use `PublicKey::try_from_bytes` instead." - )] - pub fn decode(k: &[u8]) -> Result { - Self::try_from_bytes(k) - } - /// Decode a public key from a byte slice in the the format produced /// by `encode`. pub fn try_from_bytes(k: &[u8]) -> Result {