diff --git a/openpgp-card/src/parse/key_generation_times.rs b/openpgp-card/src/parse/key_generation_times.rs index b1ce671..b5c5ce0 100644 --- a/openpgp-card/src/parse/key_generation_times.rs +++ b/openpgp-card/src/parse/key_generation_times.rs @@ -9,10 +9,25 @@ use std::fmt; use crate::errors::OpenpgpCardError; use crate::parse::KeySet; +use chrono::{DateTime, NaiveDateTime, Utc}; #[derive(Clone, Eq, PartialEq, Debug)] pub struct KeyGeneration(u32); +impl From for DateTime { + fn from(kg: KeyGeneration) -> Self { + let naive_datetime = NaiveDateTime::from_timestamp(kg.0 as i64, 0); + + DateTime::from_utc(naive_datetime, Utc) + } +} + +impl From<&KeyGeneration> for u32 { + fn from(kg: &KeyGeneration) -> Self { + kg.0 + } +} + impl From for KeyGeneration { fn from(data: u32) -> Self { Self(data)