Skip to content

Commit 459b005

Browse files
committed
f Use From trait for errors
1 parent 1c94c64 commit 459b005

File tree

1 file changed

+11
-5
lines changed
  • secp256k1-zkp/src/schnorrsig

1 file changed

+11
-5
lines changed

secp256k1-zkp/src/schnorrsig/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ impl error::Error for Error {
4646
}
4747
}
4848

49+
impl From<schnorrsig_sys::Error> for Error {
50+
fn from(err: schnorrsig_sys::Error) -> Self {
51+
Error::SysError(err)
52+
}
53+
}
54+
4955
impl fmt::Display for Error {
5056
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
5157
match *self {
@@ -87,7 +93,7 @@ impl<C: Verification> Verify for Secp256k1<C> {
8793
pk: &PublicKey,
8894
) -> Result<(), Error> {
8995
schnorrsig_sys::Verify::schnorrsig_verify(self, msg, sig, pk)
90-
.map_err(|e| Error::SysError(e))
96+
.map_err(|e| e.into())
9197
}
9298
fn schnorrsig_verify_batch(
9399
&self,
@@ -97,7 +103,7 @@ impl<C: Verification> Verify for Secp256k1<C> {
97103
pks: &[PublicKey],
98104
) -> Result<(), Error> {
99105
if msgs.len() != sigs.len() || msgs.len() != pks.len() {
100-
return Err(Error::SysError(schnorrsig_sys::Error::ArgumentLength));
106+
return Err(schnorrsig_sys::Error::ArgumentLength.into());
101107
}
102108
let scratch_space = scratch_space.unwrap_or(ScratchSpace::new(self, 8192));
103109
let n = msgs.len();
@@ -116,13 +122,13 @@ impl<C: Verification> Verify for Secp256k1<C> {
116122
&sigptrs[..],
117123
&pkptrs[..],
118124
)
119-
.map_err(|e| Error::SysError(e))
125+
.map_err(|e| e.into())
120126
}
121127
}
122128

123129
#[cfg(test)]
124130
mod tests {
125-
use super::{Error, Sign, Signature, SysError, Verify};
131+
use super::{Sign, Signature, SysError, Verify};
126132
use rand::{thread_rng, RngCore};
127133
use secp256k1::{Message, Secp256k1};
128134
use secp256k1_zkp_dev::GenerateKeypair;
@@ -146,7 +152,7 @@ mod tests {
146152
);
147153
assert_eq!(
148154
s.schnorrsig_verify_batch(None, &[msg], &[], &[pk]),
149-
Err(Error::SysError(SysError::ArgumentLength))
155+
Err(SysError::ArgumentLength.into())
150156
);
151157
}
152158
}

0 commit comments

Comments
 (0)