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
|
// SPDX-FileCopyrightText: 2020-2021 HH Partners
//
// SPDX-License-Identifier: MIT
use serde::{Deserialize, Serialize};
/// Representation of SPDX's
/// [Package Checksum](https://spdx.github.io/spdx-spec/3-package-information/#310-package-checksum)
/// and
/// [File Checksum](https://spdx.github.io/spdx-spec/4-file-information/#44-file-checksum).
/// According to the spec, SHA1 is mandatory but we don't currently enforce that.
#[derive(Debug, Serialize, Deserialize, PartialEq, PartialOrd, Clone)]
pub struct Checksum {
/// Algorithm used to calculate the checksum
pub algorithm: Algorithm,
/// The checksum value.
#[serde(rename = "checksumValue")]
pub value: String,
}
impl Checksum {
/// Create new checksum.
pub fn new(algorithm: Algorithm, value: &str) -> Self {
Self {
algorithm,
value: value.to_lowercase(),
}
}
}
/// Possible algorithms to be used for SPDX's
/// [package checksum](https://spdx.github.io/spdx-spec/3-package-information/#310-package-checksum)
/// and [file checksum](https://spdx.github.io/spdx-spec/4-file-information/#44-file-checksum).
#[derive(Debug, Serialize, Deserialize, PartialEq, PartialOrd, Clone, Copy)]
pub enum Algorithm {
SHA1,
SHA224,
SHA256,
SHA384,
SHA512,
MD2,
MD4,
MD5,
MD6,
}
|