Skip to content

Commit 53d62d6

Browse files
author
Lucas McDonald
committed
m
1 parent 12be3e3 commit 53d62d6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/software/amazon/encryption/s3/internal/CipherSubscriber.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ public void onNext(ByteBuffer byteBuffer) {
8787
// Since this class can only call `wrappedSubscriber.onNext` once,
8888
// it must send all remaining data in the next onNext call,
8989
// including the result of cipher.doFinal(), if applicable.
90-
// Calling `wrappedSubscriber.onNext` more than once violates the Reactive Streams specification
91-
// and can cause exceptions downstream.
90+
// Calling `wrappedSubscriber.onNext` more than once for `request(1)`
91+
// violates the Reactive Streams specification and can cause exceptions downstream.
9292
if (contentRead.get() + tagLength >= contentLength) {
9393
// All content has been read; complete the stream.
94+
// (Signalling onComplete from here is Reactive Streams-spec compliant;
95+
// this class is allowed to call onComplete, even if upstream has not yet signaled onComplete.)
9496
this.onComplete();
9597
} else {
9698
// Needs to read more data, so send the data downstream,
@@ -128,7 +130,7 @@ public void onError(Throwable t) {
128130

129131
@Override
130132
public void onComplete() {
131-
// onComplete can be signalled to CipherSubscriber multiple times
133+
// onComplete can be signalled to CipherSubscriber multiple times,
132134
// but additional calls should be deduped to avoid calling onNext multiple times
133135
// and raising exceptions.
134136
if (onCompleteCalled) {
@@ -149,7 +151,6 @@ public void onComplete() {
149151

150152
// If this is the last part, compute doFinal and include its result in the value sent downstream.
151153
// The result of doFinal MUST be included with the bytes that were in outputBuffer in the final onNext call.
152-
// When this class calculates it has read all content
153154
byte[] finalBytes = null;
154155
try {
155156
finalBytes = cipher.doFinal();

0 commit comments

Comments
 (0)