diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..731d071 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,4 +19,6 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: | + cargo test --verbose + cargo test --verbose --all-targets --all-features diff --git a/Cargo.toml b/Cargo.toml index 1e626cb..457e6d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,12 +18,24 @@ multibase = { version = "1.0", git = "https://github.com/cryptidtech/rust-multib multicodec = { version = "1.0", git = "https://github.com/cryptidtech/rust-multicodec.git" } multitrait = { version = "1.0", git = "https://github.com/cryptidtech/multitrait.git" } multiutil = { version = "1.0", git = "https://github.com/cryptidtech/multiutil.git" } -serde = { version = "1.0", default-features = false, features = ["alloc", "derive"], optional = true } -ssh-key = { version = "0.6", features = ["crypto"] } -ssh-encoding = "0.2" +serde = { version = "1.0", default-features = false, features = [ + "alloc", + "derive", +], optional = true } +ssh-encoding = { version = "0.2" } thiserror = "1.0" unsigned-varint = { version = "0.8", features = ["std"] } +[target.'cfg(target_arch = "wasm32")'.dependencies] +ssh-key = { version = "0.6", default-features = false, features = [ + "alloc", + "ecdsa", + "ed25519", +] } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +ssh-key = { version = "0.6", features = ["crypto"] } + [dev-dependencies] hex = "0.4" serde_test = "1.0" diff --git a/src/error.rs b/src/error.rs index e101ecd..cb08db7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + // SPDX-License-Idnetifier: Apache-2.0 /// Errors created by this library #[derive(Clone, Debug, thiserror::Error)] @@ -125,10 +127,39 @@ pub enum SharesError { #[derive(Clone, Debug, thiserror::Error)] #[non_exhaustive] pub enum ConversionsError { - /// Ssh signature conversion error - #[error(transparent)] - SshSig(#[from] ssh_key::Error), - /// Ssh label error + /// Ssh conversion error #[error(transparent)] - SshSigLabel(#[from] ssh_encoding::LabelError), + Ssh(#[from] SshError), +} + +/// SSH Errors +#[derive(Clone, Debug)] +pub enum SshError { + /// SSH Sig + Sig(ssh_key::Error), + /// SSH Sig label + SigLabel(ssh_encoding::LabelError), +} + +impl Display for SshError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SshError::Sig(e) => write!(f, "SSH Sig error: {}", e), + SshError::SigLabel(e) => write!(f, "SSH Sig label error: {}", e), + } + } +} + +impl std::error::Error for SshError {} + +impl From for SshError { + fn from(e: ssh_key::Error) -> Self { + SshError::Sig(e) + } +} + +impl From for SshError { + fn from(e: ssh_encoding::LabelError) -> Self { + SshError::SigLabel(e) + } } diff --git a/src/ms.rs b/src/ms.rs index f39f839..71ef355 100644 --- a/src/ms.rs +++ b/src/ms.rs @@ -23,15 +23,15 @@ pub const SIG_CODECS: [Codec; 4] = [ // Codec::Es384Msig, // Codec::Es521Msig, // Codec::Rs256Msig, - Codec::Es256KMsig//, - //Codec::LamportMsig, + Codec::Es256KMsig, //, + //Codec::LamportMsig, ]; /// the list of signature share codecs supported pub const SIG_SHARE_CODECS: [Codec; 2] = [ Codec::Bls12381G1ShareMsig, - Codec::Bls12381G2ShareMsig//, - //Codec::LamportShareMsig, + Codec::Bls12381G2ShareMsig, //, + //Codec::LamportShareMsig, ]; /// the multisig sigil diff --git a/src/views/bls12381.rs b/src/views/bls12381.rs index c40a58f..29364de 100644 --- a/src/views/bls12381.rs +++ b/src/views/bls12381.rs @@ -386,11 +386,11 @@ impl<'a> ConvView for View<'a> { Ok(ssh_key::Signature::new( ssh_key::Algorithm::Other( ssh_key::AlgorithmName::new(ALGORITHM_NAME_G1) - .map_err(|e| ConversionsError::SshSigLabel(e))?, + .map_err(|e| ConversionsError::Ssh(e.into()))?, ), sig_data, ) - .map_err(|e| ConversionsError::SshSig(e))?) + .map_err(|e| ConversionsError::Ssh(e.into()))?) } Codec::Bls12381G2Msig => { // create the combined sig tuple @@ -399,11 +399,11 @@ impl<'a> ConvView for View<'a> { Ok(ssh_key::Signature::new( ssh_key::Algorithm::Other( ssh_key::AlgorithmName::new(ALGORITHM_NAME_G2) - .map_err(|e| ConversionsError::SshSigLabel(e))?, + .map_err(|e| ConversionsError::Ssh(e.into()))?, ), sig_data, ) - .map_err(|e| ConversionsError::SshSig(e))?) + .map_err(|e| ConversionsError::Ssh(e.into()))?) } Codec::Bls12381G1ShareMsig => { // get the threshold attributes @@ -419,11 +419,11 @@ impl<'a> ConvView for View<'a> { Ok(ssh_key::Signature::new( ssh_key::Algorithm::Other( ssh_key::AlgorithmName::new(ALGORITHM_NAME_G1_SHARE) - .map_err(|e| ConversionsError::SshSigLabel(e))?, + .map_err(|e| ConversionsError::Ssh(e.into()))?, ), sig_data, ) - .map_err(|e| ConversionsError::SshSig(e))?) + .map_err(|e| ConversionsError::Ssh(e.into()))?) } Codec::Bls12381G2ShareMsig => { // get the threshold attributes @@ -439,11 +439,11 @@ impl<'a> ConvView for View<'a> { Ok(ssh_key::Signature::new( ssh_key::Algorithm::Other( ssh_key::AlgorithmName::new(ALGORITHM_NAME_G2_SHARE) - .map_err(|e| ConversionsError::SshSigLabel(e))?, + .map_err(|e| ConversionsError::Ssh(e.into()))?, ), sig_data, ) - .map_err(|e| ConversionsError::SshSig(e))?) + .map_err(|e| ConversionsError::Ssh(e.into()))?) } _ => Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())), } diff --git a/src/views/ed25519.rs b/src/views/ed25519.rs index fc4d0b1..0466c26 100644 --- a/src/views/ed25519.rs +++ b/src/views/ed25519.rs @@ -56,7 +56,7 @@ impl<'a> ConvView for View<'a> { let sig_bytes = dv.sig_bytes()?; Ok( ssh_key::Signature::new(ssh_key::Algorithm::Ed25519, sig_bytes) - .map_err(|e| ConversionsError::SshSig(e))?, + .map_err(|e| ConversionsError::Ssh(e.into()))?, ) } } diff --git a/src/views/secp256k1.rs b/src/views/secp256k1.rs index cd9f9c5..21bdeb3 100644 --- a/src/views/secp256k1.rs +++ b/src/views/secp256k1.rs @@ -6,7 +6,7 @@ use crate::{ use multicodec::Codec; /// the name used to identify these signatures in non-Multikey formats -pub const ALGORITHM_NAME: &'static str = "secp256k1@multisig"; +pub const ALGORITHM_NAME: &str = "secp256k1@multisig"; pub(crate) struct View<'a> { ms: &'a Multisig, @@ -60,10 +60,10 @@ impl<'a> ConvView for View<'a> { Ok(ssh_key::Signature::new( ssh_key::Algorithm::Other( ssh_key::AlgorithmName::new(ALGORITHM_NAME) - .map_err(|e| ConversionsError::SshSigLabel(e))?, + .map_err(|e| ConversionsError::Ssh(e.into()))?, ), sig_bytes, ) - .map_err(|e| ConversionsError::SshSig(e))?) + .map_err(|e| ConversionsError::Ssh(e.into()))?) } }