Skip to content

Commit 5cd8c2e

Browse files
author
Surkov, Kirill
committed
Enable rsa for wasm32 targets
1 parent 6dcfe73 commit 5cd8c2e

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

identity/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ zeroize = { version = "1.8", optional = true }
3131
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3232
ring = { workspace = true, features = ["alloc", "std"], optional = true }
3333

34+
[target.'cfg(target_arch = "wasm32")'.dependencies]
35+
ring = { workspace = true, features = ["alloc", "std", "wasm32_unknown_unknown_js"], optional = true }
36+
3437
[features]
3538
secp256k1 = ["dep:k256", "dep:asn1_der", "dep:sha2", "dep:hkdf", "dep:zeroize"]
3639
ecdsa = ["dep:p256", "dep:zeroize", "dep:sec1", "dep:sha2", "dep:hkdf"]

identity/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl DecodingError {
3535
#[allow(dead_code)]
3636
pub(crate) fn missing_feature(feature_name: &'static str) -> Self {
3737
Self {
38-
msg: format!("cargo feature `{feature_name}` is not enabled"),
38+
msg: format!("cargo feature `{feature_name}` is not enabled asd"),
3939
source: None,
4040
}
4141
}
@@ -76,7 +76,7 @@ impl DecodingError {
7676
}
7777
}
7878

79-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
79+
#[cfg(feature = "rsa")]
8080
pub(crate) fn encoding_unsupported(key_type: &'static str) -> Self {
8181
Self {
8282
msg: format!("encoding {key_type} key to Protobuf is unsupported"),
@@ -106,15 +106,15 @@ pub struct SigningError {
106106

107107
/// An error during encoding of key material.
108108
impl SigningError {
109-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
109+
#[cfg(feature = "rsa")]
110110
pub(crate) fn new<S: ToString>(msg: S) -> Self {
111111
Self {
112112
msg: msg.to_string(),
113113
source: None,
114114
}
115115
}
116116

117-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
117+
#[cfg(feature = "rsa")]
118118
pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self {
119119
Self {
120120
source: Some(Box::new(source)),

identity/src/keypair.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use crate::error::OtherVariantError;
5050
feature = "rsa"
5151
))]
5252
use crate::proto;
53-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
53+
#[cfg(feature = "rsa")]
5454
use crate::rsa;
5555
#[cfg(feature = "secp256k1")]
5656
use crate::secp256k1;
@@ -87,7 +87,7 @@ enum KeyPairInner {
8787
#[cfg(feature = "ed25519")]
8888
Ed25519(ed25519::Keypair),
8989
/// An RSA keypair.
90-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
90+
#[cfg(feature = "rsa")]
9191
Rsa(rsa::Keypair),
9292
/// A Secp256k1 keypair.
9393
#[cfg(feature = "secp256k1")]
@@ -132,7 +132,7 @@ impl Keypair {
132132
self.try_into()
133133
}
134134

135-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
135+
#[cfg(feature = "rsa")]
136136
pub fn try_into_rsa(self) -> Result<rsa::Keypair, OtherVariantError> {
137137
self.try_into()
138138
}
@@ -146,7 +146,7 @@ impl Keypair {
146146
/// format (i.e. unencrypted) as defined in [RFC5208].
147147
///
148148
/// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5
149-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
149+
#[cfg(feature = "rsa")]
150150
pub fn rsa_from_pkcs8(pkcs8_der: &mut [u8]) -> Result<Keypair, DecodingError> {
151151
rsa::Keypair::try_decode_pkcs8(pkcs8_der).map(|kp| Keypair {
152152
keypair: KeyPairInner::Rsa(kp),
@@ -180,7 +180,7 @@ impl Keypair {
180180
match self.keypair {
181181
#[cfg(feature = "ed25519")]
182182
KeyPairInner::Ed25519(ref pair) => Ok(pair.sign(msg)),
183-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
183+
#[cfg(feature = "rsa")]
184184
KeyPairInner::Rsa(ref pair) => pair.sign(msg),
185185
#[cfg(feature = "secp256k1")]
186186
KeyPairInner::Secp256k1(ref pair) => Ok(pair.secret().sign(msg)),
@@ -196,7 +196,7 @@ impl Keypair {
196196
KeyPairInner::Ed25519(ref pair) => PublicKey {
197197
publickey: PublicKeyInner::Ed25519(pair.public()),
198198
},
199-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
199+
#[cfg(feature = "rsa")]
200200
KeyPairInner::Rsa(ref pair) => PublicKey {
201201
publickey: PublicKeyInner::Rsa(pair.public()),
202202
},
@@ -227,7 +227,7 @@ impl Keypair {
227227
Type: proto::KeyType::Ed25519,
228228
Data: data.to_bytes().to_vec(),
229229
},
230-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
230+
#[cfg(feature = "rsa")]
231231
KeyPairInner::Rsa(_) => return Err(DecodingError::encoding_unsupported("RSA")),
232232
#[cfg(feature = "secp256k1")]
233233
KeyPairInner::Secp256k1(ref data) => proto::PrivateKey {
@@ -286,7 +286,7 @@ impl Keypair {
286286
Err(DecodingError::missing_feature("ed25519"))
287287
}
288288
proto::KeyType::RSA => {
289-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
289+
#[cfg(feature = "rsa")]
290290
return rsa::Keypair::try_decode_pkcs1(&mut private_key.Data).map(|sk| {
291291
Keypair {
292292
keypair: KeyPairInner::Rsa(sk),
@@ -331,7 +331,7 @@ impl Keypair {
331331
match self.keypair {
332332
#[cfg(feature = "ed25519")]
333333
KeyPairInner::Ed25519(_) => KeyType::Ed25519,
334-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
334+
#[cfg(feature = "rsa")]
335335
KeyPairInner::Rsa(_) => KeyType::RSA,
336336
#[cfg(feature = "secp256k1")]
337337
KeyPairInner::Secp256k1(_) => KeyType::Secp256k1,
@@ -389,7 +389,7 @@ impl Keypair {
389389
match self.keypair {
390390
#[cfg(feature = "ed25519")]
391391
KeyPairInner::Ed25519(ref inner) => Some(inner.secret().to_bytes()),
392-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
392+
#[cfg(feature = "rsa")]
393393
KeyPairInner::Rsa(_) => None,
394394
#[cfg(feature = "secp256k1")]
395395
KeyPairInner::Secp256k1(ref inner) => Some(inner.secret().to_bytes()),
@@ -432,7 +432,7 @@ impl From<secp256k1::Keypair> for Keypair {
432432
}
433433
}
434434

435-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
435+
#[cfg(feature = "rsa")]
436436
impl From<rsa::Keypair> for Keypair {
437437
fn from(kp: rsa::Keypair) -> Self {
438438
Keypair {
@@ -448,7 +448,7 @@ impl TryInto<ed25519::Keypair> for Keypair {
448448
fn try_into(self) -> Result<ed25519::Keypair, Self::Error> {
449449
match self.keypair {
450450
KeyPairInner::Ed25519(inner) => Ok(inner),
451-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
451+
#[cfg(feature = "rsa")]
452452
KeyPairInner::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)),
453453
#[cfg(feature = "secp256k1")]
454454
KeyPairInner::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)),
@@ -467,7 +467,7 @@ impl TryInto<ecdsa::Keypair> for Keypair {
467467
KeyPairInner::Ecdsa(inner) => Ok(inner),
468468
#[cfg(feature = "ed25519")]
469469
KeyPairInner::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)),
470-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
470+
#[cfg(feature = "rsa")]
471471
KeyPairInner::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)),
472472
#[cfg(feature = "secp256k1")]
473473
KeyPairInner::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)),
@@ -484,15 +484,15 @@ impl TryInto<secp256k1::Keypair> for Keypair {
484484
KeyPairInner::Secp256k1(inner) => Ok(inner),
485485
#[cfg(feature = "ed25519")]
486486
KeyPairInner::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)),
487-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
487+
#[cfg(feature = "rsa")]
488488
KeyPairInner::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)),
489489
#[cfg(feature = "ecdsa")]
490490
KeyPairInner::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)),
491491
}
492492
}
493493
}
494494

495-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
495+
#[cfg(feature = "rsa")]
496496
impl TryInto<rsa::Keypair> for Keypair {
497497
type Error = OtherVariantError;
498498

@@ -514,7 +514,7 @@ pub(crate) enum PublicKeyInner {
514514
/// A public Ed25519 key.
515515
#[cfg(feature = "ed25519")]
516516
Ed25519(ed25519::PublicKey),
517-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
517+
#[cfg(feature = "rsa")]
518518
/// A public RSA key.
519519
Rsa(rsa::PublicKey),
520520
#[cfg(feature = "secp256k1")]
@@ -542,7 +542,7 @@ impl PublicKey {
542542
match self.publickey {
543543
#[cfg(feature = "ed25519")]
544544
PublicKeyInner::Ed25519(ref pk) => pk.verify(msg, sig),
545-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
545+
#[cfg(feature = "rsa")]
546546
PublicKeyInner::Rsa(ref pk) => pk.verify(msg, sig),
547547
#[cfg(feature = "secp256k1")]
548548
PublicKeyInner::Secp256k1(ref pk) => pk.verify(msg, sig),
@@ -561,7 +561,7 @@ impl PublicKey {
561561
self.try_into()
562562
}
563563

564-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
564+
#[cfg(feature = "rsa")]
565565
pub fn try_into_rsa(self) -> Result<rsa::PublicKey, OtherVariantError> {
566566
self.try_into()
567567
}
@@ -642,7 +642,7 @@ impl PublicKey {
642642
match self.publickey {
643643
#[cfg(feature = "ed25519")]
644644
PublicKeyInner::Ed25519(_) => KeyType::Ed25519,
645-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
645+
#[cfg(feature = "rsa")]
646646
PublicKeyInner::Rsa(_) => KeyType::RSA,
647647
#[cfg(feature = "secp256k1")]
648648
PublicKeyInner::Secp256k1(_) => KeyType::Secp256k1,
@@ -674,15 +674,15 @@ impl TryFrom<proto::PublicKey> for PublicKey {
674674
tracing::debug!("support for ed25519 was disabled at compile-time");
675675
Err(DecodingError::missing_feature("ed25519"))
676676
}
677-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
677+
#[cfg(feature = "rsa")]
678678
proto::KeyType::RSA => {
679679
Ok(
680680
rsa::PublicKey::try_decode_x509(&pubkey.Data).map(|kp| PublicKey {
681681
publickey: PublicKeyInner::Rsa(kp),
682682
})?,
683683
)
684684
}
685-
#[cfg(any(not(feature = "rsa"), target_arch = "wasm32"))]
685+
#[cfg(not(feature = "rsa"))]
686686
proto::KeyType::RSA => {
687687
tracing::debug!("support for RSA was disabled at compile-time");
688688
Err(DecodingError::missing_feature("rsa"))
@@ -719,7 +719,7 @@ impl TryInto<ed25519::PublicKey> for PublicKey {
719719
fn try_into(self) -> Result<ed25519::PublicKey, Self::Error> {
720720
match self.publickey {
721721
PublicKeyInner::Ed25519(inner) => Ok(inner),
722-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
722+
#[cfg(feature = "rsa")]
723723
PublicKeyInner::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)),
724724
#[cfg(feature = "secp256k1")]
725725
PublicKeyInner::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)),
@@ -738,7 +738,7 @@ impl TryInto<ecdsa::PublicKey> for PublicKey {
738738
PublicKeyInner::Ecdsa(inner) => Ok(inner),
739739
#[cfg(feature = "ed25519")]
740740
PublicKeyInner::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)),
741-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
741+
#[cfg(feature = "rsa")]
742742
PublicKeyInner::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)),
743743
#[cfg(feature = "secp256k1")]
744744
PublicKeyInner::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)),
@@ -755,15 +755,15 @@ impl TryInto<secp256k1::PublicKey> for PublicKey {
755755
PublicKeyInner::Secp256k1(inner) => Ok(inner),
756756
#[cfg(feature = "ed25519")]
757757
PublicKeyInner::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)),
758-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
758+
#[cfg(feature = "rsa")]
759759
PublicKeyInner::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)),
760760
#[cfg(feature = "ecdsa")]
761761
PublicKeyInner::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)),
762762
}
763763
}
764764
}
765765

766-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
766+
#[cfg(feature = "rsa")]
767767
impl TryInto<rsa::PublicKey> for PublicKey {
768768
type Error = OtherVariantError;
769769

@@ -807,7 +807,7 @@ impl From<ecdsa::PublicKey> for PublicKey {
807807
}
808808
}
809809

810-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
810+
#[cfg(feature = "rsa")]
811811
impl From<rsa::PublicKey> for PublicKey {
812812
fn from(key: rsa::PublicKey) -> Self {
813813
PublicKey {

identity/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub mod ecdsa;
5252
#[cfg(feature = "ed25519")]
5353
pub mod ed25519;
5454

55-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
55+
#[cfg(feature = "rsa")]
5656
pub mod rsa;
5757

5858
#[cfg(feature = "secp256k1")]
@@ -89,7 +89,7 @@ impl From<&PublicKey> for proto::PublicKey {
8989
Type: proto::KeyType::Ed25519,
9090
Data: key.to_bytes().to_vec(),
9191
},
92-
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
92+
#[cfg(feature = "rsa")]
9393
keypair::PublicKeyInner::Rsa(key) => proto::PublicKey {
9494
Type: proto::KeyType::RSA,
9595
Data: key.encode_x509(),

0 commit comments

Comments
 (0)