parco_ws_security/
timestamp.rs1use chrono::{DateTime, Duration, SecondsFormat, Utc};
2use parco_xml::xml;
3
4use crate::crypto::WSSUId;
5
6#[derive(Clone, Debug)]
8pub struct Timestamp {
9 pub created: DateTime<Utc>,
11 pub expires: DateTime<Utc>,
13 pub wssu_id: WSSUId,
15}
16
17impl Timestamp {
18 pub fn now(expires_in: Duration, wssu_id: WSSUId) -> Self {
20 let now = Utc::now();
21 Self {
22 created: now,
23 expires: now + expires_in,
24 wssu_id,
25 }
26 }
27}
28
29xml! {
30 use Timestamp;
31
32 @ns {
33 wssu = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
34 }
35
36 wssu:Timestamp wssu:Id=(self.wssu_id.no_hash()) {
37 wssu:Created { (self.created.to_rfc3339_opts(SecondsFormat::Millis, true)) }
38 wssu:Expires { (self.expires.to_rfc3339_opts(SecondsFormat::Millis, true)) }
39 }
40}