Skip to content
31 changes: 16 additions & 15 deletions tuf/src/interchange/cjson/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ 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")
DateTime::parse_from_rfc3339(ts)
.map(|ts| ts.with_timezone(&Utc))
.map_err(|e| Error::Encoding(format!("Can't parse DateTime: {:?}", e)))
}

fn format_datetime(ts: &DateTime<Utc>) -> String {
format!(
"{:04}-{:02}-{:02}T{:02}:{:02}:{:02}Z",
ts.year(),
ts.month(),
ts.day(),
ts.hour(),
ts.minute(),
ts.second()
)
ts.to_rfc3339()
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -70,7 +71,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
Expand Down Expand Up @@ -184,7 +185,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
Expand Down Expand Up @@ -233,7 +234,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
Expand Down Expand Up @@ -299,7 +300,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
Expand Down
2 changes: 1 addition & 1 deletion tuf/src/interchange/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::fmt::Debug;
use crate::Result;

/// The format used for data interchange, serialization, and deserialization.
pub trait DataInterchange: Debug + PartialEq + Clone {
pub trait DataInterchange: Debug + PartialEq + Clone + Send {
/// The type of data that is contained in the `signed` portion of metadata.
type RawData: Serialize + DeserializeOwned + Clone + PartialEq;

Expand Down
1 change: 0 additions & 1 deletion tuf/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ static PATH_ILLEGAL_STRINGS: &[&str] = &[
"\"",
"|",
"?",
"*",
// control characters, all illegal in FAT
"\u{000}",
"\u{001}",
Expand Down
2 changes: 1 addition & 1 deletion tuf/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where

/// A writable TUF repository. Most implementors of this trait should also implement
/// `RepositoryProvider`.
pub trait RepositoryStorage<D>
pub trait RepositoryStorage<D>: Send
where
D: DataInterchange + Sync,
{
Expand Down