|
15 | 15 | use crate::model::ObjectChecksums; |
16 | 16 | use crate::storage::ChecksumMismatch; |
17 | 17 |
|
| 18 | +pub fn update(known: &mut ObjectChecksums, computed: ObjectChecksums) { |
| 19 | + known.crc32c = known.crc32c.or(computed.crc32c); |
| 20 | + if known.md5_hash.is_empty() { |
| 21 | + known.md5_hash = computed.md5_hash; |
| 22 | + } |
| 23 | +} |
| 24 | + |
18 | 25 | /// Compare the received object checksums vs. the computed checksums. |
19 | 26 | /// |
20 | 27 | /// If the `crc32c` field is `None`, or the `md5_mash` field is empty, they do |
@@ -84,13 +91,40 @@ impl ChecksumEngine for Null { |
84 | 91 | } |
85 | 92 | } |
86 | 93 |
|
87 | | -/// Assumes the checksums are provided as part of the object metadata. |
| 94 | +/// Assumes the CRC32C checksum is known and included in the object metadata. |
| 95 | +#[derive(Clone, Debug)] |
| 96 | +pub struct KnownCrc32c; |
| 97 | + |
| 98 | +impl sealed::ChecksumEngine for KnownCrc32c {} |
| 99 | + |
| 100 | +impl ChecksumEngine for KnownCrc32c { |
| 101 | + fn update(&mut self, _offset: u64, _data: &bytes::Bytes) {} |
| 102 | + fn finalize(&self) -> ObjectChecksums { |
| 103 | + ObjectChecksums::new() |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +/// Assumes the MD5 hash is known and included in the object metadata. |
| 108 | +#[derive(Clone, Debug)] |
| 109 | +pub struct KnownMd5; |
| 110 | + |
| 111 | +impl sealed::ChecksumEngine for KnownMd5 {} |
| 112 | + |
| 113 | +impl ChecksumEngine for KnownMd5 { |
| 114 | + fn update(&mut self, _offset: u64, _data: &bytes::Bytes) {} |
| 115 | + fn finalize(&self) -> ObjectChecksums { |
| 116 | + ObjectChecksums::new() |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +/// Assumes both the CRC32C checksum, and the MD5 checksums are known and |
| 121 | +/// included in the object metadata. |
88 | 122 | #[derive(Clone, Debug)] |
89 | | -pub struct Precomputed; |
| 123 | +pub struct Known; |
90 | 124 |
|
91 | | -impl sealed::ChecksumEngine for Precomputed {} |
| 125 | +impl sealed::ChecksumEngine for Known {} |
92 | 126 |
|
93 | | -impl ChecksumEngine for Precomputed { |
| 127 | +impl ChecksumEngine for Known { |
94 | 128 | fn update(&mut self, _offset: u64, _data: &bytes::Bytes) {} |
95 | 129 | fn finalize(&self) -> ObjectChecksums { |
96 | 130 | ObjectChecksums::new() |
@@ -359,7 +393,7 @@ mod tests { |
359 | 393 |
|
360 | 394 | #[test] |
361 | 395 | fn precomputed() { |
362 | | - let mut engine = Precomputed; |
| 396 | + let mut engine = Known; |
363 | 397 | engine.update(0, &data()); |
364 | 398 | assert_eq!(engine.finalize(), ObjectChecksums::new()); |
365 | 399 | } |
|
0 commit comments