diff options
Diffstat (limited to 'vendor/spdx-rs/src/models/checksum.rs')
-rw-r--r-- | vendor/spdx-rs/src/models/checksum.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/spdx-rs/src/models/checksum.rs b/vendor/spdx-rs/src/models/checksum.rs new file mode 100644 index 000000000..bd91f4c7a --- /dev/null +++ b/vendor/spdx-rs/src/models/checksum.rs @@ -0,0 +1,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, +} |