Skip to content

Commit

Permalink
Lint & docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Jul 29, 2022
1 parent 1bcc3e5 commit 04ce065
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions cmd/object-api-datatypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ type CompleteMultipartUpload struct {
Parts []CompletePart `xml:"Part"`
}

// NewMultipartUploadResult contains information about a newly created multipart upload.
type NewMultipartUploadResult struct {
UploadID string
ChecksumAlgo string
Expand Down
22 changes: 11 additions & 11 deletions cmd/object-handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
fault Fault
// expected output.
expectedRespStatus int // expected response status body.
wantApiCode string
wantAPICode string
wantHeaders map[string]string
}{
// Fetching the entire object and validating its contents.
Expand All @@ -1353,7 +1353,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
secretKey: credentials.SecretKey,

expectedRespStatus: http.StatusForbidden,
wantApiCode: "InvalidAccessKeyId",
wantAPICode: "InvalidAccessKeyId",
},
// Test Case with invalid header key X-Amz-Copy-Source.
2: {
Expand All @@ -1365,7 +1365,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
accessKey: credentials.AccessKey,
secretKey: credentials.SecretKey,
expectedRespStatus: http.StatusBadRequest,
wantApiCode: "InvalidArgument",
wantAPICode: "InvalidArgument",
},
// Test Case with invalid Content-Md5 value
3: {
Expand All @@ -1377,7 +1377,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
accessKey: credentials.AccessKey,
secretKey: credentials.SecretKey,
expectedRespStatus: http.StatusBadRequest,
wantApiCode: "InvalidDigest",
wantAPICode: "InvalidDigest",
},
// Test Case with object greater than maximum allowed size.
4: {
Expand All @@ -1389,7 +1389,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
secretKey: credentials.SecretKey,
fault: TooBigObject,
expectedRespStatus: http.StatusBadRequest,
wantApiCode: "EntityTooLarge",
wantAPICode: "EntityTooLarge",
},
// Test Case with missing content length
5: {
Expand All @@ -1401,7 +1401,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
secretKey: credentials.SecretKey,
fault: MissingContentLength,
expectedRespStatus: http.StatusLengthRequired,
wantApiCode: "MissingContentLength",
wantAPICode: "MissingContentLength",
},
// Test Case with invalid header key X-Amz-Storage-Class
6: {
Expand All @@ -1413,7 +1413,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
accessKey: credentials.AccessKey,
secretKey: credentials.SecretKey,
expectedRespStatus: http.StatusBadRequest,
wantApiCode: "InvalidStorageClass",
wantAPICode: "InvalidStorageClass",
},

// Invalid crc32
Expand All @@ -1426,7 +1426,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
accessKey: credentials.AccessKey,
secretKey: credentials.SecretKey,
expectedRespStatus: http.StatusBadRequest,
wantApiCode: "InvalidArgument",
wantAPICode: "InvalidArgument",
},
// Wrong crc32
8: {
Expand All @@ -1438,7 +1438,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
accessKey: credentials.AccessKey,
secretKey: credentials.SecretKey,
expectedRespStatus: http.StatusBadRequest,
wantApiCode: "XAmzContentChecksumMismatch",
wantAPICode: "XAmzContentChecksumMismatch",
},
// Correct crc32
9: {
Expand Down Expand Up @@ -1474,7 +1474,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
accessKey: credentials.AccessKey,
secretKey: credentials.SecretKey,
expectedRespStatus: http.StatusBadRequest,
wantApiCode: "XAmzContentChecksumMismatch",
wantAPICode: "XAmzContentChecksumMismatch",
},
// SHA1
12: {
Expand Down Expand Up @@ -1542,7 +1542,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
t.Fatal(err)
}
gotErr := apiErr.Code
wantErr := testCase.wantApiCode
wantErr := testCase.wantAPICode
if gotErr != wantErr {
t.Errorf("test %d: want api error %q, got %q", i, wantErr, gotErr)
}
Expand Down
10 changes: 6 additions & 4 deletions internal/hash/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (c ChecksumType) Key() string {
return ""
}

// RawByteLen returns the size of the un-encoded checksum.
func (c ChecksumType) RawByteLen() int {
switch {
case c.Is(ChecksumCRC32):
Expand Down Expand Up @@ -146,6 +147,11 @@ func (c ChecksumType) Hasher() hash.Hash {
return nil
}

// Trailing return whether the checksum is traling.
func (c ChecksumType) Trailing() bool {
return c.Is(ChecksumTrailing)
}

// NewChecksumFromData returns a new checksum from specified algorithm and base64 encoded value.
func NewChecksumFromData(t ChecksumType, data []byte) *Checksum {
if !t.IsSet() {
Expand Down Expand Up @@ -197,10 +203,6 @@ func NewChecksumString(alg, value string) *Checksum {
return &c
}

func (c Checksum) Trailing() bool {
return c.Type.Is(ChecksumTrailing)
}

// AppendTo will append the checksum to b.
func (c Checksum) AppendTo(b []byte) []byte {
var tmp [binary.MaxVarintLen32]byte
Expand Down
2 changes: 1 addition & 1 deletion internal/hash/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (r *Reader) AddChecksum(req *http.Request) error {
return nil
}
r.contentHash = *cs
if cs.Trailing() {
if cs.Type.Trailing() {
// Ignore until we have trailing headers.
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/hash/sha256/sh256_fips.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func New() hash.Hash { return fipssha256.New() }
// Sum256 returns the SHA256 checksum of the data.
func Sum256(data []byte) [fipssha256.Size]byte { return fipssha256.Sum256(data) }

// The size of a SHA256 checksum in bytes.
// Size is the size of a SHA256 checksum in bytes.
const Size = fipssha256.Size
2 changes: 1 addition & 1 deletion internal/hash/sha256/sh256_nofips.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func New() hash.Hash { return nofipssha256.New() }
// Sum256 returns the SHA256 checksum of the data.
func Sum256(data []byte) [nofipssha256.Size]byte { return nofipssha256.Sum256(data) }

// The size of a SHA256 checksum in bytes.
// Size is the size of a SHA256 checksum in bytes.
const Size = nofipssha256.Size

0 comments on commit 04ce065

Please sign in to comment.