Skip to content

Commit 8964981

Browse files
authored
Merge pull request #1 from DougAnderson444/wasm32
make `wasm32-*` compatible
2 parents bab8302 + 5260e72 commit 8964981

File tree

7 files changed

+70
-25
lines changed

7 files changed

+70
-25
lines changed

.github/workflows/rust.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ jobs:
1919
- name: Build
2020
run: cargo build --verbose
2121
- name: Run tests
22-
run: cargo test --verbose
22+
run: |
23+
cargo test --verbose
24+
cargo test --verbose --all-targets --all-features

Cargo.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@ multibase = { version = "1.0", git = "https://github.com/cryptidtech/rust-multib
1818
multicodec = { version = "1.0", git = "https://github.com/cryptidtech/rust-multicodec.git" }
1919
multitrait = { version = "1.0", git = "https://github.com/cryptidtech/multitrait.git" }
2020
multiutil = { version = "1.0", git = "https://github.com/cryptidtech/multiutil.git" }
21-
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"], optional = true }
22-
ssh-key = { version = "0.6", features = ["crypto"] }
23-
ssh-encoding = "0.2"
21+
serde = { version = "1.0", default-features = false, features = [
22+
"alloc",
23+
"derive",
24+
], optional = true }
25+
ssh-encoding = { version = "0.2" }
2426
thiserror = "1.0"
2527
unsigned-varint = { version = "0.8", features = ["std"] }
2628

29+
[target.'cfg(target_arch = "wasm32")'.dependencies]
30+
ssh-key = { version = "0.6", default-features = false, features = [
31+
"alloc",
32+
"ecdsa",
33+
"ed25519",
34+
] }
35+
36+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
37+
ssh-key = { version = "0.6", features = ["crypto"] }
38+
2739
[dev-dependencies]
2840
hex = "0.4"
2941
serde_test = "1.0"

src/error.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::Display;
2+
13
// SPDX-License-Idnetifier: Apache-2.0
24
/// Errors created by this library
35
#[derive(Clone, Debug, thiserror::Error)]
@@ -125,10 +127,39 @@ pub enum SharesError {
125127
#[derive(Clone, Debug, thiserror::Error)]
126128
#[non_exhaustive]
127129
pub enum ConversionsError {
128-
/// Ssh signature conversion error
129-
#[error(transparent)]
130-
SshSig(#[from] ssh_key::Error),
131-
/// Ssh label error
130+
/// Ssh conversion error
132131
#[error(transparent)]
133-
SshSigLabel(#[from] ssh_encoding::LabelError),
132+
Ssh(#[from] SshError),
133+
}
134+
135+
/// SSH Errors
136+
#[derive(Clone, Debug)]
137+
pub enum SshError {
138+
/// SSH Sig
139+
Sig(ssh_key::Error),
140+
/// SSH Sig label
141+
SigLabel(ssh_encoding::LabelError),
142+
}
143+
144+
impl Display for SshError {
145+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
146+
match self {
147+
SshError::Sig(e) => write!(f, "SSH Sig error: {}", e),
148+
SshError::SigLabel(e) => write!(f, "SSH Sig label error: {}", e),
149+
}
150+
}
151+
}
152+
153+
impl std::error::Error for SshError {}
154+
155+
impl From<ssh_key::Error> for SshError {
156+
fn from(e: ssh_key::Error) -> Self {
157+
SshError::Sig(e)
158+
}
159+
}
160+
161+
impl From<ssh_encoding::LabelError> for SshError {
162+
fn from(e: ssh_encoding::LabelError) -> Self {
163+
SshError::SigLabel(e)
164+
}
134165
}

src/ms.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ pub const SIG_CODECS: [Codec; 4] = [
2323
// Codec::Es384Msig,
2424
// Codec::Es521Msig,
2525
// Codec::Rs256Msig,
26-
Codec::Es256KMsig//,
27-
//Codec::LamportMsig,
26+
Codec::Es256KMsig, //,
27+
//Codec::LamportMsig,
2828
];
2929

3030
/// the list of signature share codecs supported
3131
pub const SIG_SHARE_CODECS: [Codec; 2] = [
3232
Codec::Bls12381G1ShareMsig,
33-
Codec::Bls12381G2ShareMsig//,
34-
//Codec::LamportShareMsig,
33+
Codec::Bls12381G2ShareMsig, //,
34+
//Codec::LamportShareMsig,
3535
];
3636

3737
/// the multisig sigil

src/views/bls12381.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,11 @@ impl<'a> ConvView for View<'a> {
386386
Ok(ssh_key::Signature::new(
387387
ssh_key::Algorithm::Other(
388388
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G1)
389-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
389+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
390390
),
391391
sig_data,
392392
)
393-
.map_err(|e| ConversionsError::SshSig(e))?)
393+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
394394
}
395395
Codec::Bls12381G2Msig => {
396396
// create the combined sig tuple
@@ -399,11 +399,11 @@ impl<'a> ConvView for View<'a> {
399399
Ok(ssh_key::Signature::new(
400400
ssh_key::Algorithm::Other(
401401
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G2)
402-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
402+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
403403
),
404404
sig_data,
405405
)
406-
.map_err(|e| ConversionsError::SshSig(e))?)
406+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
407407
}
408408
Codec::Bls12381G1ShareMsig => {
409409
// get the threshold attributes
@@ -419,11 +419,11 @@ impl<'a> ConvView for View<'a> {
419419
Ok(ssh_key::Signature::new(
420420
ssh_key::Algorithm::Other(
421421
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G1_SHARE)
422-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
422+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
423423
),
424424
sig_data,
425425
)
426-
.map_err(|e| ConversionsError::SshSig(e))?)
426+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
427427
}
428428
Codec::Bls12381G2ShareMsig => {
429429
// get the threshold attributes
@@ -439,11 +439,11 @@ impl<'a> ConvView for View<'a> {
439439
Ok(ssh_key::Signature::new(
440440
ssh_key::Algorithm::Other(
441441
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G2_SHARE)
442-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
442+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
443443
),
444444
sig_data,
445445
)
446-
.map_err(|e| ConversionsError::SshSig(e))?)
446+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
447447
}
448448
_ => Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())),
449449
}

src/views/ed25519.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a> ConvView for View<'a> {
5656
let sig_bytes = dv.sig_bytes()?;
5757
Ok(
5858
ssh_key::Signature::new(ssh_key::Algorithm::Ed25519, sig_bytes)
59-
.map_err(|e| ConversionsError::SshSig(e))?,
59+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
6060
)
6161
}
6262
}

src/views/secp256k1.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
use multicodec::Codec;
77

88
/// the name used to identify these signatures in non-Multikey formats
9-
pub const ALGORITHM_NAME: &'static str = "secp256k1@multisig";
9+
pub const ALGORITHM_NAME: &str = "secp256k1@multisig";
1010

1111
pub(crate) struct View<'a> {
1212
ms: &'a Multisig,
@@ -60,10 +60,10 @@ impl<'a> ConvView for View<'a> {
6060
Ok(ssh_key::Signature::new(
6161
ssh_key::Algorithm::Other(
6262
ssh_key::AlgorithmName::new(ALGORITHM_NAME)
63-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
63+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
6464
),
6565
sig_bytes,
6666
)
67-
.map_err(|e| ConversionsError::SshSig(e))?)
67+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
6868
}
6969
}

0 commit comments

Comments
 (0)