qubit_fs/metadata/checksum.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Content checksum metadata.
9
10use crate::metadata::ChecksumAlgorithm;
11
12/// Content checksum.
13///
14/// # Examples
15///
16/// ```rust
17/// use qubit_fs::metadata::{Checksum, ChecksumAlgorithm};
18///
19/// let checksum = Checksum::new(ChecksumAlgorithm::Sha256, "deadbeef");
20/// assert_eq!(ChecksumAlgorithm::Sha256, checksum.algorithm);
21/// ```
22#[derive(Clone, Debug, Eq, PartialEq)]
23pub struct Checksum {
24 /// Algorithm used to compute the checksum.
25 pub algorithm: ChecksumAlgorithm,
26 /// Encoded checksum value.
27 pub value: String,
28}
29
30impl Checksum {
31 /// Creates a checksum.
32 ///
33 /// # Parameters
34 /// - `algorithm`: Checksum algorithm.
35 /// - `value`: Encoded checksum value.
36 ///
37 /// # Returns
38 /// New checksum.
39 #[inline]
40 #[must_use]
41 pub fn new(algorithm: ChecksumAlgorithm, value: &str) -> Self {
42 Self {
43 algorithm,
44 value: value.to_owned(),
45 }
46 }
47}