Skip to content

Commit

Permalink
Remove MetadataMetadata type
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Wells committed Feb 14, 2020
1 parent 81b100f commit c1f01d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 45 deletions.
5 changes: 1 addition & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,7 @@ where
// Root metadata is signed by its own keys, but we should only trust it if it is also
// signed by the previous root metadata, which we can't check without knowing what version
// this root metadata claims to be.
let latest_version = {
let untrusted_latest_info = latest_root.untrusted_info()?;
untrusted_latest_info.version()
};
let latest_version = latest_root.parse_version_untrusted()?;

if latest_version < self.tuf.root().version() {
return Err(Error::VerificationFailure(format!(
Expand Down
53 changes: 12 additions & 41 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,18 @@ where
&self.signatures
}

// Unexported method to allow the builders to determine the version of signed metadata.
fn parse_version_untrusted(&self) -> Result<u32> {
let meta: MetadataMetadata<M> = D::deserialize(&self.metadata)?;
/// Parse the version number of this metadata without verifying signatures.
///
/// This operation is generally unsafe to do with metadata obtained from an untrusted source,
/// but rolling forward to the most recent root.json requires using the version number of the
/// latest root.json.
pub(crate) fn parse_version_untrusted(&self) -> Result<u32> {
#[derive(Deserialize)]
pub struct MetadataVersion {
version: u32,
}

let meta: MetadataVersion = D::deserialize(&self.metadata)?;
Ok(meta.version)
}

Expand Down Expand Up @@ -586,44 +595,6 @@ where
}
}

impl<D> SignedMetadata<D, RootMetadata>
where
D: DataInterchange,
{
/// Parse common metadata fields from this metadata without verifying signatures.
///
/// This operation is generally unsafe to do with metadata obtained from an untrusted source,
/// but rolling forward to the most recent root.json requires using the version number of the
/// latest root.json.
pub fn untrusted_info(&self) -> Result<MetadataMetadata<RootMetadata>> {
D::deserialize(&self.metadata)
}
}

/// Metadata common to all signed metadata files.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MetadataMetadata<M> {
version: u32,
expires: DateTime<Utc>,
#[serde(skip_serializing, skip_deserializing)]
_metadata: PhantomData<M>,
}

impl<M> Metadata for MetadataMetadata<M>
where
M: Metadata,
{
const ROLE: Role = M::ROLE;

fn version(&self) -> u32 {
self.version
}

fn expires(&self) -> &DateTime<Utc> {
&self.expires
}
}

/// Helper to construct `RootMetadata`.
pub struct RootMetadataBuilder {
version: u32,
Expand Down

0 comments on commit c1f01d1

Please sign in to comment.