diff --git a/core/src/signed_envelope.rs b/core/src/signed_envelope.rs index 754d6ec204d..d0af6a2b737 100644 --- a/core/src/signed_envelope.rs +++ b/core/src/signed_envelope.rs @@ -28,7 +28,7 @@ impl SignedEnvelope { ) -> Result { let buffer = signature_payload(domain_separation, &payload_type, &payload); - let signature = key.sign(&buffer)?; + let signature = key.sign(&buffer).unwrap(); Ok(Self { key: key.public(), diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index a1bbba00fa9..c44d01c4360 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -18,6 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use std::convert::Infallible; + #[cfg(any( feature = "ecdsa", feature = "secp256k1", @@ -176,12 +178,12 @@ impl Keypair { /// Sign a message using the private key of this keypair, producing /// a signature that can be verified using the corresponding public key. #[allow(unused_variables)] - pub fn sign(&self, msg: &[u8]) -> Result, SigningError> { + pub fn sign(&self, msg: &[u8]) -> Result, Infallible> { match self.keypair { #[cfg(feature = "ed25519")] KeyPairInner::Ed25519(ref pair) => Ok(pair.sign(msg)), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - KeyPairInner::Rsa(ref pair) => pair.sign(msg), + KeyPairInner::Rsa(ref pair) => Ok(pair.sign(msg)), #[cfg(feature = "secp256k1")] KeyPairInner::Secp256k1(ref pair) => Ok(pair.secret().sign(msg)), #[cfg(feature = "ecdsa")] diff --git a/identity/src/rsa.rs b/identity/src/rsa.rs index b14d8c66d86..8a08259fff5 100644 --- a/identity/src/rsa.rs +++ b/identity/src/rsa.rs @@ -75,12 +75,12 @@ impl Keypair { } /// Sign a message with this keypair. - pub fn sign(&self, data: &[u8]) -> Result, SigningError> { + pub fn sign(&self, data: &[u8]) -> Vec { let mut signature = vec![0; self.0.public().modulus_len()]; let rng = SystemRandom::new(); match self.0.sign(&RSA_PKCS1_SHA256, &rng, data, &mut signature) { - Ok(()) => Ok(signature), - Err(e) => Err(SigningError::new("RSA").source(e)), + Ok(()) => signature, + Err(_) => unreachable!("length of pubkey remain unchanged with immutability"), } } } @@ -359,7 +359,7 @@ mod tests { #[test] fn rsa_sign_verify() { fn prop(SomeKeypair(kp): SomeKeypair, msg: Vec) -> Result { - kp.sign(&msg).map(|s| kp.public().verify(&msg, &s)) + Ok(kp.public().verify(&msg, &kp.sign(&msg))) } QuickCheck::new() .tests(10) diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index b803337462d..f24ec28279f 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -2756,7 +2756,7 @@ where // the signature is over the bytes "libp2p-pubsub:" let mut signature_bytes = SIGNING_PREFIX.to_vec(); signature_bytes.extend_from_slice(&buf); - Some(keypair.sign(&signature_bytes)?) + Some(keypair.sign(&signature_bytes).unwrap()) }; Ok(RawMessage { diff --git a/transports/noise/src/protocol.rs b/transports/noise/src/protocol.rs index ca47ea0dfcd..3e562a549fe 100644 --- a/transports/noise/src/protocol.rs +++ b/transports/noise/src/protocol.rs @@ -90,7 +90,7 @@ impl Keypair { self, id_keys: &identity::Keypair, ) -> Result { - let sig = id_keys.sign(&[STATIC_KEY_DOMAIN.as_bytes(), self.public.as_ref()].concat())?; + let sig = id_keys.sign(&[STATIC_KEY_DOMAIN.as_bytes(), self.public.as_ref()].concat()).unwrap(); let identity = KeypairIdentity { public: id_keys.public(),