Strict encoding for SecretKey
@@ -65,6 +65,23 @@ impl StrictDecode for Script {
}
}
+impl StrictEncode for secp256k1::SecretKey {
+ #[inline]
+ fn strict_encode<E: io::Write>(&self, mut e: E) -> Result<usize, Error> {
+ Ok(e.write(&self[..])?)
+ }
+}
+
+impl StrictDecode for secp256k1::SecretKey {
+ #[inline]
+ fn strict_decode<D: io::Read>(mut d: D) -> Result<Self, Self::Error> {
+ let mut buf = [0u8; secp256k1::constants::SECRET_KEY_SIZE];
+ d.read_exact(&mut buf)?;
+ Ok(Self::from_slice(&buf)
+ .map_err(|_| Error::DataIntegrityError("invalid private key data".to_string()))?)
+ }
+}
+
impl StrictEncode for secp256k1::PublicKey {
#[inline]
fn strict_encode<E: io::Write>(&self, mut e: E) -> Result<usize, Error> {
