mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
improve error handling in cli (#7436)
* other error variant should carry a dyn Error * introduce thiserror for error derive, add explicit error variants, cleanup dependencies * cleanup handle dev-deps of sc-cli too * Update client/cli/src/error.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bernhard Schuster <bernhard@parity.io> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
3ac070b61e
commit
f373ecbcf0
@@ -77,27 +77,25 @@ fn verify<Pair>(sig_data: Vec<u8>, message: Vec<u8>, uri: &str) -> error::Result
|
||||
{
|
||||
let mut signature = Pair::Signature::default();
|
||||
if sig_data.len() != signature.as_ref().len() {
|
||||
return Err(error::Error::Other(format!(
|
||||
"signature has an invalid length. read {} bytes, expected {} bytes",
|
||||
sig_data.len(),
|
||||
signature.as_ref().len(),
|
||||
)));
|
||||
return Err(
|
||||
error::Error::SignatureInvalidLength {
|
||||
read: sig_data.len(),
|
||||
expected: signature.as_ref().len(),
|
||||
}
|
||||
);
|
||||
}
|
||||
signature.as_mut().copy_from_slice(&sig_data);
|
||||
|
||||
let pubkey = if let Ok(pubkey_vec) = hex::decode(uri) {
|
||||
Pair::Public::from_slice(pubkey_vec.as_slice())
|
||||
} else {
|
||||
Pair::Public::from_string(uri)
|
||||
.map_err(|_| {
|
||||
error::Error::Other(format!("Invalid URI; expecting either a secret URI or a public URI."))
|
||||
})?
|
||||
Pair::Public::from_string(uri)?
|
||||
};
|
||||
|
||||
if Pair::verify(&signature, &message, &pubkey) {
|
||||
println!("Signature verifies correctly.");
|
||||
} else {
|
||||
return Err(error::Error::Other("Signature invalid.".into()))
|
||||
return Err(error::Error::SignatureInvalid)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user