Skip to content

Commit 4f1550f

Browse files
authored
Merge branch 'develop' into datetime
2 parents d92249f + 8c6a86f commit 4f1550f

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

tuf/src/client.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,13 @@ where
332332
}
333333

334334
/// Create a new TUF client. It will trust and update the TUF database.
335-
pub async fn from_database(
336-
config: Config,
337-
tuf: Database<D>,
338-
local: L,
339-
remote: R,
340-
) -> Result<Self> {
341-
let (local, remote) = (Repository::new(local), Repository::new(remote));
342-
Self::new(config, tuf, local, remote).await
335+
pub fn from_database(config: Config, tuf: Database<D>, local: L, remote: R) -> Self {
336+
Self {
337+
config,
338+
tuf,
339+
local: Repository::new(local),
340+
remote: Repository::new(remote),
341+
}
343342
}
344343

345344
/// Construct a client with the given parts.
@@ -1499,9 +1498,7 @@ mod test {
14991498
Database::from_trusted_root(metadata1.root().unwrap()).unwrap(),
15001499
track_local,
15011500
track_remote,
1502-
)
1503-
.await
1504-
.unwrap(),
1501+
),
15051502
};
15061503

15071504
assert_eq!(client.tuf.trusted_root().version(), 1);
@@ -1546,13 +1543,7 @@ mod test {
15461543
);
15471544
}
15481545
ConstructorMode::FromDatabase => {
1549-
assert_eq!(
1550-
client.local_repo().take_tracks(),
1551-
vec![Track::FetchErr(
1552-
MetadataPath::root(),
1553-
MetadataVersion::Number(2)
1554-
)],
1555-
);
1546+
assert_eq!(client.local_repo().take_tracks(), vec![],);
15561547
}
15571548
};
15581549

tuf/src/interchange/cjson/shims.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ use crate::Result;
1010

1111
const SPEC_VERSION: &str = "1.0";
1212

13+
// Ensure the given spec version matches our spec version.
14+
//
15+
// We also need to handle the literal "1.0" here, despite that fact that it is not a valid version
16+
// according to the SemVer spec, because it is already baked into some of the old roots.
17+
fn valid_spec_version(other: &str) -> bool {
18+
matches!(other, "1.0" | "1.0.0")
19+
}
20+
1321
fn parse_datetime(ts: &str) -> Result<DateTime<Utc>> {
1422
DateTime::parse_from_rfc3339(ts)
1523
.map(|ts| ts.with_timezone(&Utc))
@@ -71,7 +79,7 @@ impl RootMetadata {
7179
)));
7280
}
7381

74-
if self.spec_version != SPEC_VERSION {
82+
if !valid_spec_version(&self.spec_version) {
7583
return Err(Error::Encoding(format!(
7684
"Unknown spec version {}",
7785
self.spec_version
@@ -185,7 +193,7 @@ impl TimestampMetadata {
185193
)));
186194
}
187195

188-
if self.spec_version != SPEC_VERSION {
196+
if !valid_spec_version(&self.spec_version) {
189197
return Err(Error::Encoding(format!(
190198
"Unknown spec version {}",
191199
self.spec_version
@@ -234,7 +242,7 @@ impl SnapshotMetadata {
234242
)));
235243
}
236244

237-
if self.spec_version != SPEC_VERSION {
245+
if !valid_spec_version(&self.spec_version) {
238246
return Err(Error::Encoding(format!(
239247
"Unknown spec version {}",
240248
self.spec_version
@@ -300,7 +308,7 @@ impl TargetsMetadata {
300308
)));
301309
}
302310

303-
if self.spec_version != SPEC_VERSION {
311+
if !valid_spec_version(&self.spec_version) {
304312
return Err(Error::Encoding(format!(
305313
"Unknown spec version {}",
306314
self.spec_version
@@ -576,6 +584,25 @@ mod deserialize_reject_duplicates {
576584
mod test {
577585
use super::*;
578586

587+
#[test]
588+
fn spec_version_validation() {
589+
let valid_spec_versions = ["1.0.0", "1.0"];
590+
591+
for version in valid_spec_versions {
592+
assert!(valid_spec_version(version), "{:?} should be valid", version);
593+
}
594+
595+
let invalid_spec_versions = ["1.0.1", "1.1.0", "2.0.0", "3.0"];
596+
597+
for version in invalid_spec_versions {
598+
assert!(
599+
!valid_spec_version(version),
600+
"{:?} should be invalid",
601+
version
602+
);
603+
}
604+
}
605+
579606
#[test]
580607
fn datetime_formats() {
581608
// The TUF spec says datetimes should be in ISO8601 format, specifically

0 commit comments

Comments
 (0)