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

Tweaks to better interop with go-tuf #377

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Next Next commit
adjust spec_version to proper semver format
Signed-off-by: Luke Steensen <luke.steensen@gmail.com>
lukesteensen committed Aug 30, 2022
commit 3d8cb88d00ecaecff0c3c7368fdb03abb715a349
18 changes: 13 additions & 5 deletions tuf/src/interchange/cjson/shims.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,15 @@ use crate::error::Error;
use crate::metadata::{self, Metadata};
use crate::Result;

const SPEC_VERSION: &str = "1.0";
const SPEC_VERSION: &str = "1.0.0";

// Ensure the given spec version matches our spec version.
//
// We also need to handle the literal "1.0" here, despite that fact that it is not a valid version
// according to the SemVer spec, because it is already baked into some of the old roots.
fn valid_spec_version(other: &str) -> bool {
other == SPEC_VERSION || other == "1.0"
}

fn parse_datetime(ts: &str) -> Result<DateTime<Utc>> {
Utc.datetime_from_str(ts, "%FT%TZ")
@@ -70,7 +78,7 @@ impl RootMetadata {
)));
}

if self.spec_version != SPEC_VERSION {
if !valid_spec_version(&self.spec_version) {
return Err(Error::Encoding(format!(
"Unknown spec version {}",
self.spec_version
@@ -184,7 +192,7 @@ impl TimestampMetadata {
)));
}

if self.spec_version != SPEC_VERSION {
if !valid_spec_version(&self.spec_version) {
return Err(Error::Encoding(format!(
"Unknown spec version {}",
self.spec_version
@@ -233,7 +241,7 @@ impl SnapshotMetadata {
)));
}

if self.spec_version != SPEC_VERSION {
if !valid_spec_version(&self.spec_version) {
return Err(Error::Encoding(format!(
"Unknown spec version {}",
self.spec_version
@@ -299,7 +307,7 @@ impl TargetsMetadata {
)));
}

if self.spec_version != SPEC_VERSION {
if !valid_spec_version(&self.spec_version) {
return Err(Error::Encoding(format!(
"Unknown spec version {}",
self.spec_version