summaryrefslogtreecommitdiff
path: root/src/checksummer.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-04-19 04:53:35 +0000
committerLars Wirzenius <liw@liw.fi>2022-04-19 04:53:35 +0000
commit8882409f31ddb4d77cb94dd6c57f27af1b3310d5 (patch)
tree62bb67504c47747f8ce202f4eb4121bb3d051223 /src/checksummer.rs
parent8da3f80d296dc1891159fe4fdc1787cecd9730d0 (diff)
parent18c0f4afab29e17c050208234becbfb5e2973746 (diff)
downloadobnam2-8882409f31ddb4d77cb94dd6c57f27af1b3310d5.tar.gz
Merge branch 'liw/checksum-types-try2' into 'main'
add support for migrating to new checksum types Closes #203 See merge request obnam/obnam!228
Diffstat (limited to 'src/checksummer.rs')
-rw-r--r--src/checksummer.rs41
1 files changed, 0 insertions, 41 deletions
diff --git a/src/checksummer.rs b/src/checksummer.rs
deleted file mode 100644
index 50bce04..0000000
--- a/src/checksummer.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-//! Compute checksums of data.
-//!
-//! De-duplication of backed up data in Obnam relies on cryptographic
-//! checksums. They are implemented in this module. Note that Obnam
-//! does not aim to make these algorithms configurable, so only a very
-//! small number of carefully chosen algorithms are supported here.
-
-use sha2::{Digest, Sha256};
-use std::fmt;
-
-/// A checksum of some data.
-#[derive(Debug, Clone)]
-pub enum Checksum {
- /// A SHA256 checksum.
- Sha256(String),
-}
-
-impl Checksum {
- /// Compute a SHA256 checksum for a block of data.
- pub fn sha256(data: &[u8]) -> Self {
- let mut hasher = Sha256::new();
- hasher.update(data);
- let hash = hasher.finalize();
- Self::Sha256(format!("{:x}", hash))
- }
-
- /// Create a `Checksum` from a known, previously computed hash.
- pub fn sha256_from_str_unchecked(hash: &str) -> Self {
- Self::Sha256(hash.to_string())
- }
-}
-
-impl fmt::Display for Checksum {
- /// Format a checksum for display.
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let hash = match self {
- Self::Sha256(hash) => hash,
- };
- write!(f, "{}", hash)
- }
-}