Skip to content

Commit 5260e72

Browse files
ssh-key default-features false for wasm32-* targets
1 parent e43014e commit 5260e72

File tree

7 files changed

+57
-31
lines changed

7 files changed

+57
-31
lines changed

Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ license = "Apache-2.0"
1010

1111
[features]
1212
default = ["serde"]
13-
ssh = ["ssh-key", "ssh-encoding"]
1413

1514
[dependencies]
1615
blsful = { version = "2.5", git = "https://github.com/mikelodder7/blsful.git" }
@@ -23,12 +22,19 @@ serde = { version = "1.0", default-features = false, features = [
2322
"alloc",
2423
"derive",
2524
], optional = true }
25+
ssh-encoding = { version = "0.2" }
2626
thiserror = "1.0"
2727
unsigned-varint = { version = "0.8", features = ["std"] }
2828

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+
2936
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
30-
ssh-key = { version = "0.6", features = ["crypto"], optional = true }
31-
ssh-encoding = { version = "0.2", optional = true }
37+
ssh-key = { version = "0.6", features = ["crypto"] }
3238

3339
[dev-dependencies]
3440
hex = "0.4"

src/error.rs

Lines changed: 36 additions & 7 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,12 +127,39 @@ pub enum SharesError {
125127
#[derive(Clone, Debug, thiserror::Error)]
126128
#[non_exhaustive]
127129
pub enum ConversionsError {
128-
/// Ssh signature conversion error
129-
#[cfg(feature = "ssh")]
130-
#[error(transparent)]
131-
SshSig(#[from] ssh_key::Error),
132-
/// Ssh label error
133-
#[cfg(feature = "ssh")]
130+
/// Ssh conversion error
134131
#[error(transparent)]
135-
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+
}
136165
}

src/ms.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ impl Builder {
254254
}
255255

256256
/// create new multisig from ssh Signature
257-
#[cfg(feature = "ssh")]
258257
pub fn new_from_ssh_signature(sig: &ssh_key::Signature) -> Result<Self, Error> {
259258
let mut attributes = BTreeMap::new();
260259
use ssh_key::Algorithm::*;
@@ -603,7 +602,6 @@ mod tests {
603602
assert_eq!(ms1, ms3);
604603
}
605604

606-
#[cfg(feature = "ssh")]
607605
#[test]
608606
fn test_eddsa_ssh_roundtrip() {
609607
let ms1 = Builder::new(Codec::EddsaMsig)
@@ -619,7 +617,6 @@ mod tests {
619617
assert_eq!(ms1, ms2);
620618
}
621619

622-
#[cfg(feature = "ssh")]
623620
#[test]
624621
fn test_es256k_ssh_roundtrip() {
625622
let ms1 = Builder::new(Codec::Es256KMsig)
@@ -635,7 +632,6 @@ mod tests {
635632
assert_eq!(ms1, ms2);
636633
}
637634

638-
#[cfg(feature = "ssh")]
639635
#[test]
640636
fn test_bls_signature_ssh_roundtrip() {
641637
let sk = blsful::Bls12381G1::new_secret_key();
@@ -662,7 +658,6 @@ mod tests {
662658
assert_eq!(ms1, ms2);
663659
}
664660

665-
#[cfg(feature = "ssh")]
666661
#[test]
667662
fn test_bls_signature_combine_ssh_roundtrip() {
668663
let sk = blsful::Bls12381G2::new_secret_key();

src/views.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub trait DataView {
3131
/// trait for converting Multisigs to other formats
3232
pub trait ConvView {
3333
/// convert the Multisig to an SSH signature
34-
#[cfg(feature = "ssh")]
3534
fn to_ssh_signature(&self) -> Result<ssh_key::Signature, Error>;
3635
}
3736

src/views/bls12381.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ impl<'a> DataView for View<'a> {
369369

370370
impl<'a> ConvView for View<'a> {
371371
/// convert to SSH signature format
372-
#[cfg(feature = "ssh")]
373372
fn to_ssh_signature(&self) -> Result<ssh_key::Signature, Error> {
374373
// get the signature data
375374
let dv = self.ms.data_view()?;
@@ -387,11 +386,11 @@ impl<'a> ConvView for View<'a> {
387386
Ok(ssh_key::Signature::new(
388387
ssh_key::Algorithm::Other(
389388
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G1)
390-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
389+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
391390
),
392391
sig_data,
393392
)
394-
.map_err(|e| ConversionsError::SshSig(e))?)
393+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
395394
}
396395
Codec::Bls12381G2Msig => {
397396
// create the combined sig tuple
@@ -400,11 +399,11 @@ impl<'a> ConvView for View<'a> {
400399
Ok(ssh_key::Signature::new(
401400
ssh_key::Algorithm::Other(
402401
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G2)
403-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
402+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
404403
),
405404
sig_data,
406405
)
407-
.map_err(|e| ConversionsError::SshSig(e))?)
406+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
408407
}
409408
Codec::Bls12381G1ShareMsig => {
410409
// get the threshold attributes
@@ -420,11 +419,11 @@ impl<'a> ConvView for View<'a> {
420419
Ok(ssh_key::Signature::new(
421420
ssh_key::Algorithm::Other(
422421
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G1_SHARE)
423-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
422+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
424423
),
425424
sig_data,
426425
)
427-
.map_err(|e| ConversionsError::SshSig(e))?)
426+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
428427
}
429428
Codec::Bls12381G2ShareMsig => {
430429
// get the threshold attributes
@@ -440,11 +439,11 @@ impl<'a> ConvView for View<'a> {
440439
Ok(ssh_key::Signature::new(
441440
ssh_key::Algorithm::Other(
442441
ssh_key::AlgorithmName::new(ALGORITHM_NAME_G2_SHARE)
443-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
442+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
444443
),
445444
sig_data,
446445
)
447-
.map_err(|e| ConversionsError::SshSig(e))?)
446+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
448447
}
449448
_ => Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())),
450449
}

src/views/ed25519.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ impl<'a> DataView for View<'a> {
5050

5151
impl<'a> ConvView for View<'a> {
5252
/// convert to SSH signature format
53-
#[cfg(feature = "ssh")]
5453
fn to_ssh_signature(&self) -> Result<ssh_key::Signature, Error> {
5554
// get the signature data
5655
let dv = self.ms.data_view()?;
5756
let sig_bytes = dv.sig_bytes()?;
5857
Ok(
5958
ssh_key::Signature::new(ssh_key::Algorithm::Ed25519, sig_bytes)
60-
.map_err(|e| ConversionsError::SshSig(e))?,
59+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
6160
)
6261
}
6362
}

src/views/secp256k1.rs

Lines changed: 3 additions & 4 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,
@@ -53,18 +53,17 @@ impl<'a> DataView for View<'a> {
5353

5454
impl<'a> ConvView for View<'a> {
5555
/// convert to SSH signature format
56-
#[cfg(feature = "ssh")]
5756
fn to_ssh_signature(&self) -> Result<ssh_key::Signature, Error> {
5857
// get the signature data
5958
let dv = self.ms.data_view()?;
6059
let sig_bytes = dv.sig_bytes()?;
6160
Ok(ssh_key::Signature::new(
6261
ssh_key::Algorithm::Other(
6362
ssh_key::AlgorithmName::new(ALGORITHM_NAME)
64-
.map_err(|e| ConversionsError::SshSigLabel(e))?,
63+
.map_err(|e| ConversionsError::Ssh(e.into()))?,
6564
),
6665
sig_bytes,
6766
)
68-
.map_err(|e| ConversionsError::SshSig(e))?)
67+
.map_err(|e| ConversionsError::Ssh(e.into()))?)
6968
}
7069
}

0 commit comments

Comments
 (0)