1 | // SPDX-FileCopyrightText: 2020-2021 HH Partners |
2 | // |
3 | // SPDX-License-Identifier: MIT |
4 | |
5 | use serde::{Deserialize, Serialize}; |
6 | |
7 | /// Representation of SPDX's |
8 | /// [Package Checksum](https://spdx.github.io/spdx-spec/3-package-information/#310-package-checksum) |
9 | /// and |
10 | /// [File Checksum](https://spdx.github.io/spdx-spec/4-file-information/#44-file-checksum). |
11 | /// According to the spec, SHA1 is mandatory but we don't currently enforce that. |
12 | #[derive (Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Clone)] |
13 | pub struct Checksum { |
14 | /// Algorithm used to calculate the checksum |
15 | pub algorithm: Algorithm, |
16 | |
17 | /// The checksum value. |
18 | #[serde(rename = "checksumValue" )] |
19 | pub value: String, |
20 | } |
21 | |
22 | impl Checksum { |
23 | /// Create new checksum. |
24 | pub fn new(algorithm: Algorithm, value: &str) -> Self { |
25 | Self { |
26 | algorithm, |
27 | value: value.to_lowercase(), |
28 | } |
29 | } |
30 | } |
31 | |
32 | /// Possible algorithms to be used for SPDX's |
33 | /// [package checksum](https://spdx.github.io/spdx-spec/3-package-information/#310-package-checksum) |
34 | /// and [file checksum](https://spdx.github.io/spdx-spec/4-file-information/#44-file-checksum). |
35 | #[derive (Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Clone, Copy)] |
36 | pub enum Algorithm { |
37 | SHA1, |
38 | SHA224, |
39 | SHA256, |
40 | SHA384, |
41 | SHA512, |
42 | MD2, |
43 | MD4, |
44 | MD5, |
45 | MD6, |
46 | #[serde(rename = "SHA3-256" )] |
47 | SHA3256, |
48 | #[serde(rename = "SHA3-384" )] |
49 | SHA3384, |
50 | #[serde(rename = "SHA3-512" )] |
51 | SHA3512, |
52 | #[serde(rename = "BLAKE2b-256" )] |
53 | BLAKE2B256, |
54 | #[serde(rename = "BLAKE2b-384" )] |
55 | BLAKE2B384, |
56 | #[serde(rename = "BLAKE2b-512" )] |
57 | BLAKE2B512, |
58 | BLAKE3, |
59 | ADLER32, |
60 | } |
61 | |