summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/checksummer.rs16
-rw-r--r--src/chunk.rs2
-rw-r--r--src/client.rs4
3 files changed, 16 insertions, 6 deletions
diff --git a/src/checksummer.rs b/src/checksummer.rs
index 50bce04..6d7303b 100644
--- a/src/checksummer.rs
+++ b/src/checksummer.rs
@@ -11,11 +11,19 @@ use std::fmt;
/// A checksum of some data.
#[derive(Debug, Clone)]
pub enum Checksum {
+ /// An arbitrary, literal string.
+ Literal(String),
+
/// A SHA256 checksum.
Sha256(String),
}
impl Checksum {
+ /// Construct a literal string.
+ pub fn literal(s: &str) -> Self {
+ Self::Literal(s.to_string())
+ }
+
/// Compute a SHA256 checksum for a block of data.
pub fn sha256(data: &[u8]) -> Self {
let mut hasher = Sha256::new();
@@ -33,9 +41,9 @@ impl Checksum {
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)
+ match self {
+ Self::Literal(s) => write!(f, "{}", s),
+ Self::Sha256(hash) => write!(f, "{}", hash),
+ }
}
}
diff --git a/src/chunk.rs b/src/chunk.rs
index 27a3ab9..df16a98 100644
--- a/src/chunk.rs
+++ b/src/chunk.rs
@@ -185,7 +185,7 @@ impl ClientTrust {
pub fn to_data_chunk(&self) -> Result<DataChunk, ClientTrustError> {
let json: String = serde_json::to_string(self).map_err(ClientTrustError::JsonGenerate)?;
let bytes = json.as_bytes().to_vec();
- let checksum = Checksum::sha256_from_str_unchecked("client-trust");
+ let checksum = Checksum::literal("client-trust");
let meta = ChunkMeta::new(&checksum);
Ok(DataChunk::new(bytes, meta))
}
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<Vec<ChunkId>, 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),
};