Store the dates using unix timestamps

This commit is contained in:
Rodolphe Bréard 2023-04-10 00:30:31 +02:00
parent 617230664c
commit 49493f06f7
2 changed files with 8 additions and 7 deletions

View file

@ -2,9 +2,9 @@ CREATE TABLE key_db (
selector TEXT,
sdid TEXT,
algorithm TEXT,
creation TEXT,
not_after TEXT,
revocation TEXT,
creation INTEGER,
not_after INTEGER,
revocation INTEGER,
private_key TEXT,
public_key TEXT
);

View file

@ -55,7 +55,7 @@ async fn renew_key_if_expired(
algorithm: Algorithm,
expiration: Duration,
) -> Result<Duration, ()> {
let res: Option<(OffsetDateTime,)> = sqlx::query_as(SELECT_LATEST_KEY)
let res: Option<(i64,)> = sqlx::query_as(SELECT_LATEST_KEY)
.bind(domain)
.bind(algorithm.to_string())
.fetch_optional(db)
@ -63,6 +63,7 @@ async fn renew_key_if_expired(
.map_err(|_| ())?;
match res {
Some((not_after,)) => {
let not_after = OffsetDateTime::from_unix_timestamp(not_after).map_err(|_| ())?;
log::debug!("{domain}: key is valid until {not_after}");
if not_after - expiration <= OffsetDateTime::now_utc() {
generate_key(db, cnf, domain, algorithm).await?;
@ -91,9 +92,9 @@ async fn generate_key(
.bind(selector)
.bind(domain)
.bind(algorithm.to_string())
.bind(now)
.bind(not_after)
.bind(revocation)
.bind(now.unix_timestamp())
.bind(not_after.unix_timestamp())
.bind(revocation.unix_timestamp())
.bind(priv_key)
.bind(pub_key)
.execute(db)