Skip to content

Commit

Permalink
Merge pull request #285 from wittrock/develop
Browse files Browse the repository at this point in the history
Add functions to get current trusted versions of metadata.
  • Loading branch information
erickt committed Apr 15, 2020
2 parents 62431b1 + 6a0824d commit 8c97b8d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/client.rs
Expand Up @@ -542,6 +542,31 @@ where
}
}

/// Returns the current trusted root version.
pub fn root_version(&self) -> u32 {
self.tuf.root().version()
}

/// Returns the current trusted timestamp version.
pub fn timestamp_version(&self) -> Option<u32> {
Some(self.tuf.timestamp()?.version())
}

/// Returns the current trusted snapshot version.
pub fn snapshot_version(&self) -> Option<u32> {
Some(self.tuf.snapshot()?.version())
}

/// Returns the current trusted targets version.
pub fn targets_version(&self) -> Option<u32> {
Some(self.tuf.targets()?.version())
}

/// Returns the current trusted delegations version for a given role.
pub fn delegations_version(&self, role: &MetadataPath) -> Option<u32> {
Some(self.tuf.delegations().get(role)?.version())
}

/// Returns `true` if an update occurred and `false` otherwise.
async fn update_root(&mut self) -> Result<bool> {
let root_path = MetadataPath::from_role(&Role::Root);
Expand Down Expand Up @@ -1646,6 +1671,12 @@ mod test {
assert_eq!(client.update().await, Ok(true));
assert_eq!(client.tuf.root().version(), 2);

assert_eq!(client.root_version(), 2);
assert_eq!(client.timestamp_version(), Some(1));
assert_eq!(client.snapshot_version(), Some(1));
assert_eq!(client.targets_version(), Some(1));
assert_eq!(client.delegations_version(&snapshot_path), None);

assert_eq!(
root2.to_raw().unwrap(),
client
Expand Down
2 changes: 1 addition & 1 deletion src/repository/ephemeral.rs
Expand Up @@ -29,7 +29,7 @@ impl<D> EphemeralRepository<D>
where
D: DataInterchange,
{
/// Create a new ephemercal repository.
/// Create a new ephemeral repository.
pub fn new() -> Self {
Self {
metadata: Arc::new(RwLock::new(HashMap::new())),
Expand Down

0 comments on commit 8c97b8d

Please sign in to comment.