Merge pull request #243 from stevenroose/pubkey-serialize
util:🔑 Provide to_bytes() methods for key types
This commit is contained in:
commit
221e53b13e
|
@ -44,6 +44,13 @@ impl PublicKey {
|
||||||
debug_assert!(write_res.is_ok());
|
debug_assert!(write_res.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serialize the public key to bytes
|
||||||
|
pub fn to_bytes(&self) -> Vec<u8> {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
self.write_into(&mut buf);
|
||||||
|
buf
|
||||||
|
}
|
||||||
|
|
||||||
/// Deserialize a public key from a slice
|
/// Deserialize a public key from a slice
|
||||||
pub fn from_slice(data: &[u8]) -> Result<PublicKey, encode::Error> {
|
pub fn from_slice(data: &[u8]) -> Result<PublicKey, encode::Error> {
|
||||||
let compressed: bool = match data.len() {
|
let compressed: bool = match data.len() {
|
||||||
|
@ -110,6 +117,11 @@ impl PrivateKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serialize the private key to bytes
|
||||||
|
pub fn to_bytes(&self) -> Vec<u8> {
|
||||||
|
self.key[..].to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
/// Format the private key to WIF format.
|
/// Format the private key to WIF format.
|
||||||
pub fn fmt_wif(&self, fmt: &mut fmt::Write) -> fmt::Result {
|
pub fn fmt_wif(&self, fmt: &mut fmt::Write) -> fmt::Result {
|
||||||
let mut ret = [0; 34];
|
let mut ret = [0; 34];
|
||||||
|
|
Loading…
Reference in New Issue