[−][src]Struct sequoia_openpgp::types::Timestamp
A timestamp representable by OpenPGP.
Implementations
impl Timestamp
[src]
pub fn now() -> Timestamp
[src]
Returns the current time.
pub fn checked_add(&self, d: Duration) -> Option<Timestamp>
[src]
Adds a duration to this timestamp.
Returns None
if the resulting timestamp is not
representable.
pub fn checked_sub(&self, d: Duration) -> Option<Timestamp>
[src]
Subtracts a duration from this timestamp.
Returns None
if the resulting timestamp is not
representable.
pub fn round_down<P, F>(&self, precision: P, floor: F) -> Result<Timestamp> where
P: Into<Option<u8>>,
F: Into<Option<SystemTime>>,
[src]
P: Into<Option<u8>>,
F: Into<Option<SystemTime>>,
Rounds down to the given level of precision.
This can be used to reduce the metadata leak resulting from time stamps. For example, a group of people attending a key signing event could be identified by comparing the time stamps of resulting certifications. By rounding the creation time of these signatures down, all of them, and others, fall into the same bucket.
The given level p
determines the resulting resolution of
2^p
seconds. The default is 21
, which results in a
resolution of 24 days, or roughly a month. p
must be lower
than 32.
The lower limit floor
represents the earliest time the timestamp will be
rounded down to.
See also Duration::round_up
.
Important note
If we create a signature, it is important that the signature's
creation time does not predate the signing keys creation time,
or otherwise violate the key's validity constraints.
This can be achieved by using the floor
parameter.
To ensure validity, use this function to round the time down, using the latest known relevant timestamp as a floor. Then, lookup all keys and other objects like userids using this timestamp, and on success create the signature:
use sequoia_openpgp::policy::StandardPolicy; let policy = &StandardPolicy::new(); // Let's fix a time. let now = Timestamp::from(1583436160); let cert_creation_alice = now.checked_sub(Duration::weeks(2)?).unwrap(); let cert_creation_bob = now.checked_sub(Duration::weeks(1)?).unwrap(); // Generate a Cert for Alice. let (alice, _) = CertBuilder::new() .set_creation_time(cert_creation_alice) .set_primary_key_flags(KeyFlags::default().set_certification(true)) .add_userid("alice@example.org") .generate()?; // Generate a Cert for Bob. let (bob, _) = CertBuilder::new() .set_creation_time(cert_creation_bob) .set_primary_key_flags(KeyFlags::default().set_certification(true)) .add_userid("bob@example.org") .generate()?; let sign_with_p = |p| -> Result<Signature> { // Round `now` down, then use `t` for all lookups. // Use the creation time of Bob's Cert as lower bound for rounding. let t: std::time::SystemTime = now.round_down(p, cert_creation_bob)?.into(); // First, get the certification key. let mut keypair = alice.keys().with_policy(policy, t).secret().for_certification() .nth(0).ok_or_else(|| anyhow::anyhow!("no valid key at"))? .key().clone().into_keypair()?; // Then, lookup the binding between `bob@example.org` and // `bob` at `t`. let ca = bob.userids().with_policy(policy, t) .filter(|ca| ca.userid().value() == b"bob@example.org") .nth(0).ok_or_else(|| anyhow::anyhow!("no valid userid"))?; // Finally, Alice certifies the binding between // `bob@example.org` and `bob` at `t`. ca.userid().certify(&mut keypair, &bob, SignatureType::PositiveCertification, None, t) }; assert!(sign_with_p(21).is_ok()); assert!(sign_with_p(22).is_ok()); // Rounded to bob's cert's creation time. assert!(sign_with_p(32).is_err()); // Invalid precision
Trait Implementations
impl Arbitrary for Timestamp
[src]
fn arbitrary<G: Gen>(g: &mut G) -> Self
[src]
fn shrink(&self) -> Box<dyn Iterator<Item = Self> + 'static>
[src]
impl Clone for Timestamp
[src]
impl Copy for Timestamp
[src]
impl Debug for Timestamp
[src]
impl Display for Timestamp
[src]
impl Eq for Timestamp
[src]
impl From<Timestamp> for u32
[src]
impl From<Timestamp> for SystemTime
[src]
impl From<Timestamp> for Option<SystemTime>
[src]
impl From<u32> for Timestamp
[src]
impl Hash for Timestamp
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Timestamp
[src]
fn cmp(&self, other: &Timestamp) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Timestamp> for Timestamp
[src]
impl PartialOrd<Timestamp> for Timestamp
[src]
fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
[src]
fn lt(&self, other: &Timestamp) -> bool
[src]
fn le(&self, other: &Timestamp) -> bool
[src]
fn gt(&self, other: &Timestamp) -> bool
[src]
fn ge(&self, other: &Timestamp) -> bool
[src]
impl StructuralEq for Timestamp
[src]
impl StructuralPartialEq for Timestamp
[src]
impl TryFrom<SystemTime> for Timestamp
[src]
Auto Trait Implementations
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,