feat: SSE-KMS use uuid instead of read all data to md5. (#17958)
This commit is contained in:
@@ -119,6 +119,7 @@ import (
|
||||
|
||||
"github.com/minio/minio/internal/fips"
|
||||
"github.com/minio/minio/internal/hash/sha256"
|
||||
xhttp "github.com/minio/minio/internal/http"
|
||||
"github.com/minio/sio"
|
||||
)
|
||||
|
||||
@@ -263,6 +264,12 @@ func FromContentMD5(h http.Header) (ETag, error) {
|
||||
return ETag(b), nil
|
||||
}
|
||||
|
||||
// ContentMD5Requested - for http.request.header is not request Content-Md5
|
||||
func ContentMD5Requested(h http.Header) bool {
|
||||
_, ok := h[xhttp.ContentMD5]
|
||||
return ok
|
||||
}
|
||||
|
||||
// Multipart computes an S3 multipart ETag given a list of
|
||||
// S3 singlepart ETags. It returns nil if the list of
|
||||
// ETags is empty.
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package etag
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -137,7 +138,7 @@ var readerTests = []struct { // Reference values computed by: echo <content> | m
|
||||
|
||||
func TestReader(t *testing.T) {
|
||||
for i, test := range readerTests {
|
||||
reader := NewReader(strings.NewReader(test.Content), test.ETag)
|
||||
reader := NewReader(context.Background(), strings.NewReader(test.Content), test.ETag, nil)
|
||||
if _, err := io.Copy(io.Discard, reader); err != nil {
|
||||
t.Fatalf("Test %d: read failed: %v", i, err)
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user