@NotThreadSafe public class LazyMessageCryptoHandler extends Object implements MessageCryptoHandler
MessageCryptoHandler
that delegates to another MessageCryptoHandler, which is created
at the last possible moment. Typically, this is used in order to defer the creation of the data
key (and associated request to the CryptoMaterialsManager
until the max message size is known.Modifier and Type | Class and Description |
---|---|
static class |
LazyMessageCryptoHandler.LateBoundInfo |
Constructor and Description |
---|
LazyMessageCryptoHandler(Function<LazyMessageCryptoHandler.LateBoundInfo,MessageCryptoHandler> delegateFactory) |
Modifier and Type | Method and Description |
---|---|
int |
doFinal(byte[] out,
int outOff)
Finish processing of the bytes.
|
int |
estimateFinalOutputSize()
Return the size of the output buffer required for a call to
CryptoHandler.doFinal(byte[], int) . |
int |
estimateOutputSize(int inLen)
Return the size of the output buffer required for a
CryptoHandler.processBytes(byte[], int, int,
byte[], int) plus a CryptoHandler.doFinal(byte[], int) call with an input of inLen bytes. |
int |
estimatePartialOutputSize(int inLen)
Return the size of the output buffer required for a call to
CryptoHandler.processBytes(byte[], int,
int, byte[], int) . |
Map<String,String> |
getEncryptionContext()
Return the encryption context used in the generation of the data key used for the encryption of
content.
|
CiphertextHeaders |
getHeaders() |
List<? extends MasterKey<?>> |
getMasterKeys()
All used
MasterKey s. |
boolean |
isComplete()
For decrypt and parsing flows returns
true when this has handled as many bytes as it
can. |
ProcessingSummary |
processBytes(byte[] in,
int inOff,
int inLen,
byte[] out,
int outOff)
Process a block of bytes from
in putting the result into out . |
void |
setMaxInputLength(long size)
Informs this handler of an upper bound on the input data size.
|
public LazyMessageCryptoHandler(Function<LazyMessageCryptoHandler.LateBoundInfo,MessageCryptoHandler> delegateFactory)
public void setMaxInputLength(long size)
MessageCryptoHandler
If this method is called multiple times, the smallest bound will be used.
setMaxInputLength
in interface MessageCryptoHandler
size
- An upper bound on the input data size.public boolean isComplete()
CryptoHandler
true
when this has handled as many bytes as it
can. This usually means that it has reached the end of an object, file, or other delimited
stream.isComplete
in interface CryptoHandler
public Map<String,String> getEncryptionContext()
MessageCryptoHandler
During decryption, this value should be obtained by parsing the ciphertext headers that encodes this value.
getEncryptionContext
in interface MessageCryptoHandler
public CiphertextHeaders getHeaders()
getHeaders
in interface MessageCryptoHandler
public ProcessingSummary processBytes(byte[] in, int inOff, int inLen, byte[] out, int outOff)
CryptoHandler
in
putting the result into out
.processBytes
in interface CryptoHandler
in
- the input byte array.inOff
- the offset into the in
array where the data to be processed starts.inLen
- the number of bytes to be processed.out
- the output buffer the processed bytes go into.outOff
- the offset into the output byte array the processed data starts at.out
and the number of bytes parsed.public List<? extends MasterKey<?>> getMasterKeys()
MessageCryptoHandler
MasterKey
s. For encryption flows, these are all the MasterKey
s used to protect the data. In the decryption flow, it is the single MasterKey
actually used to decrypt the data.getMasterKeys
in interface MessageCryptoHandler
public int doFinal(byte[] out, int outOff)
CryptoHandler
doFinal
in interface CryptoHandler
out
- the output buffer for copying any remaining output data.outOff
- offset into out
to start copying the output data.out
.public int estimateOutputSize(int inLen)
CryptoHandler
CryptoHandler.processBytes(byte[], int, int,
byte[], int)
plus a CryptoHandler.doFinal(byte[], int)
call with an input of inLen
bytes.
Note this method is allowed to return an estimation of the output size that is greater than the actual size of the output. Returning an estimate that is lesser than the actual size of the output will result in underflow exceptions.
estimateOutputSize
in interface CryptoHandler
inLen
- the length of the input.CryptoHandler.doFinal(byte[],
int)
with an input of size inLen
bytes.public int estimatePartialOutputSize(int inLen)
CryptoHandler
CryptoHandler.processBytes(byte[], int,
int, byte[], int)
.
Note this method is allowed to return an estimation of the output size that is greater than the actual size of the output. Returning an estimate that is lesser than the actual size of the output will result in underflow exceptions.
estimatePartialOutputSize
in interface CryptoHandler
inLen
- the length of the input.CryptoHandler.processBytes(byte[], int, int,
byte[], int)
with an input of size inLen
bytes.public int estimateFinalOutputSize()
CryptoHandler
CryptoHandler.doFinal(byte[], int)
.
Note this method is allowed to return an estimation of the output size that is greater than the actual size of the output. Returning an estimate that is lesser than the actual size of the output will result in underflow exceptions.
estimateFinalOutputSize
in interface CryptoHandler
CryptoHandler.doFinal(byte[], int)
Copyright © 2023. All rights reserved.