Merge pull request #165 from erickt/2018
clean up some post-2018 code, fix clippy suggestions
diff --git a/src/client.rs b/src/client.rs
index 80c83c3..24f6c99 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -3,51 +3,48 @@
//! # Example
//!
//! ```no_run
-//! extern crate hyper;
-//! extern crate tuf;
-//!
-//! use hyper::client::Client as HttpClient;
-//! use hyper::Url;
-//! use std::path::PathBuf;
-//! use tuf::Tuf;
-//! use tuf::crypto::KeyId;
-//! use tuf::client::{Client, Config};
-//! use tuf::metadata::{RootMetadata, SignedMetadata, Role, MetadataPath,
-//! MetadataVersion};
-//! use tuf::interchange::Json;
-//! use tuf::repository::{Repository, FileSystemRepository, HttpRepository};
-//!
+//! # use hyper::client::Client as HttpClient;
+//! # use hyper::Url;
+//! # use std::path::PathBuf;
+//! # use tuf::Tuf;
+//! # use tuf::crypto::KeyId;
+//! # use tuf::client::{Client, Config};
+//! # use tuf::metadata::{RootMetadata, SignedMetadata, Role, MetadataPath,
+//! # MetadataVersion};
+//! # use tuf::interchange::Json;
+//! # use tuf::repository::{Repository, FileSystemRepository, HttpRepository};
//! static TRUSTED_ROOT_KEY_IDS: &'static [&str] = &[
//! "diNfThTFm0PI8R-Bq7NztUIvZbZiaC_weJBgcqaHlWw=",
//! "ar9AgoRsmeEcf6Ponta_1TZu1ds5uXbDemBig30O7ck=",
//! "T5vfRrM1iHpgzGwAHe7MbJH_7r4chkOAphV3OPCCv0I=",
//! ];
//!
-//! fn main() {
-//! let key_ids: Vec<KeyId> = TRUSTED_ROOT_KEY_IDS.iter()
-//! .map(|k| KeyId::from_string(k).unwrap())
-//! .collect();
+//! # fn main() {
+//! let key_ids: Vec<KeyId> = TRUSTED_ROOT_KEY_IDS.iter()
+//! .map(|k| KeyId::from_string(k).unwrap())
+//! .collect();
//!
-//! let local = FileSystemRepository::<Json>::new(PathBuf::from("~/.rustup"))
-//! .unwrap();
+//! let local = FileSystemRepository::<Json>::new(PathBuf::from("~/.rustup"))
+//! .unwrap();
//!
-//! let remote = HttpRepository::new(
-//! Url::parse("https://static.rust-lang.org/").unwrap(),
-//! HttpClient::new(),
-//! Some("rustup/1.4.0".into()),
-//! None);
+//! let remote = HttpRepository::new(
+//! Url::parse("https://static.rust-lang.org/").unwrap(),
+//! HttpClient::new(),
+//! Some("rustup/1.4.0".into()),
+//! None);
//!
-//! let mut client = Client::with_root_pinned(
-//! &key_ids,
-//! Config::default(),
-//! local,
-//! remote,
-//! ).unwrap();
-//! let _ = client.update().unwrap();
-//! }
+//! let mut client = Client::with_root_pinned(
+//! &key_ids,
+//! Config::default(),
+//! local,
+//! remote,
+//! ).unwrap();
+//! let _ = client.update().unwrap();
+//! # }
//! ```
use chrono::offset::Utc;
+use log::{error, warn};
use std::io::{Read, Write};
use crate::crypto::{self, KeyId};
@@ -774,6 +771,7 @@
};
use crate::repository::EphemeralRepository;
use chrono::prelude::*;
+ use lazy_static::lazy_static;
use std::u32;
lazy_static! {
diff --git a/src/crypto.rs b/src/crypto.rs
index 288ea72..c4d733f 100644
--- a/src/crypto.rs
+++ b/src/crypto.rs
@@ -11,6 +11,7 @@
};
use serde::de::{Deserialize, Deserializer, Error as DeserializeError};
use serde::ser::{Error as SerializeError, Serialize, Serializer};
+use serde_derive::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt::{self, Debug, Display};
@@ -378,17 +379,15 @@
/// ```
///
/// ```no_run
- /// extern crate ring;
- /// use ring::rand::SystemRandom;
- /// use ring::signature::Ed25519KeyPair;
- /// use std::fs::File;
- /// use std::io::Write;
- ///
- /// fn main() {
- /// let mut file = File::open("ed25519-private-key.pk8").unwrap();
- /// let key = Ed25519KeyPair::generate_pkcs8(&SystemRandom::new()).unwrap();
- /// file.write_all(&key).unwrap()
- /// }
+ /// # use ring::rand::SystemRandom;
+ /// # use ring::signature::Ed25519KeyPair;
+ /// # use std::fs::File;
+ /// # use std::io::Write;
+ /// # fn main() {
+ /// let mut file = File::open("ed25519-private-key.pk8").unwrap();
+ /// let key = Ed25519KeyPair::generate_pkcs8(&SystemRandom::new()).unwrap();
+ /// file.write_all(&key).unwrap()
+ /// # }
/// ```
///
/// ## RSA
diff --git a/src/interchange/mod.rs b/src/interchange/mod.rs
index 8bdcb6f..47ea192 100644
--- a/src/interchange/mod.rs
+++ b/src/interchange/mod.rs
@@ -242,13 +242,10 @@
}
/// ```
- /// # #[macro_use]
- /// # extern crate serde_derive;
- /// # #[macro_use]
- /// # extern crate serde_json;
- /// # extern crate tuf;
- /// # use tuf::interchange::{DataInterchange, Json};
+ /// # use serde_derive::Deserialize;
+ /// # use serde_json::json;
/// # use std::collections::HashMap;
+ /// # use tuf::interchange::{DataInterchange, Json};
/// #
/// #[derive(Deserialize, Debug, PartialEq)]
/// struct Thing {
@@ -271,13 +268,10 @@
}
/// ```
- /// # #[macro_use]
- /// # extern crate serde_derive;
- /// # #[macro_use]
- /// # extern crate serde_json;
- /// # extern crate tuf;
- /// # use tuf::interchange::{DataInterchange, Json};
+ /// # use serde_derive::Serialize;
+ /// # use serde_json::json;
/// # use std::collections::HashMap;
+ /// # use tuf::interchange::{DataInterchange, Json};
/// #
/// #[derive(Serialize)]
/// struct Thing {
diff --git a/src/lib.rs b/src/lib.rs
index 1d6f125..d049b96 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -102,53 +102,28 @@
//! metadata on every update.
#![deny(missing_docs)]
-#![cfg_attr(
- feature = "cargo-clippy",
- allow(
- collapsible_if,
- implicit_hasher,
- new_ret_no_self,
- op_ref,
- too_many_arguments
- )
+#![allow(
+ clippy::collapsible_if,
+ clippy::implicit_hasher,
+ clippy::new_ret_no_self,
+ clippy::op_ref,
+ clippy::too_many_arguments
)]
-extern crate chrono;
-extern crate data_encoding;
-extern crate derp;
-extern crate hyper;
-extern crate itoa;
-#[cfg(test)]
-#[macro_use]
-extern crate lazy_static;
-#[macro_use]
-extern crate log;
-#[cfg(test)]
-#[macro_use]
-extern crate maplit;
-extern crate ring;
-extern crate serde;
-#[macro_use]
-extern crate serde_derive;
-extern crate serde_json;
-
-extern crate tempfile;
-extern crate untrusted;
-
-pub mod error;
-
-/// Alias for `Result<T, Error>`.
-pub type Result<T> = ::std::result::Result<T, Error>;
-
pub mod client;
pub mod crypto;
+pub mod error;
pub mod interchange;
pub mod metadata;
pub mod repository;
-mod shims;
pub mod tuf;
+
+mod shims;
mod util;
pub use crate::error::*;
pub use crate::tuf::*;
pub use crate::util::*;
+
+/// Alias for `Result<T, Error>`.
+pub type Result<T> = std::result::Result<T, Error>;
diff --git a/src/metadata.rs b/src/metadata.rs
index a25db77..15d1b5d 100644
--- a/src/metadata.rs
+++ b/src/metadata.rs
@@ -2,8 +2,10 @@
use chrono::offset::Utc;
use chrono::{DateTime, Duration};
+use log::{debug, warn};
use serde::de::{Deserialize, DeserializeOwned, Deserializer, Error as DeserializeError};
use serde::ser::{Error as SerializeError, Serialize, Serializer};
+use serde_derive::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::fmt::{self, Debug, Display};
use std::io::Read;
@@ -15,14 +17,14 @@
use crate::shims;
use crate::Result;
-#[cfg_attr(rustfmt, rustfmt_skip)]
+#[rustfmt::skip]
static PATH_ILLEGAL_COMPONENTS: &'static [&str] = &[
".", // current dir
"..", // parent dir
// TODO ? "0", // may translate to nul in windows
];
-#[cfg_attr(rustfmt, rustfmt_skip)]
+#[rustfmt::skip]
static PATH_ILLEGAL_COMPONENTS_CASE_INSENSITIVE: &'static [&str] = &[
// DOS device files
"CON",
@@ -54,7 +56,7 @@
"CONFIG$",
];
-#[cfg_attr(rustfmt, rustfmt_skip)]
+#[rustfmt::skip]
static PATH_ILLEGAL_STRINGS: &'static [&str] = &[
":", // for *nix compatibility
"\\", // for windows compatibility
@@ -254,9 +256,6 @@
/// bytes of the provided metadata with the provided scheme.
///
/// ```
- /// # extern crate chrono;
- /// # extern crate tuf;
- /// #
/// # use chrono::prelude::*;
/// # use tuf::crypto::{PrivateKey, SignatureScheme, HashAlgorithm};
/// # use tuf::interchange::Json;
@@ -290,9 +289,6 @@
/// to perform the "append" operations.
///
/// ```
- /// # extern crate chrono;
- /// # extern crate tuf;
- /// #
/// # use chrono::prelude::*;
/// # use tuf::crypto::{PrivateKey, SignatureScheme, HashAlgorithm};
/// # use tuf::interchange::Json;
@@ -367,11 +363,6 @@
/// Verify this metadata.
///
/// ```
- /// # extern crate chrono;
- /// # #[macro_use]
- /// # extern crate maplit;
- /// # extern crate tuf;
- ///
/// # use chrono::prelude::*;
/// # use tuf::crypto::{PrivateKey, SignatureScheme, HashAlgorithm};
/// # use tuf::interchange::Json;
@@ -628,6 +619,12 @@
}
}
+impl Default for RootMetadataBuilder {
+ fn default() -> Self {
+ RootMetadataBuilder::new()
+ }
+}
+
impl From<RootMetadata> for RootMetadataBuilder {
fn from(metadata: RootMetadata) -> Self {
RootMetadataBuilder {
@@ -1199,7 +1196,7 @@
path: MetadataPath,
description: MetadataDescription,
) -> Self {
- self.meta.insert(path.into(), description);
+ self.meta.insert(path, description);
self
}
@@ -1217,6 +1214,12 @@
}
}
+impl Default for SnapshotMetadataBuilder {
+ fn default() -> Self {
+ SnapshotMetadataBuilder::new()
+ }
+}
+
impl From<SnapshotMetadata> for SnapshotMetadataBuilder {
fn from(meta: SnapshotMetadata) -> Self {
SnapshotMetadataBuilder {
@@ -1458,8 +1461,6 @@
/// Read the from the given reader and calculate the size and hash values.
///
/// ```
- /// extern crate data_encoding;
- /// extern crate tuf;
/// use data_encoding::BASE64URL;
/// use tuf::crypto::{HashAlgorithm,HashValue};
/// use tuf::metadata::TargetDescription;
@@ -1666,6 +1667,12 @@
}
}
+impl Default for TargetsMetadataBuilder {
+ fn default() -> Self {
+ TargetsMetadataBuilder::new()
+ }
+}
+
/// Wrapper to described a collections of delegations.
#[derive(Debug, PartialEq, Clone)]
pub struct Delegations {
@@ -1833,6 +1840,7 @@
use crate::crypto::SignatureScheme;
use crate::interchange::Json;
use chrono::prelude::*;
+ use maplit::{hashmap, hashset};
use serde_json::json;
const ED25519_1_PK8: &'static [u8] = include_bytes!("../tests/ed25519/ed25519-1.pk8.der");
diff --git a/src/repository.rs b/src/repository.rs
index 3d68917..686a93f 100644
--- a/src/repository.rs
+++ b/src/repository.rs
@@ -4,6 +4,7 @@
use hyper::header::{Headers, UserAgent};
use hyper::status::StatusCode;
use hyper::{Client, Url};
+use log::debug;
use std::collections::HashMap;
use std::fs::{DirBuilder, File};
use std::io::{self, Cursor, Read, Write};
@@ -382,13 +383,15 @@
}
}
+type ArcHashMap<K, V> = Arc<RwLock<HashMap<K, V>>>;
+
/// An ephemeral repository contained solely in memory.
pub struct EphemeralRepository<D>
where
D: DataInterchange,
{
- metadata: Arc<RwLock<HashMap<(MetadataPath, MetadataVersion), Vec<u8>>>>,
- targets: Arc<RwLock<HashMap<TargetPath, Vec<u8>>>>,
+ metadata: ArcHashMap<(MetadataPath, MetadataVersion), Vec<u8>>,
+ targets: ArcHashMap<TargetPath, Vec<u8>>,
interchange: PhantomData<D>,
}
diff --git a/src/shims.rs b/src/shims.rs
index 88072a2..ebf2d4c 100644
--- a/src/shims.rs
+++ b/src/shims.rs
@@ -1,6 +1,7 @@
use chrono::offset::Utc;
use chrono::prelude::*;
use data_encoding::BASE64URL;
+use serde_derive::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::iter::FromIterator;
diff --git a/src/tuf.rs b/src/tuf.rs
index 26f2297..08d61f7 100644
--- a/src/tuf.rs
+++ b/src/tuf.rs
@@ -1,6 +1,7 @@
//! Components needed to verify TUF metadata and targets.
use chrono::offset::Utc;
+use log::info;
use std::collections::{HashMap, HashSet};
use std::marker::PhantomData;
@@ -628,6 +629,7 @@
RootMetadataBuilder, SnapshotMetadataBuilder, TargetsMetadataBuilder,
TimestampMetadataBuilder,
};
+ use lazy_static::lazy_static;
lazy_static! {
static ref KEYS: Vec<PrivateKey> = {