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

feat(identity): remove deprecated items #3928

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions identity/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, DecodingError> {
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<SecretKey, DecodingError> {
SigningKey::from_bytes(buf.as_ref().into())
Expand Down Expand Up @@ -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<PublicKey, DecodingError> {
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<PublicKey, DecodingError> {
let enc_pt = EncodedPoint::from_bytes(k)
Expand All @@ -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<PublicKey, DecodingError> {
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<PublicKey, DecodingError> {
let buf = Self::del_asn1_header(k).ok_or_else(|| {
Expand Down
51 changes: 0 additions & 51 deletions identity/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,13 @@ 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.
pub fn to_bytes(&self) -> [u8; 64] {
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<Keypair, DecodingError> {
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.
///
Expand Down Expand Up @@ -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<PublicKey, DecodingError> {
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<PublicKey, DecodingError> {
ed25519::PublicKey::from_bytes(k)
Expand Down Expand Up @@ -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<SecretKey, DecodingError> {
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
Expand Down
80 changes: 0 additions & 80 deletions identity/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ed25519::Keypair> {
self.try_into().ok()
}

#[cfg(feature = "ed25519")]
pub fn try_into_ed25519(self) -> Result<ed25519::Keypair, OtherVariantError> {
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<secp256k1::Keypair> {
self.try_into().ok()
}

#[cfg(feature = "secp256k1")]
pub fn try_into_secp256k1(self) -> Result<secp256k1::Keypair, OtherVariantError> {
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<rsa::Keypair> {
self.try_into().ok()
}

#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
pub fn try_into_rsa(self) -> Result<rsa::Keypair, OtherVariantError> {
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<ecdsa::Keypair> {
self.try_into().ok()
}

#[cfg(feature = "ecdsa")]
pub fn try_into_ecdsa(self) -> Result<ecdsa::Keypair, OtherVariantError> {
self.try_into()
Expand Down Expand Up @@ -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<ed25519::PublicKey> {
self.try_into().ok()
}

#[cfg(feature = "ed25519")]
pub fn try_into_ed25519(self) -> Result<ed25519::PublicKey, OtherVariantError> {
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<secp256k1::PublicKey> {
self.try_into().ok()
}

#[cfg(feature = "secp256k1")]
pub fn try_into_secp256k1(self) -> Result<secp256k1::PublicKey, OtherVariantError> {
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<rsa::PublicKey> {
self.try_into().ok()
}

#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
pub fn try_into_rsa(self) -> Result<rsa::PublicKey, OtherVariantError> {
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<ecdsa::PublicKey> {
self.try_into().ok()
}

#[cfg(feature = "ecdsa")]
pub fn try_into_ecdsa(self) -> Result<ecdsa::PublicKey, OtherVariantError> {
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<u8> {
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<u8> {
Expand Down Expand Up @@ -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<PublicKey, DecodingError> {
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)]
Expand Down
19 changes: 0 additions & 19 deletions identity/src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Keypair, DecodingError> {
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].
///
Expand Down Expand Up @@ -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<PublicKey, DecodingError> {
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<PublicKey, DecodingError> {
Expand Down
40 changes: 0 additions & 40 deletions identity/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SecretKey, DecodingError> {
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.
Expand Down Expand Up @@ -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<PublicKey, DecodingError> {
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<PublicKey, DecodingError> {
Expand Down