diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-04-19 04:53:35 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-04-19 04:53:35 +0000 |
commit | 8882409f31ddb4d77cb94dd6c57f27af1b3310d5 (patch) | |
tree | 62bb67504c47747f8ce202f4eb4121bb3d051223 /src/chunkmeta.rs | |
parent | 8da3f80d296dc1891159fe4fdc1787cecd9730d0 (diff) | |
parent | 18c0f4afab29e17c050208234becbfb5e2973746 (diff) | |
download | obnam2-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/chunkmeta.rs')
-rw-r--r-- | src/chunkmeta.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/chunkmeta.rs b/src/chunkmeta.rs index 33c1070..fe7ef4c 100644 --- a/src/chunkmeta.rs +++ b/src/chunkmeta.rs @@ -1,6 +1,6 @@ //! Metadata about a chunk. -use crate::checksummer::Checksum; +use crate::label::Label; use serde::{Deserialize, Serialize}; use std::default::Default; use std::str::FromStr; @@ -37,9 +37,9 @@ impl ChunkMeta { /// Create a new data chunk. /// /// Data chunks are not for generations. - pub fn new(checksum: &Checksum) -> Self { + pub fn new(label: &Label) -> Self { ChunkMeta { - label: checksum.to_string(), + label: label.serialize(), } } @@ -79,20 +79,20 @@ impl FromStr for ChunkMeta { #[cfg(test)] mod test { - use super::{Checksum, ChunkMeta}; + use super::{ChunkMeta, Label}; #[test] fn new_creates_data_chunk() { - let sum = Checksum::sha256_from_str_unchecked("abcdef"); + let sum = Label::sha256(b"abcdef"); let meta = ChunkMeta::new(&sum); - assert_eq!(meta.label(), "abcdef"); + assert_eq!(meta.label(), sum.serialize()); } #[test] fn new_generation_creates_generation_chunk() { - let sum = Checksum::sha256_from_str_unchecked("abcdef"); + let sum = Label::sha256(b"abcdef"); let meta = ChunkMeta::new(&sum); - assert_eq!(meta.label(), "abcdef"); + assert_eq!(meta.label(), sum.serialize()); } #[test] @@ -113,7 +113,7 @@ mod test { #[test] fn generation_json_roundtrip() { - let sum = Checksum::sha256_from_str_unchecked("abcdef"); + let sum = Label::sha256(b"abcdef"); let meta = ChunkMeta::new(&sum); let json = serde_json::to_string(&meta).unwrap(); let meta2 = serde_json::from_str(&json).unwrap(); @@ -122,7 +122,7 @@ mod test { #[test] fn data_json_roundtrip() { - let sum = Checksum::sha256_from_str_unchecked("abcdef"); + let sum = Label::sha256(b"abcdef"); let meta = ChunkMeta::new(&sum); let json = meta.to_json_vec(); let meta2 = serde_json::from_slice(&json).unwrap(); |