Struct tor_hscrypto::time::TimePeriod

source ·
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 from_parts( length: u32, interval_num: u64, epoch_offset_in_sec: u32 ) -> Self

Compute the TimePeriod, given its length (in minutes), index (the number of time periods that have passed since the unix epoch), and offset from the epoch (in seconds).

The epoch_offset_in_sec value is the number of seconds after the Unix epoch when our epoch begins, rounded down to the nearest second. Note that this is not the time_t at which this Time Period begins.

The returned TP begins at the time_t interval_num * length * 60 + epoch_offset_in_sec and ends length * 60 seconds later.

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.

source

pub fn epoch_offset_in_sec(&self) -> u32

Return our offset from the epoch, in seconds.

Note that this is not the start of the TP. See TimePeriod::from_parts.

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 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 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 StructuralPartialEq for TimePeriod

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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 T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more