1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use crate::{id, proof, Result};
use chrono::{self, prelude::*};
use crev_common::{
self,
serde::{as_rfc3339_fixed, from_rfc3339_fixed},
};
use serde_yaml;
use std::{default::Default, fmt};
const BEGIN_BLOCK: &str = "-----BEGIN CREV PACKAGE REVIEW-----";
const BEGIN_SIGNATURE: &str = "-----BEGIN CREV PACKAGE REVIEW SIGNATURE-----";
const END_BLOCK: &str = "-----END CREV PACKAGE REVIEW-----";
const CURRENT_PACKAGE_REVIEW_PROOF_SERIALIZATION_VERSION: i64 = -1;
fn cur_version() -> i64 {
CURRENT_PACKAGE_REVIEW_PROOF_SERIALIZATION_VERSION
}
#[derive(Clone, Builder, Debug, Serialize, Deserialize)]
pub struct Package {
#[builder(default = "cur_version()")]
version: i64,
#[builder(default = "crev_common::now()")]
#[serde(
serialize_with = "as_rfc3339_fixed",
deserialize_with = "from_rfc3339_fixed"
)]
pub date: chrono::DateTime<FixedOffset>,
pub from: crate::PubId,
#[serde(rename = "package")]
pub package: proof::PackageInfo,
#[builder(default = "Default::default()")]
review: super::Review,
#[serde(skip_serializing_if = "String::is_empty", default = "Default::default")]
#[builder(default = "Default::default()")]
comment: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PackageDraft {
#[serde(
skip_serializing,
default = "cur_version"
)]
version: i64,
#[serde(
serialize_with = "as_rfc3339_fixed",
deserialize_with = "from_rfc3339_fixed"
)]
date: chrono::DateTime<FixedOffset>,
pub from: crate::PubId,
#[serde(rename = "package")]
pub package: proof::PackageInfo,
review: super::Review,
#[serde(default = "Default::default")]
comment: String,
}
impl From<Package> for PackageDraft {
fn from(package: Package) -> Self {
PackageDraft {
version: package.version,
date: package.date,
from: package.from,
package: package.package,
review: package.review,
comment: package.comment,
}
}
}
impl From<PackageDraft> for Package {
fn from(package: PackageDraft) -> Self {
Package {
version: package.version,
date: package.date,
from: package.from,
package: package.package,
review: package.review,
comment: package.comment,
}
}
}
impl Package {
pub(crate) const BEGIN_BLOCK: &'static str = BEGIN_BLOCK;
pub(crate) const BEGIN_SIGNATURE: &'static str = BEGIN_SIGNATURE;
pub(crate) const END_BLOCK: &'static str = END_BLOCK;
}
impl proof::ContentCommon for Package {
fn date(&self) -> &chrono::DateTime<FixedOffset> {
&self.date
}
fn author(&self) -> &crate::PubId {
&self.from
}
}
impl super::Common for Package {
fn review(&self) -> &super::Review {
&self.review
}
}
impl Package {
pub fn parse(s: &str) -> Result<Self> {
Ok(serde_yaml::from_str(&s)?)
}
pub fn sign_by(self, id: &id::OwnId) -> Result<proof::Proof> {
proof::Content::from(self).sign_by(id)
}
}
impl PackageDraft {
pub fn parse(s: &str) -> Result<Self> {
Ok(serde_yaml::from_str(&s)?)
}
}
impl fmt::Display for Package {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
crev_common::serde::write_as_headerless_yaml(self, f)
}
}
impl fmt::Display for PackageDraft {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
crev_common::serde::write_as_headerless_yaml(self, f)
}
}