pub struct TimePeriod { /* private fields */ }
Expand description

A period of time, as used in the onion service system.

A TimePeriod is defined as a duration (in seconds), and the number of such durations that have elapsed since a given offset from the Unix epoch. So for example, the interval “(86400 seconds length, 15 intervals, 12 hours offset)”, covers 1970-01-16T12:00:00 up to but not including 1970-01-17T12:00:00.

These time periods are used to derive a different BlindedOnionIdKey during each period from each OnionIdKey.

Implementations§

source§

impl TimePeriod

source

pub fn new( length: Duration, when: SystemTime, epoch_offset: Duration ) -> Result<Self, TimePeriodError>

Construct a time period of a given length that contains when.

The length value is rounded down to the nearest second, and must then be a whole number of minutes.

The epoch_offset value is the amount of time after the Unix epoch when our epoch begins. It is also rounded down to the nearest second.

Return None if the Duration is too large or too small, or if when cannot be represented as a time period.

source

pub fn next(&self) -> Option<Self>

Return the time period after this one.

Return None if this is the last representable time period.

source

pub fn prev(&self) -> Option<Self>

Return the time period before this one.

Return None if this is the first representable time period.

source

pub fn contains(&self, when: SystemTime) -> bool

Return true if this time period contains when.

Limitations

This function always returns false if the time period contains any times that cannot be represented as a SystemTime.

source

pub fn range(&self) -> Result<Range<SystemTime>, TimePeriodError>

Return a range representing the SystemTime values contained within this time period.

Return None if this time period contains any times that can be represented as a SystemTime.

source

pub fn interval_num(&self) -> u64

Return the numeric index of this time period.

This function should only be used when encoding the time period for cryptographic purposes.

source

pub fn length(&self) -> IntegerMinutes<u32>

Return the length of this time period as a number of seconds.

This function should only be used when encoding the time period for cryptographic purposes.

Trait Implementations§

source§

impl Clone for TimePeriod

source§

fn clone(&self) -> TimePeriod

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TimePeriod

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<TimePeriod> for TimePeriod

source§

fn eq(&self, other: &TimePeriod) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<TimePeriod> for TimePeriod

Two TimePeriods are ordered with respect to one another if they have the same interval length and offset.

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for TimePeriod

source§

impl Eq for TimePeriod

source§

impl StructuralEq for TimePeriod

source§

impl StructuralPartialEq for TimePeriod

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V