Skip to content
Permalink
Browse files

add extra debugging messages

  • Loading branch information...
vincenthz committed May 15, 2019
1 parent f441bd3 commit de8b5302e856692e0ce7863d3508a9d856fc151b
@@ -93,7 +93,10 @@ impl VerificationAlgorithm for Ed25519 {

fn signature_from_bytes(data: &[u8]) -> Result<Self::Signature, SignatureError> {
if data.len() != ed25519::SIGNATURE_LENGTH {
return Err(SignatureError::SizeInvalid);
return Err(SignatureError::SizeInvalid {
expected: ed25519::SIGNATURE_LENGTH,
got: data.len(),
});
}
let mut buf = [0; ed25519::SIGNATURE_LENGTH];
buf[0..ed25519::SIGNATURE_LENGTH].clone_from_slice(data);
@@ -62,7 +62,10 @@ impl SecretKeySizeStatic for Ed25519Bip32 {
impl From<i::SignatureError> for SignatureError {
fn from(v: i::SignatureError) -> Self {
match v {
i::SignatureError::InvalidLength(_) => SignatureError::SizeInvalid,
i::SignatureError::InvalidLength(got) => SignatureError::SizeInvalid {
expected: ed25519_bip32::SIGNATURE_SIZE,
got: got,
},
}
}
}
@@ -83,7 +83,10 @@ impl VerificationAlgorithm for Ed25519Extended {

fn signature_from_bytes(data: &[u8]) -> Result<Self::Signature, SignatureError> {
if data.len() != ed25519::SIGNATURE_LENGTH {
return Err(SignatureError::SizeInvalid);
return Err(SignatureError::SizeInvalid {
expected: ed25519::SIGNATURE_LENGTH,
got: data.len(),
});
}
let mut buf = [0; ed25519::SIGNATURE_LENGTH];
buf[0..ed25519::SIGNATURE_LENGTH].clone_from_slice(data);
@@ -80,7 +80,10 @@ impl VerificationAlgorithm for FakeMMM {

fn signature_from_bytes(data: &[u8]) -> Result<Self::Signature, SignatureError> {
if data.len() != ed25519::SIGNATURE_LENGTH {
return Err(SignatureError::SizeInvalid);
return Err(SignatureError::SizeInvalid {
expected: ed25519::SIGNATURE_LENGTH,
got: data.len(),
});
}
let mut buf = [0; ed25519::SIGNATURE_LENGTH];
buf[0..ed25519::SIGNATURE_LENGTH].clone_from_slice(data);
@@ -60,7 +60,10 @@ impl VerificationAlgorithm for SumEd25519_12 {

fn signature_from_bytes(data: &[u8]) -> Result<Self::Signature, SignatureError> {
sum::Signature::from_bytes(DEPTH, data).map_err(|e| match e {
sum::Error::InvalidSignatureSize(_) => SignatureError::SizeInvalid,
sum::Error::InvalidSignatureSize(_) => SignatureError::SizeInvalid {
expected: Self::SIGNATURE_SIZE,
got: data.len(),
},
_ => SignatureError::StructureInvalid,
})
}
@@ -465,7 +465,7 @@ impl Signature {
return Err(Error::InvalidSignatureSize(bytes.len()));
}
let found_depth = (bytes.len() - minimum_size) / 32;
if found_depth == depth.0 {
if found_depth != depth.0 {
return Err(Error::InvalidSignatureSize(bytes.len()));
}

@@ -720,6 +720,9 @@ mod tests {
if sk.is_updatable() {
update(&mut sk).unwrap();
}

let sigdata = sig.as_bytes();
assert_eq!(signature_size(depth), sigdata.len())
}
}

@@ -21,7 +21,7 @@ impl From<bool> for Verification {

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SignatureError {
SizeInvalid,
SizeInvalid { expected: usize, got: usize }, // expected, got in bytes
StructureInvalid,
}

@@ -59,7 +59,11 @@ impl<A: VerificationAlgorithm, T> fmt::Display for Signature<T, A> {
impl fmt::Display for SignatureError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
SignatureError::SizeInvalid => write!(f, "Invalid Signature size"),
SignatureError::SizeInvalid { expected, got } => write!(
f,
"Invalid Signature size expecting {} got {}",
expected, got
),
SignatureError::StructureInvalid => write!(f, "Invalid Signature structure"),
}
}
@@ -30,9 +30,9 @@ fn chain_crypto_pub_err(e: crypto::PublicKeyError) -> ReadError {
}
fn chain_crypto_sig_err(e: crypto::SignatureError) -> ReadError {
match e {
crypto::SignatureError::SizeInvalid => {
ReadError::StructureInvalid("signature size invalid".to_string())
}
crypto::SignatureError::SizeInvalid { expected, got } => ReadError::StructureInvalid(
format!("signature size invalid, expected {} got {}", expected, got),
),
crypto::SignatureError::StructureInvalid => {
ReadError::StructureInvalid("signature structure invalid".to_string())
}

0 comments on commit de8b530

Please sign in to comment.
You can’t perform that action at this time.