Skip to content

Commit

Permalink
Preserve the content name
Browse files Browse the repository at this point in the history
  • Loading branch information
mnylen committed Apr 24, 2024
1 parent 22b946f commit 9e94665
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private String sign(final Payload payload, final Key key, final Provider provide

// Next, b64 extension requires the raw (non-encoded) payload to be included directly in the signing input,
// so we ensure we have an input stream for that:
payloadStream = convertPayloadToInputStream(payload);
payloadStream = toInputStream("JWS Unencoded Payload", payload);

if (!payload.isClaims()) {
payloadStream = new CountingInputStream(payloadStream); // we'll need to assert if it's empty later
Expand Down Expand Up @@ -687,7 +687,7 @@ private String encrypt(final Payload content, final Key key, final Provider keyP
Assert.stateNotNull(keyAlgFunction, "KeyAlgorithm function cannot be null.");
assertPayloadEncoding("JWE");

InputStream plaintext = convertPayloadToInputStream(content);
InputStream plaintext = toInputStream("JWE Unencoded Payload", content);

//only expose (mutable) JweHeader functionality to KeyAlgorithm instances, not the full headerBuilder
// (which exposes this JwtBuilder and shouldn't be referenced by KeyAlgorithms):
Expand Down Expand Up @@ -807,10 +807,10 @@ private void encodeAndWrite(String name, byte[] data, OutputStream out) {
Streams.writeAndClose(out, data, "Unable to write bytes");
}

private InputStream convertPayloadToInputStream(Payload payload) {
private InputStream toInputStream(final String name, Payload payload) {
if (payload.isClaims() || payload.isCompressed()) {
ByteArrayOutputStream claimsOut = new ByteArrayOutputStream(8192);
writeAndClose("JWS Unencoded Payload", payload, claimsOut);
writeAndClose(name, payload, claimsOut);
return Streams.of(claimsOut.toByteArray());
} else {
// No claims and not compressed, so just get the direct InputStream:
Expand Down

0 comments on commit 9e94665

Please sign in to comment.