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
|
use getset::Getters;
use serde::Deserialize;
use serde::Serialize;
use url::Url;
#[derive(Clone, Debug, Serialize, Deserialize, Getters)]
pub struct Source {
#[getset(get = "pub")]
url: Url,
#[getset(get = "pub")]
hash: SourceHash,
}
impl Source {
#[cfg(test)]
pub fn new(url: Url, hash: SourceHash) -> Self {
Source { url, hash }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Getters)]
pub struct SourceHash {
#[serde(rename = "type")]
#[getset(get = "pub")]
hashtype: HashType,
#[serde(rename = "hash")]
#[getset(get = "pub")]
value: HashValue,
}
impl SourceHash {
#[cfg(test)]
pub fn new(hashtype: HashType, value: HashValue) -> Self {
SourceHash { hashtype, value }
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum HashType {
#[serde(rename = "sha1")]
Sha1,
#[serde(rename = "sha256")]
Sha256,
#[serde(rename = "sha512")]
Sha512,
}
impl std::fmt::Display for HashType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
HashType::Sha1 => write!(f, "sha1"),
HashType::Sha256 => write!(f, "sha256"),
HashType::Sha512 => write!(f, "sha512"),
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
#[serde(transparent)]
pub struct HashValue(String);
#[cfg(test)]
impl From<String> for HashValue {
fn from(s: String) -> Self {
HashValue(s)
}
}
impl std::fmt::Display for HashValue {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
self.0.fmt(f)
}
}
|