diff --git a/Cargo.toml b/Cargo.toml index cabc2e5a983..2911fd312c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,7 @@ pin-project = "0.4.17" smallvec = "1.0" wasm-timer = "0.2.4" -[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies] +[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] libp2p-deflate = { version = "0.19.2", path = "protocols/deflate", optional = true } libp2p-dns = { version = "0.19.0", path = "transports/dns", optional = true } libp2p-mdns = { version = "0.19.2", path = "protocols/mdns", optional = true } diff --git a/core/Cargo.toml b/core/Cargo.toml index 7253dd3da11..05311f95879 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -35,7 +35,7 @@ unsigned-varint = "0.4" void = "1" zeroize = "1" -[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies] +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false } [dev-dependencies] diff --git a/core/src/identity.rs b/core/src/identity.rs index da5ecb5657d..4b65f1a5dbd 100644 --- a/core/src/identity.rs +++ b/core/src/identity.rs @@ -21,7 +21,7 @@ //! A node's network identity keys. pub mod ed25519; -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(target_arch = "wasm32"))] pub mod rsa; #[cfg(feature = "secp256k1")] pub mod secp256k1; @@ -52,7 +52,7 @@ use crate::{PeerId, keys_proto}; pub enum Keypair { /// An Ed25519 keypair. Ed25519(ed25519::Keypair), - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] /// An RSA keypair. Rsa(rsa::Keypair), /// A Secp256k1 keypair. @@ -76,7 +76,7 @@ impl Keypair { /// format (i.e. unencrypted) as defined in [RFC5208]. /// /// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5 - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] pub fn rsa_from_pkcs8(pkcs8_der: &mut [u8]) -> Result { rsa::Keypair::from_pkcs8(pkcs8_der).map(Keypair::Rsa) } @@ -97,7 +97,7 @@ impl Keypair { use Keypair::*; match self { Ed25519(ref pair) => Ok(pair.sign(msg)), - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] Rsa(ref pair) => pair.sign(msg), #[cfg(feature = "secp256k1")] Secp256k1(ref pair) => pair.secret().sign(msg) @@ -109,7 +109,7 @@ impl Keypair { use Keypair::*; match self { Ed25519(pair) => PublicKey::Ed25519(pair.public()), - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] Rsa(pair) => PublicKey::Rsa(pair.public()), #[cfg(feature = "secp256k1")] Secp256k1(pair) => PublicKey::Secp256k1(pair.public().clone()), @@ -122,7 +122,7 @@ impl Keypair { pub enum PublicKey { /// A public Ed25519 key. Ed25519(ed25519::PublicKey), - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] /// A public RSA key. Rsa(rsa::PublicKey), #[cfg(feature = "secp256k1")] @@ -139,7 +139,7 @@ impl PublicKey { use PublicKey::*; match self { Ed25519(pk) => pk.verify(msg, sig), - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] Rsa(pk) => pk.verify(msg, sig), #[cfg(feature = "secp256k1")] Secp256k1(pk) => pk.verify(msg, sig) @@ -157,7 +157,7 @@ impl PublicKey { r#type: keys_proto::KeyType::Ed25519 as i32, data: key.encode().to_vec() }, - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] PublicKey::Rsa(key) => keys_proto::PublicKey { r#type: keys_proto::KeyType::Rsa as i32, @@ -192,11 +192,11 @@ impl PublicKey { keys_proto::KeyType::Ed25519 => { ed25519::PublicKey::decode(&pubkey.data).map(PublicKey::Ed25519) }, - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(target_arch = "wasm32"))] keys_proto::KeyType::Rsa => { rsa::PublicKey::decode_x509(&pubkey.data).map(PublicKey::Rsa) } - #[cfg(any(target_os = "emscripten", target_os = "unknown"))] + #[cfg(target_arch = "wasm32")] keys_proto::KeyType::Rsa => { log::debug!("support for RSA was disabled at compile-time"); Err(DecodingError::new("Unsupported")) diff --git a/protocols/noise/Cargo.toml b/protocols/noise/Cargo.toml index ec3b60c596b..4936b7933e2 100644 --- a/protocols/noise/Cargo.toml +++ b/protocols/noise/Cargo.toml @@ -20,10 +20,10 @@ static_assertions = "1" x25519-dalek = "0.6.0" zeroize = "1" -[target.'cfg(not(target_os = "unknown"))'.dependencies] +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] snow = { version = "0.7.0", features = ["ring-resolver"], default-features = false } -[target.'cfg(target_os = "unknown")'.dependencies] +[target.'cfg(target_arch = "wasm32")'.dependencies] snow = { version = "0.7.0", features = ["default-resolver"], default-features = false } [dev-dependencies] diff --git a/protocols/noise/src/protocol.rs b/protocols/noise/src/protocol.rs index 5844dbc8212..7c61274acb5 100644 --- a/protocols/noise/src/protocol.rs +++ b/protocols/noise/src/protocol.rs @@ -229,22 +229,22 @@ impl snow::resolvers::CryptoResolver for Resolver { } fn resolve_hash(&self, choice: &snow::params::HashChoice) -> Option> { - #[cfg(target_os = "unknown")] + #[cfg(target_arch = "wasm32")] { snow::resolvers::DefaultResolver.resolve_hash(choice) } - #[cfg(not(target_os = "unknown"))] + #[cfg(not(target_arch = "wasm32"))] { snow::resolvers::RingResolver.resolve_hash(choice) } } fn resolve_cipher(&self, choice: &snow::params::CipherChoice) -> Option> { - #[cfg(target_os = "unknown")] + #[cfg(target_arch = "wasm32")] { snow::resolvers::DefaultResolver.resolve_cipher(choice) } - #[cfg(not(target_os = "unknown"))] + #[cfg(not(target_arch = "wasm32"))] { snow::resolvers::RingResolver.resolve_cipher(choice) } diff --git a/protocols/secio/src/algo_support.rs b/protocols/secio/src/algo_support.rs index 21114cde919..5e6d5e461f5 100644 --- a/protocols/secio/src/algo_support.rs +++ b/protocols/secio/src/algo_support.rs @@ -24,7 +24,7 @@ //! helps you with. use crate::error::SecioError; -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] use ring::digest; use std::cmp::Ordering; use crate::stream_cipher::Cipher; @@ -204,7 +204,7 @@ pub fn select_digest(r: Ordering, ours: &str, theirs: &str) -> Result for Digest { #[inline] fn into(self) -> &'static digest::Algorithm { diff --git a/protocols/secio/src/exchange.rs b/protocols/secio/src/exchange.rs index c1a9bad6590..1ae4120b7fc 100644 --- a/protocols/secio/src/exchange.rs +++ b/protocols/secio/src/exchange.rs @@ -24,10 +24,10 @@ use futures::prelude::*; use crate::SecioError; #[path = "exchange/impl_ring.rs"] -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] mod platform; #[path = "exchange/impl_webcrypto.rs"] -#[cfg(any(target_os = "emscripten", target_os = "unknown"))] +#[cfg(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown"))] mod platform; /// Possible key agreement algorithms. diff --git a/protocols/secio/src/handshake.rs b/protocols/secio/src/handshake.rs index faffccc9d36..e436a777cc1 100644 --- a/protocols/secio/src/handshake.rs +++ b/protocols/secio/src/handshake.rs @@ -371,7 +371,7 @@ mod tests { use futures::{prelude::*, channel::oneshot}; #[test] - #[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] + #[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] fn handshake_with_self_succeeds_rsa() { let key1 = { let mut private = include_bytes!("../tests/test-rsa-private-key.pk8").to_vec(); diff --git a/src/lib.rs b/src/lib.rs index 1dab7142765..eb68a331deb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,7 +85,7 @@ //! Example ([`secio`] + [`yamux`] Protocol Upgrade): //! //! ```rust -//! # #[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "secio", feature = "yamux"))] { +//! # #[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), feature = "tcp-async-std", feature = "secio", feature = "yamux"))] { //! use libp2p::{Transport, core::upgrade, tcp::TcpConfig, secio::SecioConfig, identity::Keypair, yamux}; //! let tcp = TcpConfig::new(); //! let secio = SecioConfig::new(Keypair::generate_ed25519()); @@ -166,12 +166,12 @@ pub use multihash; pub use libp2p_core as core; #[cfg(feature = "deflate")] #[cfg_attr(docsrs, doc(cfg(feature = "deflate")))] -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[doc(inline)] pub use libp2p_deflate as deflate; #[cfg(feature = "dns")] #[cfg_attr(docsrs, doc(cfg(feature = "dns")))] -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[doc(inline)] pub use libp2p_dns as dns; #[cfg(feature = "identify")] @@ -196,7 +196,7 @@ pub use libp2p_gossipsub as gossipsub; pub use libp2p_mplex as mplex; #[cfg(feature = "mdns")] #[cfg_attr(docsrs, doc(cfg(feature = "mdns")))] -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[doc(inline)] pub use libp2p_mdns as mdns; #[cfg(feature = "noise")] @@ -219,7 +219,7 @@ pub use libp2p_secio as secio; pub use libp2p_swarm as swarm; #[cfg(any(feature = "tcp-async-std", feature = "tcp-tokio"))] #[cfg_attr(docsrs, doc(cfg(any(feature = "tcp-async-std", feature = "tcp-tokio"))))] -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[doc(inline)] pub use libp2p_tcp as tcp; #[cfg(feature = "uds")] @@ -232,7 +232,7 @@ pub use libp2p_uds as uds; pub use libp2p_wasm_ext as wasm_ext; #[cfg(feature = "websocket")] #[cfg_attr(docsrs, doc(cfg(feature = "websocket")))] -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[doc(inline)] pub use libp2p_websocket as websocket; #[cfg(feature = "yamux")] @@ -266,8 +266,8 @@ pub use self::transport_ext::TransportExt; /// /// > **Note**: This `Transport` is not suitable for production usage, as its implementation /// > reserves the right to support additional protocols or remove deprecated protocols. -#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))] -#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))] +#[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))] +#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))] pub fn build_development_transport(keypair: identity::Keypair) -> std::io::Result> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> { @@ -280,8 +280,8 @@ pub fn build_development_transport(keypair: identity::Keypair) /// and mplex or yamux as the multiplexing layer. /// /// > **Note**: If you ever need to express the type of this `Transport`. -#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))] -#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))] +#[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))] +#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))] pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair) -> std::io::Result> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> { @@ -309,8 +309,8 @@ pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair) /// and mplex or yamux as the multiplexing layer. /// /// > **Note**: If you ever need to express the type of this `Transport`. -#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))] -#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))))] +#[cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))] +#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), any(feature = "tcp-async-std", feature = "tcp-tokio"), feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))))] pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PreSharedKey) -> std::io::Result> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> { diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index ae8f2492367..f72fe8b8ffc 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -9,14 +9,14 @@ repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] -[target.'cfg(all(unix, not(any(target_os = "emscripten", target_os = "unknown"))))'.dependencies] +[target.'cfg(all(unix, not(target_os = "emscripten")))'.dependencies] async-std = { version = "1.6.2", optional = true } libp2p-core = { version = "0.19.2", path = "../../core" } log = "0.4.1" futures = "0.3.1" tokio = { version = "0.2", default-features = false, features = ["uds"], optional = true } -[target.'cfg(all(unix, not(any(target_os = "emscripten", target_os = "unknown"))))'.dev-dependencies] +[target.'cfg(all(unix, not(target_os = "emscripten")))'.dev-dependencies] tempfile = "3.0" [features] diff --git a/transports/uds/src/lib.rs b/transports/uds/src/lib.rs index 44bad943c2a..05efae630bb 100644 --- a/transports/uds/src/lib.rs +++ b/transports/uds/src/lib.rs @@ -31,8 +31,8 @@ //! The `UdsConfig` structs implements the `Transport` trait of the `core` library. See the //! documentation of `core` and of libp2p in general to learn how to use the `Transport` trait. -#![cfg(all(unix, not(any(target_os = "emscripten", target_os = "unknown"))))] -#![cfg_attr(docsrs, doc(cfg(all(unix, not(any(target_os = "emscripten", target_os = "unknown"))))))] +#![cfg(all(unix, not(target_os = "emscripten")))] +#![cfg_attr(docsrs, doc(cfg(all(unix, not(target_os = "emscripten")))))] use futures::{prelude::*, future::{BoxFuture, Ready}}; use futures::stream::BoxStream;