From 9f6ff22ff9a1b0a5a28d037846b1cecee4f2945c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 9 Apr 2022 08:15:03 +0300 Subject: refactor: add a Literal variant to Checksum We've had fake checksums that are just arbitrary literal strings, and this change makes this more explicit. It's a preliminary change for later support for additional checksum algorithms. Sponsored-by: author --- src/client.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/client.rs') diff --git a/src/client.rs b/src/client.rs index c5d66c1..563921d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,6 @@ //! Client to the Obnam server HTTP API. +use crate::checksummer::Checksum; use crate::chunk::{ ClientTrust, ClientTrustError, DataChunk, GenerationChunk, GenerationChunkError, }; @@ -195,7 +196,8 @@ impl BackupClient { } async fn find_client_trusts(&self) -> Result, ClientError> { - let body = match self.get("", &[("label", "client-trust")]).await { + let label = format!("{}", Checksum::literal("client-trust")); + let body = match self.get("", &[("label", &label)]).await { Ok((_, body)) => body, Err(err) => return Err(err), }; -- cgit v1.2.1 From d9b72ffa5485f3c253da22f09ff0a7090de7aa37 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 9 Apr 2022 11:27:14 +0300 Subject: refactor: rename Checksum to Label Label is a clearer and more accurate name for the type now that it is not just a checksum. Also, serialize a Label in tests, rather than using string literals. This is more correct, and we'll be changing serialization later. Sponsored-by: author --- src/client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/client.rs') diff --git a/src/client.rs b/src/client.rs index 563921d..d8bf262 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,5 @@ //! Client to the Obnam server HTTP API. -use crate::checksummer::Checksum; use crate::chunk::{ ClientTrust, ClientTrustError, DataChunk, GenerationChunk, GenerationChunkError, }; @@ -10,6 +9,7 @@ use crate::cipher::{CipherEngine, CipherError}; use crate::config::{ClientConfig, ClientConfigError}; use crate::generation::{FinishedGeneration, GenId, LocalGeneration, LocalGenerationError}; use crate::genlist::GenerationList; +use crate::label::Label; use log::{debug, error, info}; use reqwest::header::HeaderMap; @@ -196,7 +196,7 @@ impl BackupClient { } async fn find_client_trusts(&self) -> Result, ClientError> { - let label = format!("{}", Checksum::literal("client-trust")); + let label = format!("{}", Label::literal("client-trust")); let body = match self.get("", &[("label", &label)]).await { Ok((_, body)) => body, Err(err) => return Err(err), -- cgit v1.2.1 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/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client.rs') diff --git a/src/client.rs b/src/client.rs index d8bf262..bed5f1e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -196,7 +196,7 @@ impl BackupClient { } async fn find_client_trusts(&self) -> Result, ClientError> { - let label = format!("{}", Label::literal("client-trust")); + let label = Label::literal("client-trust").serialize(); let body = match self.get("", &[("label", &label)]).await { Ok((_, body)) => body, Err(err) => return Err(err), -- cgit v1.2.1