dubp_documents/
revocation.rs

1//  Copyright (C) 2020  Éloïs SANCHEZ.
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU Affero General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16//! Wrappers around Revocation documents.
17
18pub mod v10;
19
20use crate::*;
21
22pub use v10::{
23    CompactRevocationDocumentV10, CompactRevocationDocumentV10Stringified, RevocationDocumentV10,
24    RevocationDocumentV10Stringified,
25};
26
27/// Wrap an Revocation document.
28///
29/// Must be created by parsing a text document or using a builder.
30#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
31pub enum RevocationDocument {
32    /// Revocation document v10
33    V10(RevocationDocumentV10),
34}
35
36/// Wrap an Compact Revocation document.
37///
38/// Must be created by a revocation document.
39#[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq, Eq)]
40pub enum CompactRevocationDocument {
41    /// Compact revocation document v10
42    V10(CompactRevocationDocumentV10),
43}
44
45impl Document for RevocationDocument {
46    type PublicKey = PubKeyEnum;
47
48    #[inline]
49    fn version(&self) -> usize {
50        match self {
51            RevocationDocument::V10(revoc_10) => revoc_10.version(),
52        }
53    }
54
55    #[inline]
56    fn currency(&self) -> &str {
57        match self {
58            RevocationDocument::V10(revoc_v10) => revoc_v10.currency(),
59        }
60    }
61
62    #[inline]
63    fn blockstamp(&self) -> Blockstamp {
64        match self {
65            RevocationDocument::V10(revoc_v10) => revoc_v10.blockstamp(),
66        }
67    }
68
69    #[inline]
70    fn issuers(&self) -> SmallVec<[Self::PublicKey; 1]> {
71        match self {
72            RevocationDocument::V10(revoc_v10) => {
73                svec![PubKeyEnum::Ed25519(revoc_v10.issuers()[0])]
74            }
75        }
76    }
77
78    #[inline]
79    fn signatures(&self) -> SmallVec<[<Self::PublicKey as PublicKey>::Signature; 1]> {
80        match self {
81            RevocationDocument::V10(revoc_v10) => svec![Sig::Ed25519(revoc_v10.signatures()[0])],
82        }
83    }
84
85    #[inline]
86    fn as_bytes(&self) -> BeefCow<[u8]> {
87        match self {
88            RevocationDocument::V10(revoc_v10) => revoc_v10.as_bytes(),
89        }
90    }
91}
92
93#[derive(Clone, Debug, Deserialize, Serialize)]
94pub enum RevocationDocumentStringified {
95    V10(RevocationDocumentV10Stringified),
96}
97
98impl ToStringObject for RevocationDocument {
99    type StringObject = RevocationDocumentStringified;
100
101    fn to_string_object(&self) -> Self::StringObject {
102        match self {
103            RevocationDocument::V10(idty) => {
104                RevocationDocumentStringified::V10(idty.to_string_object())
105            }
106        }
107    }
108}
109
110#[derive(Clone, Debug, Deserialize, Serialize)]
111pub enum CompactRevocationDocumentStringified {
112    V10(CompactRevocationDocumentV10Stringified),
113}
114
115impl ToStringObject for CompactRevocationDocument {
116    type StringObject = CompactRevocationDocumentStringified;
117
118    fn to_string_object(&self) -> Self::StringObject {
119        match self {
120            CompactRevocationDocument::V10(doc) => {
121                CompactRevocationDocumentStringified::V10(doc.to_string_object())
122            }
123        }
124    }
125}