1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Define types to compute and compare Cloud Storage object checksums.
//!
//! The [ChecksumEngine] trait is sealed, and cannot be used to create new
//! implementations. However, it may be useful when working with
//! [UploadObject][crate::builder::storage::UploadObject].
//!
//! # Example
//! ```
//! use google_cloud_storage::builder::storage::UploadObject;
//! use google_cloud_storage::model::Object;
//! use google_cloud_storage::{upload_source::StreamingSource, checksum::ChecksumEngine};
//!
//! async fn example<S, C>(builder: UploadObject<S, C>) -> anyhow::Result<Object>
//! where
//! S: StreamingSource + Send + Sync + 'static,
//! C: ChecksumEngine + Send + Sync + 'static
//! {
//! // Finish configuring `builder` and complete the upload
//! let object = builder
//! .with_if_generation_match(0)
//! .with_resumable_upload_threshold(0_usize)
//! .send_buffered()
//! .await?;
//! Ok(object)
//! }
//! ```
use crateChecksumMismatch;
use crateObjectChecksums;
/// Computes a checksum or hash for [Cloud Storage] transfers.
///
/// We want to minimize code complexity in our implementation of data integrity
/// checks for uploads and downloads. This trait defines a composable interface
/// to support:
/// - No checksums (`Null`): the client library does not compute any checksums,
/// and therefore does not validate checksums either.
/// - Precomputed checksums (`Precomputed`): the client library assumes the
/// application provided checksums in the object metadata.
/// - Only crc32c (`Crc32c` or `Crc32c<Null>`)`: compute (and validate) only
/// crc32c checksums.
/// - Only MD5 (`Md5` or `Md5<Null>`): compute (and validate) only MD5 hashes.
/// - Both: (`Crc32c<Md5>` or `Md5<Crc32>`): compute (and validate) both crc32
/// checksums and MD5 hashes.
///
/// The application should have no need to interact with these types directly,
/// or even name them. They are used only as implementation details. They may
/// be visible in debug messages.
pub