The deadline a TTL of `ttl_secs` from `now` means, or [`GrantError::InvalidTtl`]. Checked arithmetic throughout: the TTL comes off the wire, and a request this refuses must be an error, never a panic inside a store's lock.
(now: DateTime<Utc>, ttl_secs: u64)
| 226 | /// off the wire, and a request this refuses must be an error, never a panic |
| 227 | /// inside a store's lock. |
| 228 | pub fn grant_deadline(now: DateTime<Utc>, ttl_secs: u64) -> Result<DateTime<Utc>, GrantError> { |
| 229 | if !(MIN_TTL_SECS..=MAX_TTL_SECS).contains(&ttl_secs) { |
| 230 | return Err(GrantError::InvalidTtl); |
| 231 | } |
| 232 | let secs = i64::try_from(ttl_secs).map_err(|_| GrantError::InvalidTtl)?; |
| 233 | let ttl = Duration::try_seconds(secs).ok_or(GrantError::InvalidTtl)?; |
| 234 | now.checked_add_signed(ttl).ok_or(GrantError::InvalidTtl) |
| 235 | } |
| 236 | |
| 237 | /// A requested capability list as a grant's set: nonempty, and every entry |
| 238 | /// delegable. |