key: add some missing functionality
This commit is contained in:
parent
4bf99e79f8
commit
fc47c477ab
|
@ -17,7 +17,7 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::io;
|
use std::{io, ops};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use secp256k1::{self, Secp256k1};
|
use secp256k1::{self, Secp256k1};
|
||||||
use consensus::encode;
|
use consensus::encode;
|
||||||
|
@ -35,7 +35,7 @@ pub struct PublicKey {
|
||||||
|
|
||||||
impl PublicKey {
|
impl PublicKey {
|
||||||
/// Write the public key into a writer
|
/// Write the public key into a writer
|
||||||
pub fn write_into<W: io::Write>(&self, writer: &mut W) {
|
pub fn write_into<W: io::Write>(&self, mut writer: W) {
|
||||||
let write_res: io::Result<()> = if self.compressed {
|
let write_res: io::Result<()> = if self.compressed {
|
||||||
writer.write_all(&self.key.serialize())
|
writer.write_all(&self.key.serialize())
|
||||||
} else {
|
} else {
|
||||||
|
@ -64,7 +64,7 @@ impl PublicKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
/// A Bitcoin ECDSA private key
|
/// A Bitcoin ECDSA private key
|
||||||
pub struct PrivateKey {
|
pub struct PrivateKey {
|
||||||
/// Whether this private key should be serialized as compressed
|
/// Whether this private key should be serialized as compressed
|
||||||
|
@ -152,6 +152,13 @@ impl FromStr for PrivateKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ops::Index<ops::RangeFull> for PrivateKey {
|
||||||
|
type Output = [u8];
|
||||||
|
fn index(&self, _: ops::RangeFull) -> &[u8] {
|
||||||
|
&self.key[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::PrivateKey;
|
use super::PrivateKey;
|
||||||
|
|
Loading…
Reference in New Issue