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
impl TimePeriod
sourcepub fn new(
length: Duration,
when: SystemTime,
epoch_offset: Duration
) -> Result<Self, TimePeriodError>
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.
sourcepub fn next(&self) -> Option<Self>
pub fn next(&self) -> Option<Self>
Return the time period after this one.
Return None if this is the last representable time period.
sourcepub fn prev(&self) -> Option<Self>
pub fn prev(&self) -> Option<Self>
Return the time period before this one.
Return None if this is the first representable time period.
sourcepub fn contains(&self, when: SystemTime) -> bool
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.
sourcepub fn range(&self) -> Result<Range<SystemTime>, TimePeriodError>
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.
sourcepub fn interval_num(&self) -> u64
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.
sourcepub fn length(&self) -> IntegerMinutes<u32>
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
impl Clone for TimePeriod
source§fn clone(&self) -> TimePeriod
fn clone(&self) -> TimePeriod
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for TimePeriod
impl Debug for TimePeriod
source§impl PartialEq<TimePeriod> for TimePeriod
impl PartialEq<TimePeriod> for TimePeriod
source§fn eq(&self, other: &TimePeriod) -> bool
fn eq(&self, other: &TimePeriod) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd<TimePeriod> for TimePeriod
impl PartialOrd<TimePeriod> for TimePeriod
Two TimePeriods are ordered with respect to one another if they have the
same interval length and offset.
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more