mirror of
https://github.com/pgsty/minio.git
synced 2026-07-22 13:40:22 +03:00
feat: SSE-KMS use uuid instead of read all data to md5. (#17958)
This commit is contained in:
+46
-1
@@ -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