trust_graph/
trust_relation.rs1use crate::revoke::Revocation;
18use crate::trust::Trust;
19use failure::_core::time::Duration;
20use fluence_keypair::public_key::PublicKey;
21use fluence_keypair::Signature;
22use serde::{Deserialize, Serialize};
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct Auth {
27 pub trust: Trust,
29 pub issued_by: PublicKey,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub enum TrustRelation {
35 Auth(Auth),
36 Revocation(Revocation),
37}
38
39impl TrustRelation {
40 pub fn issued_at(&self) -> Duration {
42 match self {
43 TrustRelation::Auth(auth) => auth.trust.issued_at,
44 TrustRelation::Revocation(r) => r.revoked_at,
45 }
46 }
47
48 pub fn issued_by(&self) -> &PublicKey {
50 match self {
51 TrustRelation::Auth(auth) => &auth.issued_by,
52 TrustRelation::Revocation(r) => &r.revoked_by,
53 }
54 }
55
56 pub fn issued_for(&self) -> &PublicKey {
57 match self {
58 TrustRelation::Auth(auth) => &auth.trust.issued_for,
59 TrustRelation::Revocation(r) => &r.pk,
60 }
61 }
62
63 pub fn expires_at(&self) -> Duration {
64 match self {
65 TrustRelation::Auth(auth) => auth.trust.expires_at,
66 TrustRelation::Revocation(_) => Duration::from_secs(0),
68 }
69 }
70
71 pub fn signature(&self) -> &Signature {
72 match self {
73 TrustRelation::Auth(auth) => &auth.trust.signature,
74 TrustRelation::Revocation(r) => &r.signature,
75 }
76 }
77}