Sctrict encoding: schnorr public keys & signatures
@@ -156,6 +156,24 @@ impl StrictDecode for secp256k1::PublicKey {
}
}
+impl StrictEncode for secp256k1::schnorrsig::PublicKey {
+ #[inline]
+ fn strict_encode<E: io::Write>(&self, mut e: E) -> Result<usize, Error> {
+ Ok(e.write(&self.serialize())?)
+ }
+}
+
+impl StrictDecode for secp256k1::schnorrsig::PublicKey {
+ #[inline]
+ fn strict_decode<D: io::Read>(mut d: D) -> Result<Self, Error> {
+ let mut buf = [0u8; secp256k1::constants::SCHNORRSIG_PUBLIC_KEY_SIZE];
+ d.read_exact(&mut buf)?;
+ Ok(Self::from_slice(&buf).map_err(|_| {
+ Error::DataIntegrityError("invalid public key data".to_string())
+ })?)
+ }
+}
+
impl StrictEncode for secp256k1::Signature {
#[inline]
fn strict_encode<E: io::Write>(&self, mut e: E) -> Result<usize, Error> {
@@ -176,6 +194,26 @@ impl StrictDecode for secp256k1::Signature {
}
}
+impl StrictEncode for secp256k1::schnorrsig::Signature {
+ #[inline]
+ fn strict_encode<E: io::Write>(&self, mut e: E) -> Result<usize, Error> {
+ Ok(e.write(&self[..])?)
+ }
+}
+
+impl StrictDecode for secp256k1::schnorrsig::Signature {
+ #[inline]
+ fn strict_decode<D: io::Read>(mut d: D) -> Result<Self, Error> {
+ let mut buf = [0u8; secp256k1::constants::SCHNORRSIG_SIGNATURE_SIZE];
+ d.read_exact(&mut buf)?;
+ Ok(Self::from_slice(&buf).map_err(|_| {
+ Error::DataIntegrityError(
+ "Invalid secp256k1 signature data".to_string(),
+ )
+ })?)
+ }
+}
+
impl StrictEncode for bitcoin::PublicKey {
#[inline]
fn strict_encode<E: io::Write>(&self, mut e: E) -> Result<usize, Error> {
