From 82ff782fe85c84c10f1f18c9bd5c2b017bc2f240 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 9 Apr 2022 09:40:59 +0300 Subject: feat! change how chunk labels are serialized Serialized labels now start with a type prefix: a character that says what type of label it is. This isn't strictly required: we _can_ just decide to always use a single type of checksum for all chunks in one backup, for one client, or in the whole repository. However, if it's ever possible to have more than one type, it helps debugging if every checksum, when serialized, is explicit about its type. Change things to use the new serialize method instead of the Display trait for Label. We're primarily serializing labels so they can be stored in a database, and used in URLs, only secondarily showing them to users. Sponsored-by: author --- src/index.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/index.rs') diff --git a/src/index.rs b/src/index.rs index 5310a44..52da2f2 100644 --- a/src/index.rs +++ b/src/index.rs @@ -93,7 +93,7 @@ mod test { let mut idx = new_index(dir.path()); idx.insert_meta(id.clone(), meta.clone()).unwrap(); assert_eq!(idx.get_meta(&id).unwrap(), meta); - let ids = idx.find_by_label(&format!("{}", sum)).unwrap(); + let ids = idx.find_by_label(&sum.serialize()).unwrap(); assert_eq!(ids, vec![id]); } @@ -117,7 +117,7 @@ mod test { let mut idx = new_index(dir.path()); idx.insert_meta(id.clone(), meta).unwrap(); idx.remove_meta(&id).unwrap(); - let ids: Vec = idx.find_by_label(&format!("{}", sum)).unwrap(); + let ids: Vec = idx.find_by_label(&sum.serialize()).unwrap(); assert_eq!(ids, vec![]); } } @@ -216,7 +216,7 @@ mod sql { fn row_to_meta(row: &Row) -> rusqlite::Result { let hash: String = row.get("label")?; - let sha256 = Label::sha256_from_str_unchecked(&hash); + let sha256 = Label::deserialize(&hash).expect("deserialize checksum from database"); Ok(ChunkMeta::new(&sha256)) } -- cgit v1.2.1