public class GeneralJsonSerializer extends JWSSerializer
This class implements the JWSSerializer interface. If defines the logic to serialize a JWS using the General Json Serialization, defined in RFC 7515. Inject an instance of this class to JWSSignedData(JWSSerializer) to create a JWS with this serialization. Note that if the signature incorporates only a single signer, the implementation will always use Flattened Serialization.
It writes the JWS to the specified OutputStream.
Constructor and Description |
---|
GeneralJsonSerializer(OutputStream output)
Creates the serializer which writes all bytes to the specified stream.
|
GeneralJsonSerializer(OutputStream output,
JsonFactoryWrapper factory)
Creates the serializer which writes all bytes to the specified stream.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closePayload()
Signals that the payload stream finished.
|
protected void |
finalizeSigners(List<? extends JWSSigner> signers,
List<String> signatureValues)
Serializes the remaining information of the signers to the specified destination.
|
protected void |
serializeJWS(List<iaik.jades.JWSSignerSigning> signers,
byte[] payload,
List<String> signatureValues)
Writes the provided information as JWS in General Json Serialization.
|
protected boolean |
supportMultipleSigners()
Tells whether this serializer can support multiple signers
|
protected void |
writePayload(byte[] bytes,
int off,
int len)
This is a hack to enable writing the payload in a streaming way.
|
protected void |
writePreamble(List<iaik.jades.JWSSignerSigning> signers)
Writes the Preamble of the signature.
|
public GeneralJsonSerializer(OutputStream output) throws IOException
Creates the serializer which writes all bytes to the specified stream. This class will NOT close the stream.
output
- an OutputStreamIOException
public GeneralJsonSerializer(OutputStream output, JsonFactoryWrapper factory) throws IOException
Creates the serializer which writes all bytes to the specified stream. This class will NOT close the stream. Uses the JsonFactoryWrapper to create Jackson's JsonGenerator. In almost all cases it is sufficient to use the constructor and reuse the default implementation.
output
- an OutputStreamfactory
- a class managing an instance of Jackson's JsonFactoryIOException
protected void serializeJWS(List<iaik.jades.JWSSignerSigning> signers, byte[] payload, List<String> signatureValues) throws JWSException, IOException
Writes the provided information as JWS in General Json Serialization. If the list of signers contains only a single signer, this method uses the flattened serialization.
Only writes to the OutputStream. This method does not perform any additional processing.
serializeJWS
in class JWSSerializer
JWSException
IOException
protected boolean supportMultipleSigners()
supportMultipleSigners
in class JWSSerializer
true
protected void finalizeSigners(List<? extends JWSSigner> signers, List<String> signatureValues) throws IOException
Serializes the remaining information of the signers to the specified destination. During streamed serialization, call this always after closePayload().
Writes the Json representation of the signers. If there is only a single signer, this method uses the flattened serialization.
finalizeSigners
in class JWSSerializer
signers
- the signers of the signaturesignatureValues
- the signature values of the signers in respective orderIOException
- if it is not possible to write to specified destinationprotected void writePreamble(List<iaik.jades.JWSSignerSigning> signers) throws IOException
Writes the Preamble of the signature. Only necessary in streaming context.
For this concrete implementation, writes "{" to signalize start of JSON.
writePreamble
in class JWSSerializer
signers
- ignoredIOException
- if it is not possible to write to specified destinationprotected void writePayload(byte[] bytes, int off, int len) throws IOException
writePayload
in class JWSSerializer
IOException
protected void closePayload() throws IOException
Signals that the payload stream finished. Closes the string value from the payload.
closePayload
in class JWSSerializer
IOException
Copyright © 2022 Stiftung SIC. All rights reserved.