key: Deprecate to_bytes
As we have been doing in other places deprecate `to_bytes` in favour of `to_vec`. Note this is only for functions that return a `Vec`, the `key` module has `CompressedKey::to_bytes` still as it returns an array.
This commit is contained in:
parent
3af3239ad0
commit
a51768af3f
|
@ -54,7 +54,7 @@ fn p2pk_pubkey_bytes_valid_key_and_valid_script_returns_expected_key() {
|
||||||
let key = key_str.parse::<PublicKey>().unwrap();
|
let key = key_str.parse::<PublicKey>().unwrap();
|
||||||
let p2pk = Script::builder().push_key(key).push_opcode(OP_CHECKSIG).into_script();
|
let p2pk = Script::builder().push_key(key).push_opcode(OP_CHECKSIG).into_script();
|
||||||
let actual = p2pk.p2pk_pubkey_bytes().unwrap();
|
let actual = p2pk.p2pk_pubkey_bytes().unwrap();
|
||||||
assert_eq!(actual.to_vec(), key.to_bytes());
|
assert_eq!(actual.to_vec(), key.to_vec());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -109,7 +109,7 @@ fn p2pk_pubkey_bytes_compressed_key_returns_expected_key() {
|
||||||
let key = compressed_key_str.parse::<PublicKey>().unwrap();
|
let key = compressed_key_str.parse::<PublicKey>().unwrap();
|
||||||
let p2pk = Script::builder().push_key(key).push_opcode(OP_CHECKSIG).into_script();
|
let p2pk = Script::builder().push_key(key).push_opcode(OP_CHECKSIG).into_script();
|
||||||
let actual = p2pk.p2pk_pubkey_bytes().unwrap();
|
let actual = p2pk.p2pk_pubkey_bytes().unwrap();
|
||||||
assert_eq!(actual.to_vec(), key.to_bytes());
|
assert_eq!(actual.to_vec(), key.to_vec());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -110,7 +110,11 @@ impl PublicKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serializes the public key to bytes.
|
/// Serializes the public key to bytes.
|
||||||
pub fn to_bytes(self) -> Vec<u8> {
|
#[deprecated(since = "TBD", note = "use to_vec instead")]
|
||||||
|
pub fn to_bytes(self) -> Vec<u8> { self.to_vec() }
|
||||||
|
|
||||||
|
/// Serializes the public key to bytes.
|
||||||
|
pub fn to_vec(self) -> Vec<u8> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
self.write_into(&mut buf).expect("vecs don't error");
|
self.write_into(&mut buf).expect("vecs don't error");
|
||||||
buf
|
buf
|
||||||
|
@ -442,8 +446,13 @@ impl PrivateKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Serializes the private key to bytes.
|
/// Serializes the private key to bytes.
|
||||||
pub fn to_bytes(self) -> Vec<u8> { self.inner[..].to_vec() }
|
#[deprecated(since = "TBD", note = "use to_vec instead")]
|
||||||
|
pub fn to_bytes(self) -> Vec<u8> { self.to_vec() }
|
||||||
|
|
||||||
|
/// Serializes the private key to bytes.
|
||||||
|
pub fn to_vec(self) -> Vec<u8> { self.inner[..].to_vec() }
|
||||||
|
|
||||||
/// Deserializes a private key from a slice.
|
/// Deserializes a private key from a slice.
|
||||||
pub fn from_slice(
|
pub fn from_slice(
|
||||||
|
|
Loading…
Reference in New Issue