diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-31 09:00:21 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-31 12:10:10 +0200 |
commit | acf1ba3f8f1492b961c9a6eb09eb93e882f5eb3f (patch) | |
tree | 1ce0288f878cac71990bb01f358d6035f1626c92 /src/checksummer.rs | |
parent | 686e87981db210fa443404c8473dfe7a3f39b241 (diff) | |
download | obnam2-acf1ba3f8f1492b961c9a6eb09eb93e882f5eb3f.tar.gz |
docs: add documentation comments to crate
Also, make it an error for a public symbol to not be documented.
Sponsored-by: author
Diffstat (limited to 'src/checksummer.rs')
-rw-r--r-- | src/checksummer.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/checksummer.rs b/src/checksummer.rs index 18b8afb..50bce04 100644 --- a/src/checksummer.rs +++ b/src/checksummer.rs @@ -1,13 +1,22 @@ +//! 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); @@ -15,12 +24,14 @@ impl Checksum { 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, |