Enforce that the periods in a consensus lifetime are nonempty.
To be valid, a lifetime must have valid_after < fresh_until < valid_until.
This commit is contained in:
parent
402d501020
commit
6ddf55f799
|
@ -764,7 +764,8 @@ mod test {
|
|||
now.into(),
|
||||
(now + one_hour).into(),
|
||||
(now + one_hour * 2).into(),
|
||||
),
|
||||
)
|
||||
.unwrap(),
|
||||
[0xAB; 32],
|
||||
[0xBC; 32],
|
||||
);
|
||||
|
|
|
@ -87,11 +87,15 @@ impl Lifetime {
|
|||
valid_after: time::SystemTime,
|
||||
fresh_until: time::SystemTime,
|
||||
valid_until: time::SystemTime,
|
||||
) -> Self {
|
||||
Lifetime {
|
||||
valid_after,
|
||||
fresh_until,
|
||||
valid_until,
|
||||
) -> Result<Self> {
|
||||
if valid_after < fresh_until && fresh_until < valid_until {
|
||||
Ok(Lifetime {
|
||||
valid_after,
|
||||
fresh_until,
|
||||
valid_until,
|
||||
})
|
||||
} else {
|
||||
Err(Error::InvalidLifetime)
|
||||
}
|
||||
}
|
||||
/// Return time when this consensus first becomes valid.
|
||||
|
@ -792,7 +796,7 @@ impl CommonHeader {
|
|||
.args_as_str()
|
||||
.parse::<ISO8601TimeSp>()?
|
||||
.into();
|
||||
let lifetime = Lifetime::new(valid_after, fresh_until, valid_until);
|
||||
let lifetime = Lifetime::new(valid_after, fresh_until, valid_until)?;
|
||||
|
||||
let client_versions = sec
|
||||
.maybe(CLIENT_VERSIONS)
|
||||
|
|
|
@ -265,6 +265,9 @@ pub enum Error {
|
|||
/// Items not sorted as expected
|
||||
#[error("Incorrect sort order{0}")]
|
||||
WrongSortOrder(Pos),
|
||||
/// A consensus lifetime was ill-formed.
|
||||
#[error("Invalid consensus lifetime")]
|
||||
InvalidLifetime,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
|
@ -302,6 +305,7 @@ impl Error {
|
|||
WrongStartingToken(_, p) => Some(p),
|
||||
WrongEndingToken(_, p) => Some(p),
|
||||
WrongSortOrder(p) => Some(p),
|
||||
InvalidLifetime => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,6 +345,7 @@ impl Error {
|
|||
WrongStartingToken(_, p) => Some(p),
|
||||
WrongEndingToken(_, p) => Some(p),
|
||||
WrongSortOrder(p) => Some(p),
|
||||
InvalidLifetime => None,
|
||||
};
|
||||
*pos.unwrap_or(&Pos::Unknown)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue