diff options
author | Alex Auvolat <lx@deuxfleurs.fr> | 2025-02-18 21:55:48 +0100 |
---|---|---|
committer | Alex Auvolat <lx@deuxfleurs.fr> | 2025-02-18 21:56:32 +0100 |
commit | cfe8e8d45cf54a28911525d1cc7bb01c8ecb6bea (patch) | |
tree | 77129779363a4171ebf02fabf6992f45eef7651b | |
parent | f6e805e7db7b35e9fc6baaad6ec953e30a443437 (diff) | |
download | garage-cfe8e8d45cf54a28911525d1cc7bb01c8ecb6bea.tar.gz garage-cfe8e8d45cf54a28911525d1cc7bb01c8ecb6bea.zip |
api: PutObject: save trailer checksum in metadata
-rw-r--r-- | src/api/s3/put.rs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/api/s3/put.rs b/src/api/s3/put.rs index 496d80f3..4d866a06 100644 --- a/src/api/s3/put.rs +++ b/src/api/s3/put.rs @@ -49,7 +49,10 @@ pub(crate) struct SaveStreamResult { pub(crate) enum ChecksumMode<'a> { Verify(&'a ExpectedChecksums), - VerifyFrom(StreamingChecksumReceiver), + VerifyFrom { + checksummer: StreamingChecksumReceiver, + trailer_algo: Option<ChecksumAlgorithm>, + }, Calculate(Option<ChecksumAlgorithm>), } @@ -70,6 +73,7 @@ pub async fn handle_put( sha256: None, extra: request_checksum_value(req.headers())?, }; + let trailer_checksum_algorithm = request_trailer_checksum_algorithm(req.headers())?; let meta = ObjectVersionMetaInner { headers, @@ -90,7 +94,7 @@ pub async fn handle_put( req_body.add_md5(); } - let (stream, checksums) = req_body.streaming_with_checksums(); + let (stream, checksummer) = req_body.streaming_with_checksums(); let stream = stream.map_err(Error::from); let res = save_stream( @@ -99,7 +103,10 @@ pub async fn handle_put( encryption, stream, key, - ChecksumMode::VerifyFrom(checksums), + ChecksumMode::VerifyFrom { + checksummer, + trailer_algo: trailer_checksum_algorithm, + }, ) .await?; @@ -140,7 +147,7 @@ pub(crate) async fn save_stream<S: Stream<Item = Result<Bytes, Error>> + Unpin>( ChecksumMode::Calculate(algo) => { Checksummer::init(&Default::default(), !encryption.is_encrypted()).add(*algo) } - ChecksumMode::VerifyFrom(_) => { + ChecksumMode::VerifyFrom { .. } => { // Checksums are calculated by the garage_api_common::signature module // so here we can just have an empty checksummer that does nothing Checksummer::new() @@ -160,11 +167,17 @@ pub(crate) async fn save_stream<S: Stream<Item = Result<Bytes, Error>> + Unpin>( ChecksumMode::Calculate(algo) => { meta.checksum = checksums.extract(algo); } - ChecksumMode::VerifyFrom(checksummer) => { + ChecksumMode::VerifyFrom { + checksummer, + trailer_algo, + } => { drop(chunker); checksums = checksummer .await .ok_or_internal_error("checksum calculation")??; + if let Some(algo) = trailer_algo { + meta.checksum = checksums.extract(Some(algo)); + } } }; @@ -256,10 +269,16 @@ pub(crate) async fn save_stream<S: Stream<Item = Result<Bytes, Error>> + Unpin>( ChecksumMode::Calculate(algo) => { meta.checksum = checksums.extract(algo); } - ChecksumMode::VerifyFrom(checksummer) => { + ChecksumMode::VerifyFrom { + checksummer, + trailer_algo, + } => { checksums = checksummer .await .ok_or_internal_error("checksum calculation")??; + if let Some(algo) = trailer_algo { + meta.checksum = checksums.extract(Some(algo)); + } } }; |