Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get clippy CI job working #401

Merged
merged 9 commits into from
Feb 9, 2024
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- stable
- beta
- nightly
- "1.56.1"
- "1.63.0"
steps:
- name: Checkout repository
uses: actions/checkout@v1
Expand Down
2 changes: 2 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msrv = "1.63.0"

2 changes: 1 addition & 1 deletion interop-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT/Apache-2.0"
publish = false

[dependencies]
chrono = { version = "0.4", features = [ "serde" ] }
chrono = { version = "0.4.23", features = [ "serde" ] }
data-encoding = "2.0.0-rc.2"
futures-executor = "0.3.1"
serde = "1"
Expand Down
6 changes: 3 additions & 3 deletions interop-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn read_dir_files(path: &Path) -> BTreeMap<PathBuf, String> {
let f = fs::read_to_string(entry.path()).unwrap();

// Strip off the path prefix.
let path = entry.into_path().strip_prefix(&path).unwrap().to_path_buf();
let path = entry.into_path().strip_prefix(path).unwrap().to_path_buf();

entries.insert(path, f);
}
Expand All @@ -112,7 +112,7 @@ async fn update_root(
consistent_snapshot: bool,
) {
// Same expiration as go-tuf metadata generator.
let expiration = Utc.ymd(2100, 1, 1).and_hms(0, 0, 0);
let expiration = Utc.with_ymd_and_hms(2100, 1, 1, 0, 0, 0).unwrap();

let mut repo_builder = RepoBuilder::create(repo)
.trusted_root_keys(&[keys.get("root").unwrap()])
Expand Down Expand Up @@ -149,7 +149,7 @@ async fn add_target(
consistent_snapshot: bool,
) {
// Same expiration as go-tuf metadata generator.
let expiration = Utc.ymd(2100, 1, 1).and_hms(0, 0, 0);
let expiration = Utc.with_ymd_and_hms(2100, 1, 1, 0, 0, 0).unwrap();
let version: u32 = (step + 1).into();

let mut targets_builder = TargetsMetadataBuilder::new()
Expand Down
2 changes: 1 addition & 1 deletion tuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name = "tuf"
path = "./src/lib.rs"

[dependencies]
chrono = { version = "0.4", features = [ "serde" ] }
chrono = { version = "0.4.23", features = [ "serde" ] }
data-encoding = "2.0.0-rc.2"
derp = "0.0.14"
futures-io = "0.3.1"
Expand Down
14 changes: 7 additions & 7 deletions tuf/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ where
/// let root_version = 1;
/// let root = RootMetadataBuilder::new()
/// .version(root_version)
/// .expires(Utc.ymd(2038, 1, 1).and_hms(0, 0, 0))
/// .expires(Utc.with_ymd_and_hms(2038, 1, 1, 0, 0, 0).unwrap())
/// .root_key(public_key.clone())
/// .snapshot_key(public_key.clone())
/// .targets_key(public_key.clone())
Expand Down Expand Up @@ -185,7 +185,7 @@ where
/// let root_threshold = 1;
/// let raw_root = RootMetadataBuilder::new()
/// .version(root_version)
/// .expires(Utc.ymd(2038, 1, 1).and_hms(0, 0, 0))
/// .expires(Utc.with_ymd_and_hms(2038, 1, 1, 0, 0, 0).unwrap())
/// .root_key(public_key.clone())
/// .root_threshold(root_threshold)
/// .snapshot_key(public_key.clone())
Expand Down Expand Up @@ -248,7 +248,7 @@ where
/// let root_threshold = 1;
/// let root = RootMetadataBuilder::new()
/// .version(root_version)
/// .expires(Utc.ymd(2038, 1, 1).and_hms(0, 0, 0))
/// .expires(Utc.with_ymd_and_hms(2038, 1, 1, 0, 0, 0).unwrap())
/// .root_key(public_key.clone())
/// .root_threshold(root_threshold)
/// .snapshot_key(public_key.clone())
Expand Down Expand Up @@ -1433,7 +1433,7 @@ mod test {
// Store an expired root in the local store.
let mut local = EphemeralRepository::<Pouf1>::new();
let metadata1 = RepoBuilder::create(&mut local)
.current_time(Utc.timestamp(0, 0))
.current_time(Utc.timestamp_opt(0, 0).unwrap())
.trusted_root_keys(&[&KEYS[0]])
.trusted_targets_keys(&[&KEYS[0]])
.trusted_snapshot_keys(&[&KEYS[0]])
Expand Down Expand Up @@ -1698,7 +1698,7 @@ mod test {

// Store an expired root in the local store.
let metadata1 = RepoBuilder::create(&mut local)
.current_time(Utc.timestamp(0, 0))
.current_time(Utc.timestamp_opt(0, 0).unwrap())
.trusted_root_keys(&[&KEYS[0]])
.trusted_targets_keys(&[&KEYS[0]])
.trusted_snapshot_keys(&[&KEYS[0]])
Expand All @@ -1710,7 +1710,7 @@ mod test {
.unwrap();

let metadata2 = RepoBuilder::create(&mut local)
.current_time(Utc.timestamp(0, 0))
.current_time(Utc.timestamp_opt(0, 0).unwrap())
.trusted_root_keys(&[&KEYS[0]])
.trusted_targets_keys(&[&KEYS[0]])
.trusted_snapshot_keys(&[&KEYS[0]])
Expand Down Expand Up @@ -1765,7 +1765,7 @@ mod test {
.stage_root_with_builder(|bld| {
bld.version(3)
.consistent_snapshot(true)
.expires(Utc.ymd(2038, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2038, 1, 1, 0, 0, 0).unwrap())
})
.unwrap()
.stage_targets_with_builder(|bld| bld.version(2))
Expand Down
9 changes: 6 additions & 3 deletions tuf/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ fn python_tuf_compatibility_keyid_hash_algorithms() -> Option<Vec<String>> {
/// ],
/// );
/// ```
pub fn retain_supported_hashes<'a>(
hashes: &'a HashMap<HashAlgorithm, HashValue>,
pub fn retain_supported_hashes(
hashes: &HashMap<HashAlgorithm, HashValue>,
) -> Vec<(&'static HashAlgorithm, HashValue)> {
let mut data = vec![];
for alg in HASH_ALG_PREFS {
Expand Down Expand Up @@ -427,6 +427,7 @@ impl KeyType {
}
}

#[allow(clippy::format_collect)]
fn from_oid(oid: &[u8]) -> Result<Self> {
match oid {
#[cfg(feature = "unstable_rsa")]
Expand Down Expand Up @@ -998,7 +999,7 @@ impl Signature {

impl PartialOrd for Signature {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
(&self.key_id, &self.value).partial_cmp(&(&other.key_id, &other.value))
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -1564,6 +1565,7 @@ mod test {
});

let encoded: PublicKey = serde_json::from_value(original.clone()).unwrap();
#[allow(clippy::needless_borrows_for_generic_args)]
let decoded = serde_json::to_value(&encoded).unwrap();

assert_eq!(original, decoded);
Expand All @@ -1587,6 +1589,7 @@ mod test {
});

let encoded: PublicKey = serde_json::from_value(original.clone()).unwrap();
#[allow(clippy::needless_borrows_for_generic_args)]
let decoded = serde_json::to_value(&encoded).unwrap();

assert_eq!(original, decoded);
Expand Down
32 changes: 15 additions & 17 deletions tuf/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,7 @@ where
/// Construct a new `SignedMetadata` using the included signatures, sorting the signatures by
/// `KeyId`.
pub fn build(self) -> SignedMetadata<D, M> {
let mut signatures = self
.signatures
.into_iter()
.map(|(_k, v)| v)
.collect::<Vec<_>>();
let mut signatures = self.signatures.into_values().collect::<Vec<_>>();
signatures.sort_unstable_by(|a, b| a.key_id().cmp(b.key_id()));

SignedMetadata {
Expand Down Expand Up @@ -2470,7 +2466,7 @@ mod test {
let timestamp_key = Ed25519PrivateKey::from_pkcs8(ED25519_4_PK8).unwrap();

let root = RootMetadataBuilder::new()
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.root_key(root_key.public().clone())
.snapshot_key(snapshot_key.public().clone())
.targets_key(targets_key.public().clone())
Expand Down Expand Up @@ -2820,7 +2816,7 @@ mod test {
.unwrap();

let timestamp = TimestampMetadataBuilder::from_metadata_description(description)
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.build()
.unwrap();

Expand Down Expand Up @@ -2852,7 +2848,7 @@ mod test {
let description = MetadataDescription::new(1, None, HashMap::new()).unwrap();

let timestamp = TimestampMetadataBuilder::from_metadata_description(description)
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.build()
.unwrap();

Expand Down Expand Up @@ -2925,7 +2921,7 @@ mod test {
#[test]
fn serde_snapshot_metadata() {
let snapshot = SnapshotMetadataBuilder::new()
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.insert_metadata_description(
MetadataPath::new("targets").unwrap(),
MetadataDescription::new(
Expand Down Expand Up @@ -2964,7 +2960,7 @@ mod test {
#[test]
fn serde_snapshot_optional_length_and_hashes() {
let snapshot = SnapshotMetadataBuilder::new()
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.insert_metadata_description(
MetadataPath::new("targets").unwrap(),
MetadataDescription::new(1, None, HashMap::new()).unwrap(),
Expand Down Expand Up @@ -2994,7 +2990,7 @@ mod test {
fn serde_targets_metadata() {
block_on(async {
let targets = TargetsMetadataBuilder::new()
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.insert_target_from_slice(
TargetPath::new("insert-target-from-slice").unwrap(),
&b"foo"[..],
Expand Down Expand Up @@ -3098,7 +3094,7 @@ mod test {
.unwrap();

let targets = TargetsMetadataBuilder::new()
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.delegations(delegations)
.build()
.unwrap();
Expand Down Expand Up @@ -3142,7 +3138,7 @@ mod test {
#[test]
fn serde_signed_metadata() {
let snapshot = SnapshotMetadataBuilder::new()
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.insert_metadata_description(
MetadataPath::new("targets").unwrap(),
MetadataDescription::new(
Expand Down Expand Up @@ -3222,7 +3218,7 @@ mod test {
let timestamp_key = Ed25519PrivateKey::from_pkcs8(ED25519_4_PK8).unwrap();

let root = RootMetadataBuilder::new()
.expires(Utc.ymd(2038, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2038, 1, 1, 0, 0, 0).unwrap())
.root_key(root_key.public().clone())
.snapshot_key(snapshot_key.public().clone())
.targets_key(targets_key.public().clone())
Expand All @@ -3235,10 +3231,11 @@ mod test {

fn make_snapshot() -> serde_json::Value {
let snapshot = SnapshotMetadataBuilder::new()
.expires(Utc.ymd(2038, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2038, 1, 1, 0, 0, 0).unwrap())
.build()
.unwrap();

#[allow(clippy::needless_borrows_for_generic_args)]
serde_json::to_value(&snapshot).unwrap()
}

Expand All @@ -3247,17 +3244,18 @@ mod test {
MetadataDescription::from_slice(&[][..], 1, &[HashAlgorithm::Sha256]).unwrap();

let timestamp = TimestampMetadataBuilder::from_metadata_description(description)
.expires(Utc.ymd(2017, 1, 1).and_hms(0, 0, 0))
.expires(Utc.with_ymd_and_hms(2017, 1, 1, 0, 0, 0).unwrap())
.build()
.unwrap();

#[allow(clippy::needless_borrows_for_generic_args)]
serde_json::to_value(&timestamp).unwrap()
}

fn make_targets() -> serde_json::Value {
let targets = TargetsMetadata::new(
1,
Utc.ymd(2038, 1, 1).and_hms(0, 0, 0),
Utc.with_ymd_and_hms(2038, 1, 1, 0, 0, 0).unwrap(),
hashmap!(),
Delegations::default(),
)
Expand Down
Loading
Loading