Add conversion implementations

This commit is contained in:
Heiko Schaefer 2021-07-14 22:31:00 +02:00
parent c445757633
commit ec8c15cab3

View file

@ -9,10 +9,25 @@ use std::fmt;
use crate::errors::OpenpgpCardError; use crate::errors::OpenpgpCardError;
use crate::parse::KeySet; use crate::parse::KeySet;
use chrono::{DateTime, NaiveDateTime, Utc};
#[derive(Clone, Eq, PartialEq, Debug)] #[derive(Clone, Eq, PartialEq, Debug)]
pub struct KeyGeneration(u32); pub struct KeyGeneration(u32);
impl From<KeyGeneration> for DateTime<Utc> {
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<u32> for KeyGeneration { impl From<u32> for KeyGeneration {
fn from(data: u32) -> Self { fn from(data: u32) -> Self {
Self(data) Self(data)