feat: SSE-KMS use uuid instead of read all data to md5. (#17958)

This commit is contained in:
jiuker
2023-09-19 01:00:54 +08:00
committed by GitHub
parent a00db4267c
commit 9947c01c8e
23 changed files with 133 additions and 56 deletions
+46 -1
View File
@@ -18,6 +18,7 @@
package etag
import (
"context"
"crypto/md5"
"fmt"
"hash"
@@ -102,12 +103,19 @@ type Reader struct {
// If the provided etag is not nil the returned
// Reader compares the etag with the computed
// MD5 sum once the r returns io.EOF.
func NewReader(r io.Reader, etag ETag) *Reader {
func NewReader(ctx context.Context, r io.Reader, etag ETag, forceMD5 []byte) *Reader {
if er, ok := r.(*Reader); ok {
if er.readN == 0 && Equal(etag, er.checksum) {
return er
}
}
if len(forceMD5) != 0 {
return &Reader{
src: r,
md5: NewUUIDHash(forceMD5),
checksum: etag,
}
}
return &Reader{
src: r,
md5: md5.New(),
@@ -153,3 +161,40 @@ type VerifyError struct {
func (v VerifyError) Error() string {
return fmt.Sprintf("etag: expected ETag %q does not match computed ETag %q", v.Expected, v.Computed)
}
// UUIDHash - use uuid to make md5sum
type UUIDHash struct {
uuid []byte
}
// Write - implement hash.Hash Write
func (u UUIDHash) Write(p []byte) (n int, err error) {
return len(p), nil
}
// Sum - implement md5.Sum
func (u UUIDHash) Sum(b []byte) []byte {
return u.uuid
}
// Reset - implement hash.Hash Reset
func (u UUIDHash) Reset() {
return
}
// Size - implement hash.Hash Size
func (u UUIDHash) Size() int {
return len(u.uuid)
}
// BlockSize - implement hash.Hash BlockSize
func (u UUIDHash) BlockSize() int {
return md5.BlockSize
}
var _ hash.Hash = &UUIDHash{}
// NewUUIDHash - new UUIDHash
func NewUUIDHash(uuid []byte) *UUIDHash {
return &UUIDHash{uuid: uuid}
}