/// Buffer time before key expiry to trigger rotation. This ensures we rotate slightly before the
/// C-tor uses 3 hours for the link/auth key and 1 day for the signing key. Let's use 3 hours here,
/// If the key already exists, the error is ignored as this could happen if the system time drifts
fn generate_key<K>(keymgr: &KeyMgr, spec: &dyn KeySpecifier) -> Result<(), tor_keymgr::Error>
/// Returns `(removed, min_remaining)` where `removed` indicates whether any entry was deleted and
/// Attempt to generate a key and cert using the given [`KeyCertificateSpecifier`] which is signed
/// [`RelaySigningKeyCert`]. Note that identity keys are NOT generated within this function, it is
/// Returns the minimum valid until value if a key was generated. Else, a None value indicates that
let ntor_generated = try_generate_key::<RelayNtorKeypair, RelayNtorKeypairSpecifierPattern, _>(
/// Return (`removed`, `next_expiry`) where the `removed` indicates if at least one key has been
/// removed because it was expired. The `next_expiry` is the minimum value of all valid_until which
fn try_rotate_keys(now: SystemTime, keymgr: &KeyMgr) -> anyhow::Result<(KeyChange, SystemTime)> {