Skip to content

Commit

Permalink
fix(wasm): Fixes deps for building in wasm
Browse files Browse the repository at this point in the history
A while ago we made sure that if you wanted to pull in the base bindle types
into something compiling to wasm, it would build. Recently, tokio made a
change that made it so it wouldn't compile for wasm with the `fs` feature
enabled. This makes sense, but I did have to untangle some fs stuff from
the signatures module.

While I was here I fixed a bunch of new clippy lints from the latest version
of clippy

Signed-off-by: Taylor Thomas <[email protected]>
  • Loading branch information
thomastaylor312 committed Dec 5, 2022
1 parent 536abea commit 767ec06
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ default = ["server", "client", "caching", "test-tools", "native-tls"]
server = ["warp", "openid", "hyper", "mime", "either", "_common"]
client = ["mime_guess", "dirs", "time", "async-compression", "tokio-tar", "_common"]
# Internal use only feature that groups all of the optional deps we need for both server and client
_common = ["providers", "tokio/full", "tokio-util", "oauth2", "reqwest"]
_common = ["providers", "tokio/full", "tokio-util", "oauth2", "reqwest", "tokio-stream/fs"]
# Activates provider implementations
providers = ["lru", "serde_cbor", "sled"]
caching = ["lru"]
Expand Down Expand Up @@ -74,8 +74,8 @@ sled = { version = "0.34.7", optional = true }
tempfile = "3.2.0"
thiserror = "1.0.29"
time = { version = "0.3", features = ["serde"], optional = true }
tokio = { version = "1.11.0", default-features = false, features = ["fs", "sync", "io-util"] }
tokio-stream = { version = "0.1.7", features = ["fs"] }
tokio = { version = "1.11.0", default-features = false, features = ["sync", "io-util"] }
tokio-stream = { version = "0.1.7" }
tokio-tar = { version = "0.3", optional = true }
tokio-util = { version = "0.7", features = ["io", "codec"], optional = true }
toml = "0.5.8"
Expand Down
8 changes: 2 additions & 6 deletions src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ impl<'a> BindleFilter<'a> {
/// returned in the filter result if something else does not remove them.
pub fn activate_feature(&mut self, group: &str, name: &str, value: &str) -> &mut Self {
// This is a hack to remove duplicate group/name pairs.
self.features = self
.features
.iter()
.filter(|i| !(i.name == name && i.group == group))
.cloned()
.collect();
self.features
.retain(|i| !(i.name == name && i.group == group));

self.features.push(FeatureReference {
group: group.to_owned(),
Expand Down
13 changes: 9 additions & 4 deletions src/invoice/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
pub use ed25519_dalek::{Keypair, PublicKey, Signature as EdSignature, Signer};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tokio::fs::OpenOptions;
#[cfg(not(target_arch = "wasm32"))]
use tokio::io::AsyncWriteExt;
use tracing::error;

use std::convert::TryFrom;
use std::fmt::{Display, Formatter, Result as FmtResult};
#[cfg(not(target_arch = "wasm32"))]
use std::path::Path;
use std::str::FromStr;

Expand Down Expand Up @@ -66,7 +67,7 @@ pub enum SignatureError {
///
/// Signatories on a signature must have an associated role, as defined in the
/// specification.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum SignatureRole {
Creator,
Expand Down Expand Up @@ -126,6 +127,7 @@ pub trait KeyRingSaver {
async fn save(&self, keyring: &KeyRing) -> anyhow::Result<()>;
}

#[cfg(not(target_arch = "wasm32"))]
#[async_trait::async_trait]
impl<T: AsRef<Path> + Sync> KeyRingLoader for T {
async fn load(&self) -> anyhow::Result<KeyRing> {
Expand All @@ -141,10 +143,11 @@ impl<T: AsRef<Path> + Sync> KeyRingLoader for T {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[async_trait::async_trait]
impl<T: AsRef<Path> + Sync> KeyRingSaver for T {
async fn save(&self, keyring: &KeyRing) -> anyhow::Result<()> {
let mut opts = OpenOptions::new();
let mut opts = tokio::fs::OpenOptions::new();
opts.create(true).write(true).truncate(true);

// TODO(thomastaylor312): Figure out what the proper permissions are on windows (probably
Expand Down Expand Up @@ -401,6 +404,7 @@ impl Default for SecretKeyFile {
}
}

#[cfg(not(target_arch = "wasm32"))]
impl SecretKeyFile {
pub async fn load_file(path: impl AsRef<Path>) -> anyhow::Result<SecretKeyFile> {
let raw = tokio::fs::read(path).await?;
Expand All @@ -411,7 +415,7 @@ impl SecretKeyFile {
/// Save the present keyfile to the named path.
pub async fn save_file(&self, dest: impl AsRef<Path>) -> anyhow::Result<()> {
let out = toml::to_vec(self)?;
let mut opts = OpenOptions::new();
let mut opts = tokio::fs::OpenOptions::new();
opts.create(true).write(true);

// TODO(thomastaylor312): Figure out what the proper permissions are on windows (probably
Expand All @@ -426,6 +430,7 @@ impl SecretKeyFile {
Ok(())
}
}

/// This enumerates the select criteria of the key based on the given Label
pub enum LabelMatch {
/// Key will be selected with an exact match of the given label.
Expand Down
2 changes: 1 addition & 1 deletion src/invoice/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum VerificationStrategy {
/// Verifies that all signatures of the given roles are valid and signed by known keys. Will
/// also validate unknown signers similar to GreedyVerification
///
/// If the bool is true, unknown signers will also be validated. Be aware that doing so may make
/// Unknown signers will also be validated. Be aware that doing so may make
/// the validation subject to a special form of DOS attack in which someone can generate a
/// known-bad signature.
MultipleAttestationGreedy(Vec<SignatureRole>),
Expand Down
34 changes: 17 additions & 17 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TEST_LABEL: &str = "Benjamin Sisko <[email protected]>";
async fn setup_data<T: TokenManager>(client: &Client<T>) {
// For now let's just put in a simple manifest and one with a lot of parcels
for name in &["valid_v1", "lotsa_parcels"] {
let scaffold = testing::Scaffold::load(*name).await;
let scaffold = testing::Scaffold::load(name).await;
client
.create_invoice(scaffold.invoice.clone())
.await
Expand Down Expand Up @@ -47,7 +47,7 @@ async fn test_push() {
let path = std::path::PathBuf::from(root).join("test/data/standalone");
// TODO: Figure out how to dedup these outputs. I tried doing something but `args` returns an `&mut` which complicates things
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand All @@ -72,7 +72,7 @@ async fn test_push_tarball() {
let path = std::path::PathBuf::from(root).join("test/data/standalone");
// TODO: Figure out how to dedup these outputs. I tried doing something but `args` returns an `&mut` which complicates things
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand All @@ -96,7 +96,7 @@ async fn test_push_invoice_and_file() {
let root = std::env::var("CARGO_MANIFEST_DIR").expect("Unable to get project directory");
let base = std::path::PathBuf::from(root).join("tests/scaffolds/valid_v1");
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand All @@ -114,7 +114,7 @@ async fn test_push_invoice_and_file() {

// Now try to push a file from the bindle
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand All @@ -137,7 +137,7 @@ async fn test_get() {
setup_data(&controller.client).await;
let cachedir = tempfile::tempdir().expect("unable to set up tempdir");
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand All @@ -158,7 +158,7 @@ async fn test_get() {

// This is a sanity check test to make sure a second call triggers the code path for successfully fetching from the cache
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand All @@ -180,7 +180,7 @@ async fn test_get() {
// Now try and export to a test directory and make sure it is there
let tempdir = tempfile::tempdir().expect("Unable to set up tempdir");
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -221,7 +221,7 @@ async fn test_get_invoice() {
let tempdir = tempfile::tempdir().expect("Unable to set up tempdir");
let cachedir = tempfile::tempdir().expect("Unable to set up tempdir");
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -302,7 +302,7 @@ async fn test_get_parcel() {
let tempdir = tempfile::tempdir().expect("Unable to set up tempdir");
let cachedir = tempfile::tempdir().expect("Unable to set up tempdir");
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -337,7 +337,7 @@ async fn test_yank() {
setup_data(&controller.client).await;

let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand All @@ -358,7 +358,7 @@ async fn test_yank() {
async fn test_no_bindles() {
let controller = TestController::new(BINARY_NAME).await;
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -389,7 +389,7 @@ async fn test_package() {
let path = std::path::PathBuf::from(root).join("test/data/standalone");
// TODO: Figure out how to dedup these outputs. I tried doing something but `args` returns an `&mut` which complicates things
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -520,7 +520,7 @@ async fn test_keyring_add() {
let keyring_file = tempdir.path().join(KEYRING_FILE);

let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -574,7 +574,7 @@ async fn test_keyring_add_to_existing() {

let second_label = "Miles O'Brien <[email protected]>";
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -614,7 +614,7 @@ async fn test_fetch_host_keys() {

let controller = TestController::new(BINARY_NAME).await;
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down Expand Up @@ -654,7 +654,7 @@ async fn test_fetch_host_keys_from_specific_host() {

let controller = TestController::new(BINARY_NAME).await;
let output = std::process::Command::new("cargo")
.args(&[
.args([
"run",
"--features",
"cli",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl TestController {
pub async fn new(server_binary_name: &str) -> TestController {
let build_result = tokio::task::spawn_blocking(|| {
std::process::Command::new("cargo")
.args(&["build", "--features", "cli"])
.args(["build", "--features", "cli"])
.output()
})
.await
Expand Down Expand Up @@ -90,7 +90,7 @@ impl TestController {
.join("target/debug")
.join(server_binary_name),
)
.args(&[
.args([
"--unauthenticated",
"-d",
tempdir.path().to_string_lossy().to_string().as_str(),
Expand Down

0 comments on commit 767ec06

Please sign in to comment.