Class LazyMessageCryptoHandler
- All Implemented Interfaces:
CryptoHandler
,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.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionLazyMessageCryptoHandler(Function<LazyMessageCryptoHandler.LateBoundInfo,MessageCryptoHandler> delegateFactory)
-
Method Summary
Modifier and TypeMethodDescriptionint
doFinal(byte[] out, int outOff)
Finish processing of the bytes.int
Return the size of the output buffer required for a call toCryptoHandler.doFinal(byte[], int)
.int
estimateOutputSize(int inLen)
Return the size of the output buffer required for aCryptoHandler.processBytes(byte[], int, int, byte[], int)
plus aCryptoHandler.doFinal(byte[], int)
call with an input ofinLen
bytes.int
estimatePartialOutputSize(int inLen)
Return the size of the output buffer required for a call toCryptoHandler.processBytes(byte[], int, int, byte[], int)
.Return the encryption context used in the generation of the data key used for the encryption of content.All usedMasterKey
s.boolean
For decrypt and parsing flows returnstrue
when this has handled as many bytes as it can.processBytes(byte[] in, int inOff, int inLen, byte[] out, int outOff)
Process a block of bytes fromin
putting the result intoout
.void
setMaxInputLength(long size)
Informs this handler of an upper bound on the input data size.
-
Constructor Details
-
LazyMessageCryptoHandler
public LazyMessageCryptoHandler(Function<LazyMessageCryptoHandler.LateBoundInfo,MessageCryptoHandler> delegateFactory)
-
-
Method Details
-
setMaxInputLength
public void setMaxInputLength(long size)Description copied from interface:MessageCryptoHandler
Informs this handler of an upper bound on the input data size. The handler will throw an exception if this bound is exceeded, and may use it to perform performance optimizations as well.If this method is called multiple times, the smallest bound will be used.
- Specified by:
setMaxInputLength
in interfaceMessageCryptoHandler
- Parameters:
size
- An upper bound on the input data size.
-
isComplete
public boolean isComplete()Description copied from interface:CryptoHandler
For decrypt and parsing flows returnstrue
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.- Specified by:
isComplete
in interfaceCryptoHandler
-
getEncryptionContext
Description copied from interface:MessageCryptoHandler
Return the encryption context used in the generation of the data key used for the encryption of content.During decryption, this value should be obtained by parsing the ciphertext headers that encodes this value.
- Specified by:
getEncryptionContext
in interfaceMessageCryptoHandler
- Returns:
- the key-value map containing the encryption context.
-
getHeaders
- Specified by:
getHeaders
in interfaceMessageCryptoHandler
-
processBytes
Description copied from interface:CryptoHandler
Process a block of bytes fromin
putting the result intoout
.- Specified by:
processBytes
in interfaceCryptoHandler
- Parameters:
in
- the input byte array.inOff
- the offset into thein
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.- Returns:
- the number of bytes written to
out
and the number of bytes parsed.
-
getMasterKeys
Description copied from interface:MessageCryptoHandler
All usedMasterKey
s. For encryption flows, these are all theMasterKey
s used to protect the data. In the decryption flow, it is the singleMasterKey
actually used to decrypt the data.- Specified by:
getMasterKeys
in interfaceMessageCryptoHandler
-
doFinal
public int doFinal(byte[] out, int outOff)Description copied from interface:CryptoHandler
Finish processing of the bytes.- Specified by:
doFinal
in interfaceCryptoHandler
- Parameters:
out
- the output buffer for copying any remaining output data.outOff
- offset intoout
to start copying the output data.- Returns:
- number of bytes written into
out
.
-
estimateOutputSize
public int estimateOutputSize(int inLen)Description copied from interface:CryptoHandler
Return the size of the output buffer required for aCryptoHandler.processBytes(byte[], int, int, byte[], int)
plus aCryptoHandler.doFinal(byte[], int)
call with an input ofinLen
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.
- Specified by:
estimateOutputSize
in interfaceCryptoHandler
- Parameters:
inLen
- the length of the input.- Returns:
- the space required to accommodate a call to processBytes and
CryptoHandler.doFinal(byte[], int)
with an input of sizeinLen
bytes.
-
estimatePartialOutputSize
public int estimatePartialOutputSize(int inLen)Description copied from interface:CryptoHandler
Return the size of the output buffer required for a call toCryptoHandler.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.
- Specified by:
estimatePartialOutputSize
in interfaceCryptoHandler
- Parameters:
inLen
- the length of the input.- Returns:
- the space required to accommodate a call to
CryptoHandler.processBytes(byte[], int, int, byte[], int)
with an input of sizeinLen
bytes.
-
estimateFinalOutputSize
public int estimateFinalOutputSize()Description copied from interface:CryptoHandler
Return the size of the output buffer required for a call toCryptoHandler.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.
- Specified by:
estimateFinalOutputSize
in interfaceCryptoHandler
- Returns:
- the space required to accomodate a call to
CryptoHandler.doFinal(byte[], int)
-