Class LazyMessageCryptoHandler

java.lang.Object
com.amazonaws.encryptionsdk.internal.LazyMessageCryptoHandler
All Implemented Interfaces:
CryptoHandler, MessageCryptoHandler

@NotThreadSafe public class LazyMessageCryptoHandler extends Object implements MessageCryptoHandler
A 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.
  • Constructor Details

  • 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 interface MessageCryptoHandler
      Parameters:
      size - An upper bound on the input data size.
    • isComplete

      public boolean isComplete()
      Description copied from interface: CryptoHandler
      For decrypt and parsing flows returns 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.
      Specified by:
      isComplete in interface CryptoHandler
    • getEncryptionContext

      public Map<String,​String> 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 interface MessageCryptoHandler
      Returns:
      the key-value map containing the encryption context.
    • getHeaders

      public CiphertextHeaders getHeaders()
      Specified by:
      getHeaders in interface MessageCryptoHandler
    • processBytes

      public ProcessingSummary processBytes(byte[] in, int inOff, int inLen, byte[] out, int outOff)
      Description copied from interface: CryptoHandler
      Process a block of bytes from in putting the result into out.
      Specified by:
      processBytes in interface CryptoHandler
      Parameters:
      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.
      Returns:
      the number of bytes written to out and the number of bytes parsed.
    • getMasterKeys

      public List<? extends MasterKey<?>> getMasterKeys()
      Description copied from interface: MessageCryptoHandler
      All used MasterKeys. For encryption flows, these are all the MasterKeys used to protect the data. In the decryption flow, it is the single MasterKey actually used to decrypt the data.
      Specified by:
      getMasterKeys in interface MessageCryptoHandler
    • doFinal

      public int doFinal(byte[] out, int outOff)
      Description copied from interface: CryptoHandler
      Finish processing of the bytes.
      Specified by:
      doFinal in interface CryptoHandler
      Parameters:
      out - the output buffer for copying any remaining output data.
      outOff - offset into out 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 a 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.

      Specified by:
      estimateOutputSize in interface CryptoHandler
      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 size inLen bytes.
    • estimatePartialOutputSize

      public int estimatePartialOutputSize(int inLen)
      Description copied from interface: CryptoHandler
      Return the size of the output buffer required for a call to 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.

      Specified by:
      estimatePartialOutputSize in interface CryptoHandler
      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 size inLen bytes.
    • estimateFinalOutputSize

      public int estimateFinalOutputSize()
      Description copied from interface: CryptoHandler
      Return the size of the output buffer required for a call to 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.

      Specified by:
      estimateFinalOutputSize in interface CryptoHandler
      Returns:
      the space required to accomodate a call to CryptoHandler.doFinal(byte[], int)