diff --git a/src/util/key.rs b/src/util/key.rs index 2bcfdc91..e827c9aa 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -17,7 +17,7 @@ //! use std::fmt::{self, Write}; -use std::io; +use std::{io, ops}; use std::str::FromStr; use secp256k1::{self, Secp256k1}; use consensus::encode; @@ -35,7 +35,7 @@ pub struct PublicKey { impl PublicKey { /// Write the public key into a writer - pub fn write_into(&self, writer: &mut W) { + pub fn write_into(&self, mut writer: W) { let write_res: io::Result<()> = if self.compressed { writer.write_all(&self.key.serialize()) } else { @@ -64,7 +64,7 @@ impl PublicKey { } } -#[derive(Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq)] /// A Bitcoin ECDSA private key pub struct PrivateKey { /// Whether this private key should be serialized as compressed @@ -152,6 +152,13 @@ impl FromStr for PrivateKey { } } +impl ops::Index for PrivateKey { + type Output = [u8]; + fn index(&self, _: ops::RangeFull) -> &[u8] { + &self.key[..] + } +} + #[cfg(test)] mod tests { use super::PrivateKey;