summaryrefslogtreecommitdiff
path: root/src/chunkid.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-01-04 18:57:49 +0200
committerLars Wirzenius <liw@liw.fi>2021-01-04 20:02:06 +0200
commit8efabc60f87e5462b01f4832d575f68382929624 (patch)
tree422b3941b6867871486df2198aef0e431c6b95ac /src/chunkid.rs
parent650b7cee5700eae9ab6c300fbdb816dead6f01f5 (diff)
downloadobnam2-8efabc60f87e5462b01f4832d575f68382929624.tar.gz
feat: verify checksum of chunks downloaded from server
Diffstat (limited to 'src/chunkid.rs')
-rw-r--r--src/chunkid.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/chunkid.rs b/src/chunkid.rs
index 9eec41f..3933d4b 100644
--- a/src/chunkid.rs
+++ b/src/chunkid.rs
@@ -37,6 +37,10 @@ impl ChunkId {
}
}
+ pub fn from_str(s: &str) -> Self {
+ ChunkId { id: s.to_string() }
+ }
+
pub fn as_bytes(&self) -> &[u8] {
self.id.as_bytes()
}
@@ -81,7 +85,7 @@ impl FromStr for ChunkId {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
- Ok(ChunkId { id: s.to_string() })
+ Ok(ChunkId::from_str(s))
}
}
@@ -113,6 +117,6 @@ mod test {
fn survives_round_trip() {
let id = ChunkId::new();
let id_str = id.to_string();
- assert_eq!(id, id_str.parse().unwrap());
+ assert_eq!(id, ChunkId::from_str(&id_str))
}
}