pub fn update_timestamp(
        &mut self,
        raw_timestamp: &RawSignedMetadata<D, TimestampMetadata>,
    ) -> Result<Option<&Verified<TimestampMetadata>>> {
        let verified = {
            // FIXME(https://github.com/theupdateframework/specification/issues/113) Should we
            // check if the root metadata is expired here? We do that in the other `Database::update_*`
            // methods, but not here.
            let trusted_root = &self.trusted_root;

            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.1:
            //
            //     Check signatures. The new timestamp metadata file must have been signed by a
            //     threshold of keys specified in the trusted root metadata file. If the new
            //     timestamp metadata file is not properly signed, discard it, abort the update
            //     cycle, and report the signature failure.

            let new_timestamp = verify::verify_signatures(
                raw_timestamp,
                trusted_root.timestamp().threshold(),
                trusted_root.timestamp_keys(),
            )?;

            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.2: Check for a rollback attack.

            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.2.1:
            //
            //     The version number of the trusted timestamp metadata file, if any, must be less
            //     than or equal to the version number of the new timestamp metadata file. If the
            //     new timestamp metadata file is older than the trusted timestamp metadata file,
            //     discard it, abort the update cycle, and report the potential rollback attack.

            let trusted_timestamp_version = self.trusted_timestamp_version();

            match new_timestamp.version().cmp(&trusted_timestamp_version) {
                Ordering::Less => {
                    return Err(Error::VerificationFailure(format!(
                        "Attempted to roll back timestamp metadata at version {} to {}.",
                        trusted_timestamp_version,
                        new_timestamp.version()
                    )));
                }
                Ordering::Equal => {
                    return Ok(None);
                }
                Ordering::Greater => {}
            }

            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.2.2:
            //
            //     The version number of the snapshot metadata file in the trusted timestamp
            //     metadata file, if any, MUST be less than or equal to its version number in the
            //     new timestamp metadata file. If not, discard the new timestamp metadadata file,
            //     abort the update cycle, and report the failure.

            // FIXME(#294): Implement this section.

            /////////////////////////////////////////
            // FIXME(#297): forgetting the trusted snapshot here is not part of the spec. Do we need to
            // do it?

            if self.trusted_snapshot_version() != new_timestamp.snapshot().version() {
                self.trusted_snapshot = None;
            }

            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.3:
            //
            //     Check for a freeze attack. The latest known time should be lower than the
            //     expiration timestamp in the new timestamp metadata file. If so, the new
            //     timestamp metadata file becomes the trusted timestamp metadata file. If the new
            //     timestamp metadata file has expired, discard it, abort the update cycle, and
            //     report the potential freeze attack.

            if new_timestamp.expires() <= &Utc::now() {
                return Err(Error::ExpiredMetadata(Role::Timestamp));
            }

            new_timestamp
        };

        self.trusted_timestamp = Some(verified);
        Ok(self.trusted_timestamp.as_ref())
    }
/// Verify and update the timestamp metadata.
///
/// Returns a reference to the parsed metadata if the metadata was newer.
Verify and update the timestamp metadata.
Returns a reference to the parsed metadata if the metadata was newer.
Verify and update the timestamp metadata . Returns a reference to the parsed metadata if the metadata was newer .
pub fn update_timestamp(
        &mut self,
        raw_timestamp: &RawSignedMetadata<D, TimestampMetadata>,
    ) -> Result<Option<&Verified<TimestampMetadata>>> {
        let verified = {
            // FIXME(https://github.com/theupdateframework/specification/issues/113) Should we
            // check if the root metadata is expired here? We do that in the other `Database::update_*`
            // methods, but not here.
            let trusted_root = &self.trusted_root;
            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.1:
            //
            //     Check signatures. The new timestamp metadata file must have been signed by a
            //     threshold of keys specified in the trusted root metadata file. If the new
            //     timestamp metadata file is not properly signed, discard it, abort the update
            //     cycle, and report the signature failure.
            let new_timestamp = verify::verify_signatures(
                raw_timestamp,
                trusted_root.timestamp().threshold(),
                trusted_root.timestamp_keys(),
            )?;
            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.2: Check for a rollback attack.
            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.2.1:
            //
            //     The version number of the trusted timestamp metadata file, if any, must be less
            //     than or equal to the version number of the new timestamp metadata file. If the
            //     new timestamp metadata file is older than the trusted timestamp metadata file,
            //     discard it, abort the update cycle, and report the potential rollback attack.
            let trusted_timestamp_version = self.trusted_timestamp_version();
            match new_timestamp.version().cmp(&trusted_timestamp_version) {
                Ordering::Less => {
                    return Err(Error::VerificationFailure(format!(
                        "Attempted to roll back timestamp metadata at version {} to {}.",
                        trusted_timestamp_version,
                        new_timestamp.version()
                    )));
                }
                Ordering::Equal => {
                    return Ok(None);
                }
                Ordering::Greater => {}
            }
            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.2.2:
            //
            //     The version number of the snapshot metadata file in the trusted timestamp
            //     metadata file, if any, MUST be less than or equal to its version number in the
            //     new timestamp metadata file. If not, discard the new timestamp metadadata file,
            //     abort the update cycle, and report the failure.
            // FIXME(#294): Implement this section.
            /////////////////////////////////////////
            // FIXME(#297): forgetting the trusted snapshot here is not part of the spec. Do we need to
            // do it?
            if self.trusted_snapshot_version() != new_timestamp.snapshot().version() {
                self.trusted_snapshot = None;
            }
            /////////////////////////////////////////
            // TUF-1.0.5 §5.2.3:
            //
            //     Check for a freeze attack. The latest known time should be lower than the
            //     expiration timestamp in the new timestamp metadata file. If so, the new
            //     timestamp metadata file becomes the trusted timestamp metadata file. If the new
            //     timestamp metadata file has expired, discard it, abort the update cycle, and
            //     report the potential freeze attack.
            if new_timestamp.expires() <= &Utc::now() {
                return Err(Error::ExpiredMetadata(Role::Timestamp));
            }
            new_timestamp
        };
        self.trusted_timestamp = Some(verified);
        Ok(self.trusted_timestamp.as_ref())
    }
pub fn update_timestamp ( & mut self , raw_timestamp : & RawSignedMetadata < D , TimestampMetadata > , ) -> Result < Option < & Verified < TimestampMetadata > > > { let verified = { // FIXME(https://github.com/theupdateframework/specification/issues/113) Should we // check if the root metadata is expired here? We do that in the other `Database::update_*` // methods, but not here. let trusted_root = & self . trusted_root ; ///////////////////////////////////////// // TUF-1.0.5 §5.2.1: // //     Check signatures. The new timestamp metadata file must have been signed by a //     threshold of keys specified in the trusted root metadata file. If the new //     timestamp metadata file is not properly signed, discard it, abort the update //     cycle, and report the signature failure. let new_timestamp = verify :: verify_signatures ( raw_timestamp , trusted_root . timestamp ( ) . threshold ( ) , trusted_root . timestamp_keys ( ) , ) ? ; ///////////////////////////////////////// // TUF-1.0.5 §5.2.2: Check for a rollback attack. ///////////////////////////////////////// // TUF-1.0.5 §5.2.2.1: // //     The version number of the trusted timestamp metadata file, if any, must be less //     than or equal to the version number of the new timestamp metadata file. If the //     new timestamp metadata file is older than the trusted timestamp metadata file, //     discard it, abort the update cycle, and report the potential rollback attack. let trusted_timestamp_version = self . trusted_timestamp_version ( ) ; match new_timestamp . version ( ) . cmp ( & trusted_timestamp_version ) { Ordering :: Less => { return Err ( Error :: VerificationFailure ( format ! ( " " trusted_timestamp_version new_timestamp version ( ) ) ) ) ; } Ordering :: Equal => { return Ok ( None ) ; } Ordering :: Greater => { } } ///////////////////////////////////////// // TUF-1.0.5 §5.2.2.2: // //     The version number of the snapshot metadata file in the trusted timestamp //     metadata file, if any, MUST be less than or equal to its version number in the //     new timestamp metadata file. If not, discard the new timestamp metadadata file, //     abort the update cycle, and report the failure. // FIXME(#294): Implement this section. ///////////////////////////////////////// // FIXME(#297): forgetting the trusted snapshot here is not part of the spec. Do we need to // do it? if self . trusted_snapshot_version ( ) != new_timestamp . snapshot ( ) . version ( ) { self . trusted_snapshot = None ; } ///////////////////////////////////////// // TUF-1.0.5 §5.2.3: // //     Check for a freeze attack. The latest known time should be lower than the //     expiration timestamp in the new timestamp metadata file. If so, the new //     timestamp metadata file becomes the trusted timestamp metadata file. If the new //     timestamp metadata file has expired, discard it, abort the update cycle, and //     report the potential freeze attack. if new_timestamp . expires ( ) <= & Utc :: now ( ) { return Err ( Error :: ExpiredMetadata ( Role :: Timestamp ) ) ; } new_timestamp } ; self . trusted_timestamp = Some ( verified ) ; Ok ( self . trusted_timestamp . as_ref ( ) ) }
Verify and update the timestamp metadata.
Verify and update the timestamp metadata .
&mut self
raw_timestamp
&RawSignedMetadata<D, TimestampMetadata>
&mut self
raw_timestamp
&RawSignedMetadata<D, TimestampMetadata>