42
42
import java .util .function .Consumer ;
43
43
import java .util .function .Function ;
44
44
45
+ import static software .amazon .encryption .s3 .S3EncryptionClientUtilities .DEFAULT_BUFFER_SIZE_BYTES ;
46
+ import static software .amazon .encryption .s3 .S3EncryptionClientUtilities .MAX_ALLOWED_BUFFER_SIZE_BYTES ;
47
+ import static software .amazon .encryption .s3 .S3EncryptionClientUtilities .MIN_ALLOWED_BUFFER_SIZE_BYTES ;
45
48
import static software .amazon .encryption .s3 .internal .ApiNameVersion .API_NAME_INTERCEPTOR ;
46
49
47
50
/**
@@ -56,6 +59,7 @@ public class S3AsyncEncryptionClient extends DelegatingS3AsyncClient {
56
59
private final boolean _enableLegacyUnauthenticatedModes ;
57
60
private final boolean _enableDelayedAuthenticationMode ;
58
61
private final boolean _enableMultipartPutObject ;
62
+ private final long _bufferSize ;
59
63
60
64
private S3AsyncEncryptionClient (Builder builder ) {
61
65
super (builder ._wrappedClient );
@@ -65,6 +69,7 @@ private S3AsyncEncryptionClient(Builder builder) {
65
69
_enableLegacyUnauthenticatedModes = builder ._enableLegacyUnauthenticatedModes ;
66
70
_enableDelayedAuthenticationMode = builder ._enableDelayedAuthenticationMode ;
67
71
_enableMultipartPutObject = builder ._enableMultipartPutObject ;
72
+ _bufferSize = builder ._bufferSize ;
68
73
}
69
74
70
75
/**
@@ -181,6 +186,7 @@ public <T> CompletableFuture<T> getObject(GetObjectRequest getObjectRequest,
181
186
.cryptoMaterialsManager (_cryptoMaterialsManager )
182
187
.enableLegacyUnauthenticatedModes (_enableLegacyUnauthenticatedModes )
183
188
.enableDelayedAuthentication (_enableDelayedAuthenticationMode )
189
+ .bufferSize (_bufferSize )
184
190
.build ();
185
191
186
192
return pipeline .getObject (getObjectRequest , asyncResponseTransformer );
@@ -200,9 +206,9 @@ public CompletableFuture<DeleteObjectResponse> deleteObject(DeleteObjectRequest
200
206
final DeleteObjectRequest actualRequest = deleteObjectRequest .toBuilder ()
201
207
.overrideConfiguration (API_NAME_INTERCEPTOR )
202
208
.build ();
203
- final CompletableFuture <DeleteObjectResponse > response = _wrappedClient .deleteObject (actualRequest );
209
+ final CompletableFuture <DeleteObjectResponse > response = _wrappedClient .deleteObject (actualRequest );
204
210
final String instructionObjectKey = deleteObjectRequest .key () + ".instruction" ;
205
- final CompletableFuture <DeleteObjectResponse > instructionResponse = _wrappedClient .deleteObject (builder -> builder
211
+ final CompletableFuture <DeleteObjectResponse > instructionResponse = _wrappedClient .deleteObject (builder -> builder
206
212
.overrideConfiguration (API_NAME_INTERCEPTOR )
207
213
.bucket (deleteObjectRequest .bucket ())
208
214
.key (instructionObjectKey ));
@@ -257,6 +263,7 @@ public static class Builder {
257
263
private boolean _enableMultipartPutObject = false ;
258
264
private Provider _cryptoProvider = null ;
259
265
private SecureRandom _secureRandom = new SecureRandom ();
266
+ private long _bufferSize = -1L ;
260
267
261
268
private Builder () {
262
269
}
@@ -434,6 +441,22 @@ public Builder enableMultipartPutObject(boolean _enableMultipartPutObject) {
434
441
return this ;
435
442
}
436
443
444
+ /**
445
+ * Sets the buffer size for safe authentication used when delayed authentication mode is disabled.
446
+ * If buffer size is not given during client configuration, default buffer size is set to 64MiB.
447
+ * @param bufferSize the desired buffer size in Bytes.
448
+ * @return Returns a reference to this object so that method calls can be chained together.
449
+ * @throws S3EncryptionClientException if the specified buffer size is outside the allowed bounds
450
+ */
451
+ public Builder setBufferSize (long bufferSize ) {
452
+ if (bufferSize < MIN_ALLOWED_BUFFER_SIZE_BYTES || bufferSize > MAX_ALLOWED_BUFFER_SIZE_BYTES ) {
453
+ throw new S3EncryptionClientException ("Invalid buffer size: " + bufferSize + " Bytes. Buffer size must be between " + MIN_ALLOWED_BUFFER_SIZE_BYTES + " and " + MAX_ALLOWED_BUFFER_SIZE_BYTES + " Bytes." );
454
+ }
455
+
456
+ this ._bufferSize = bufferSize ;
457
+ return this ;
458
+ }
459
+
437
460
/**
438
461
* Allows the user to pass an instance of {@link Provider} to be used
439
462
* for cryptographic operations. By default, the S3 Encryption Client
@@ -476,6 +499,14 @@ public S3AsyncEncryptionClient build() {
476
499
throw new S3EncryptionClientException ("Exactly one must be set of: crypto materials manager, keyring, AES key, RSA key pair, KMS key id" );
477
500
}
478
501
502
+ if (_bufferSize >= 0 ) {
503
+ if (_enableDelayedAuthenticationMode ) {
504
+ throw new S3EncryptionClientException ("Buffer size cannot be set when delayed authentication mode is enabled" );
505
+ }
506
+ } else {
507
+ _bufferSize = DEFAULT_BUFFER_SIZE_BYTES ;
508
+ }
509
+
479
510
if (_keyring == null ) {
480
511
if (_aesKey != null ) {
481
512
_keyring = AesKeyring .builder ()
0 commit comments