Package: checksum

import "../ibm-cos-sdk-go-v2/service/internal/checksum"

Constants

const AlgorithmCRC32C Algorithm = readonly

AlgorithmCRC32C represents CRC32C hash algorithm

Value:

"CRC32C"
const AlgorithmCRC32 Algorithm = readonly

AlgorithmCRC32 represents CRC32 hash algorithm

Value:

"CRC32"
const AlgorithmSHA1 Algorithm = readonly

AlgorithmSHA1 represents SHA1 hash algorithm

Value:

"SHA1"
const AlgorithmSHA256 Algorithm = readonly

AlgorithmSHA256 represents SHA256 hash algorithm

Value:

"SHA256"
const AlgorithmCRC64NVME Algorithm = readonly

AlgorithmCRC64NVME represents CRC64NVME hash algorithm

Value:

"CRC64NVME"

Type Summary collapse

Function Summary collapse

Type Details

Algorithm struct

Structure Fields:

(empty struct)

InputMiddlewareOptions struct

InputMiddlewareOptions provides the options for the request checksum middleware setup.

Structure Fields:

RequireChecksum bool

RequireChecksum indicates whether operation model forces middleware to compute the input payload’s checksum. If RequireChecksum is set to true, checksum will be calculated and RequestChecksumCalculation will be ignored, otherwise RequestChecksumCalculation will be used to indicate if checksum will be calculated

RequestChecksumCalculation aws.RequestChecksumCalculation

RequestChecksumCalculation is the user config to opt-in/out request checksum calculation. If RequireChecksum is set to true, checksum will be calculated and this field will be ignored, otherwise RequestChecksumCalculation will be used to indicate if checksum will be calculated

EnableTrailingChecksum bool

Enables support for wrapping the serialized input payload with a content-encoding: aws-check wrapper, and including a trailer for the algorithm’s checksum value.

The checksum will not be computed, nor added as trailing checksum, if the Algorithm’s header is already set on the request.

EnableComputeSHA256PayloadHash bool

Enables support for computing the SHA256 checksum of input payloads along with the algorithm specified checksum. Prevents downstream middleware handlers (computePayloadSHA256) re-reading the payload.

The SHA256 payload checksum will only be used for computed for requests that are not TLS, or do not enable trailing checksums.

The SHA256 payload hash will not be computed, if the Algorithm’s header is already set on the request.

EnableDecodedContentLengthHeader bool

Enables support for setting the aws-chunked decoded content length header for the decoded length of the underlying stream. Will only be set when used with trailing checksums, and aws-chunked content-encoding.

OutputMiddlewareOptions struct

OutputMiddlewareOptions provides options for configuring output checksum validation middleware.

Structure Fields:

ResponseChecksumValidation aws.ResponseChecksumValidation

ResponseChecksumValidation is the user config to opt-in/out response checksum validation

ValidationAlgorithms []string

The set of checksum algorithms that should be used for response payload checksum validation. The algorithm(s) used will be a union of the output’s returned algorithms and this set.

Only the first algorithm in the union is currently used.

IgnoreMultipartValidation bool

If set the middleware will ignore output multipart checksums. Otherwise a checksum format error will be returned by the middleware.

LogValidationSkipped bool

When set the middleware will log when output does not have checksum or algorithm to validate.

LogMultipartValidationSkipped bool

When set the middleware will log when the output contains a multipart checksum that was, skipped and not validated.

Function Details

func AddInputMiddleware(stack *middleware.Stack, options InputMiddlewareOptions) (err error)

AddInputMiddleware adds the middleware for performing checksum computing of request payloads, and checksum validation of response payloads.

Deprecated: This internal-only runtime API is frozen. Do not call or modify it in new code. Checksum-enabled service operations now generate this middleware setup code inline per #2507.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// File 'service/internal/checksum/middleware_add.go', line 58

func AddInputMiddleware(stack *middleware.Stack, options InputMiddlewareOptions) (err error) { // Initial checksum configuration look up middleware err = stack.Initialize.Add(&SetupInputContext{ GetAlgorithm: options.GetAlgorithm, RequireChecksum: options.RequireChecksum, RequestChecksumCalculation: options.RequestChecksumCalculation, }, middleware.Before) if err != nil { return err } stack.Build.Remove("ContentChecksum") inputChecksum := &ComputeInputPayloadChecksum{ EnableTrailingChecksum: options.EnableTrailingChecksum, EnableComputePayloadHash: options.EnableComputeSHA256PayloadHash, EnableDecodedContentLengthHeader: options.EnableDecodedContentLengthHeader, } if err := stack.Finalize.Insert(inputChecksum, "ResolveEndpointV2", middleware.After); err != nil { return err } // If trailing checksum is not supported no need for finalize handler to be added. if options.EnableTrailingChecksum { trailerMiddleware := &AddInputChecksumTrailer{ EnableTrailingChecksum: inputChecksum.EnableTrailingChecksum, EnableComputePayloadHash: inputChecksum.EnableComputePayloadHash, EnableDecodedContentLengthHeader: inputChecksum.EnableDecodedContentLengthHeader, } if err := stack.Finalize.Insert(trailerMiddleware, "Retry", middleware.After); err != nil { return err } } return nil }

func AddOutputMiddleware(stack *middleware.Stack, options OutputMiddlewareOptions) error

AddOutputMiddleware adds the middleware for validating response payload’s checksum.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// File 'service/internal/checksum/middleware_add.go', line 143

func AddOutputMiddleware(stack *middleware.Stack, options OutputMiddlewareOptions) error { err := stack.Initialize.Add(&setupOutputContext{ GetValidationMode: options.GetValidationMode, SetValidationMode: options.SetValidationMode, ResponseChecksumValidation: options.ResponseChecksumValidation, }, middleware.Before) if err != nil { return err } // Resolve a supported priority order list of algorithms to validate. algorithms := FilterSupportedAlgorithms(options.ValidationAlgorithms) m := &validateOutputPayloadChecksum{ Algorithms: algorithms, IgnoreMultipartValidation: options.IgnoreMultipartValidation, LogMultipartValidationSkipped: options.LogMultipartValidationSkipped, LogValidationSkipped: options.LogValidationSkipped, } return stack.Deserialize.Add(m, middleware.After) }

func AlgorithmChecksumLength(v Algorithm) (int, error)

AlgorithmChecksumLength returns the length of the algorithm’s checksum in bytes. If the algorithm is not known, an error is returned.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// File 'service/internal/checksum/algorithms.go', line 108

func AlgorithmChecksumLength(v Algorithm) (int, error) { switch v { case AlgorithmSHA1: return sha1.Size, nil case AlgorithmSHA256: return sha256.Size, nil case AlgorithmCRC32: return crc32.Size, nil case AlgorithmCRC32C: return crc32.Size, nil case AlgorithmCRC64NVME: return crc64.Size, nil default: return 0, fmt.Errorf("unknown checksum algorithm, %v", v) } }

func AlgorithmHTTPHeader(v Algorithm) string

AlgorithmHTTPHeader returns the HTTP header for the algorithm’s hash.



128
129
130
// File 'service/internal/checksum/algorithms.go', line 128

func AlgorithmHTTPHeader(v Algorithm) string { return awsChecksumHeaderPrefix + strings.ToLower(string(v)) }

func FilterSupportedAlgorithms(vs []string) []Algorithm

FilterSupportedAlgorithms filters the set of algorithms, returning a slice of algorithms that are supported.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// File 'service/internal/checksum/algorithms.go', line 65

func FilterSupportedAlgorithms(vs []string) []Algorithm { found := map[Algorithm]struct{}{} supported := make([]Algorithm, 0, len(supportedAlgorithms)) for _, v := range vs { for _, a := range supportedAlgorithms { // Only consider algorithms that are supported if !strings.EqualFold(v, string(a)) { continue } // Ignore duplicate algorithms in list. if _, ok := found[a]; ok { continue } supported = append(supported, a) found[a] = struct{}{} } } return supported }

func GetComputedInputChecksums(m middleware.Metadata) (map[string]string, bool)

GetComputedInputChecksums returns the map of checksum algorithm to their computed value stored in the middleware Metadata. Returns false if no values were stored in the Metadata.



29
30
31
32
// File 'service/internal/checksum/middleware_compute_input_checksum.go', line 29

func GetComputedInputChecksums(m middleware.Metadata) (map[string]string, bool) { vs, ok := m.Get(computedInputChecksumsKey{}).(map[string]string) return vs, ok }

func GetOutputValidationAlgorithmsUsed(m middleware.Metadata) ([]string, bool)

GetOutputValidationAlgorithmsUsed returns the checksum algorithms used stored in the middleware Metadata. Returns false if no algorithms were stored in the Metadata.



21
22
23
24
// File 'service/internal/checksum/middleware_validate_output.go', line 21

func GetOutputValidationAlgorithmsUsed(m middleware.Metadata) ([]string, bool) { vs, ok := m.Get(outputValidationAlgorithmsUsedKey{}).([]string) return vs, ok }

func NewAlgorithmHash(v Algorithm) (hash.Hash, error)

NewAlgorithmHash returns a hash.Hash for the checksum algorithm. Error is returned if the algorithm is unknown.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// File 'service/internal/checksum/algorithms.go', line 89

func NewAlgorithmHash(v Algorithm) (hash.Hash, error) { switch v { case AlgorithmSHA1: return sha1.New(), nil case AlgorithmSHA256: return sha256.New(), nil case AlgorithmCRC32: return crc32.NewIEEE(), nil case AlgorithmCRC32C: return crc32.New(crc32.MakeTable(crc32.Castagnoli)), nil case AlgorithmCRC64NVME: return crc64.New(crc64.MakeTable(crc64NVME)), nil default: return nil, fmt.Errorf("unknown checksum algorithm, %v", v) } }

func RemoveInputMiddleware(stack *middleware.Stack)

RemoveInputMiddleware Removes the compute input payload checksum middleware handlers from the stack.



97
98
99
100
101
102
103
// File 'service/internal/checksum/middleware_add.go', line 97

func RemoveInputMiddleware(stack *middleware.Stack) { id := (*SetupInputContext)(nil).ID() stack.Initialize.Remove(id) id = (*ComputeInputPayloadChecksum)(nil).ID() stack.Finalize.Remove(id) }

func RemoveOutputMiddleware(stack *middleware.Stack)

RemoveOutputMiddleware Removes the compute input payload checksum middleware handlers from the stack.



168
169
170
171
172
173
174
// File 'service/internal/checksum/middleware_add.go', line 168

func RemoveOutputMiddleware(stack *middleware.Stack) { id := (*setupOutputContext)(nil).ID() stack.Initialize.Remove(id) id = (*validateOutputPayloadChecksum)(nil).ID() stack.Deserialize.Remove(id) }

func SetComputedInputChecksums(m *middleware.Metadata, vs map[string]string)

SetComputedInputChecksums stores the map of checksum algorithm to their computed value in the middleware Metadata. Overwrites any values that currently exist in the metadata.



37
38
39
// File 'service/internal/checksum/middleware_compute_input_checksum.go', line 37

func SetComputedInputChecksums(m *middleware.Metadata, vs map[string]string) { m.Set(computedInputChecksumsKey{}, vs) }

func SetOutputValidationAlgorithmsUsed(m *middleware.Metadata, vs []string)

SetOutputValidationAlgorithmsUsed stores the checksum algorithms used in the middleware Metadata.



28
29
30
// File 'service/internal/checksum/middleware_validate_output.go', line 28

func SetOutputValidationAlgorithmsUsed(m *middleware.Metadata, vs []string) { m.Set(outputValidationAlgorithmsUsedKey{}, vs) }