-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathChecksumConfig.java
More file actions
139 lines (122 loc) · 4.72 KB
/
ChecksumConfig.java
File metadata and controls
139 lines (122 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
package software.amazon.awssdk.crt.s3;
import java.util.List;
import java.util.Collections;
public class ChecksumConfig {
public enum ChecksumLocation {
NONE(0),
HEADER(1),
TRAILER(2);
ChecksumLocation(int nativeValue) {
this.nativeValue = nativeValue;
}
public int getNativeValue() {
return nativeValue;
}
private int nativeValue;
};
private ChecksumLocation location = ChecksumLocation.NONE;
private ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.NONE;
private boolean validateChecksum = false;
private List<ChecksumAlgorithm> validateChecksumAlgorithmList = null;
public ChecksumConfig() {
}
/**
* If NONE. No request payload checksum will be added and calculated.
*
* If HEADER, the checksum will be calculated by client and related header added
* to the request sent.
*
* If TRAILER, the payload will be aws_chunked encoded, The checksum will be
* calculated while reading the
* payload by client. Related header will be added to the trailer part of the
* encoded payload. Note the payload of
* the original request cannot be aws-chunked encoded already. Otherwise, error
* will be raised.
*
* @param location The location of client added request payload checksum header.
* @return this
*/
public ChecksumConfig withChecksumLocation(ChecksumLocation location) {
this.location = location;
return this;
}
/**
* @return The location of client added checksum header.
*/
public ChecksumLocation getChecksumLocation() {
return this.location;
}
/**
* The checksum algorithm used to calculate the checksum of payload uploaded.
* Must be set if location is not AWS_SCL_NONE. Must be AWS_SCA_NONE if location
* is AWS_SCL_NONE.
*
* @param algorithm The checksum algorithm used to calculate the checksum of
* payload uploaded.
* @return this
*/
public ChecksumConfig withChecksumAlgorithm(ChecksumAlgorithm algorithm) {
this.checksumAlgorithm = algorithm;
return this;
}
/**
* @return The checksum algorithm used to calculate the checksum of payload
* uploaded.
*/
public ChecksumAlgorithm getChecksumAlgorithm() {
return this.checksumAlgorithm;
}
/**
* Enable checksum mode header will be attached to get requests, this will tell
* s3 to send back checksums headers if they exist.
*
* For object that has checksum, the checksum of whole object will be calculated
* and validated. The result will finish with a did validate field.
*
* For object has checksum for parts, if ALL the parts have been validated, the
* result will finish with a did validate field. If any part failed the
* validation, AWS_ERROR_S3_RESPONSE_CHECKSUM_MISMATCH will be raised.
*
* @param validateChecksum Validate the checksum of response if server provides.
* @return this
*/
public ChecksumConfig withValidateChecksum(boolean validateChecksum) {
this.validateChecksum = validateChecksum;
return this;
}
public boolean getValidateChecksum() {
return validateChecksum;
}
/**
* Ignored when validate_response_checksum is not set.
* If not set all the algorithms will be selected as default behavior.
*
* The list of algorithms for user to pick up when validate the checksum. Client
* will pick up the algorithm from the list with the priority based on
* performance, and the algorithm sent by server. The priority based on
* performance is [XXHASH128, XXHASH3,CRC64NVME, CRC32C, CRC32, XXHASH64, SHA512, SHA256, SHA1].
*
* If the response checksum was validated by client, the result will indicate
* which algorithm was picked.
*
* @param validateChecksumAlgorithmList The list of algorithm picked to validate
* checksum from response.
* @return this
*/
public ChecksumConfig withValidateChecksumAlgorithmList(List<ChecksumAlgorithm> validateChecksumAlgorithmList) {
this.validateChecksumAlgorithmList = validateChecksumAlgorithmList != null
? Collections.unmodifiableList(validateChecksumAlgorithmList)
: null;
return this;
}
/**
* @return The list of algorithm picked to validate checksum from response.
*/
public List<ChecksumAlgorithm> getValidateChecksumAlgorithmList() {
return this.validateChecksumAlgorithmList;
}
}