private void readHeaderFields(final CiphertextHeaders ciphertextHeaders){
  final byte version=ciphertextHeaders.getVersion();
  if (version != VersionInfo.CURRENT_CIPHERTEXT_VERSION) {
    throw new BadCiphertextException("Invalid version in ciphertext.");
  }
  cryptoAlgo_=ciphertextHeaders.getCryptoAlgoId();
  final CiphertextType ciphertextType=ciphertextHeaders.getType();
  if (ciphertextType != CiphertextType.CUSTOMER_AUTHENTICATED_ENCRYPTED_DATA) {
    throw new BadCiphertextException("Invalid type in ciphertext.");
  }
  final byte[] messageId=ciphertextHeaders.getMessageId();
  encryptionContext_=ciphertextHeaders.getEncryptionContextMap();
  if (cryptoAlgo_.getTrailingSignatureLength() > 0) {
    try {
      trailingPublicKey_=deserializeTrailingKeyFromEc(encryptionContext_.get(Constants.EC_PUBLIC_KEY_FIELD));
      trailingSig_=Signature.getInstance(cryptoAlgo_.getTrailingSignatureAlgo(),"BC");
      trailingSig_.initVerify(trailingPublicKey_);
    }
 catch (    final GeneralSecurityException ex) {
      throw new AwsCryptoException(ex);
    }
  }
 else {
    trailingPublicKey_=null;
    trailingSig_=null;
  }
  final ContentType contentType=ciphertextHeaders.getContentType();
  final short nonceLen=ciphertextHeaders.getNonceLength();
  final int frameLen=ciphertextHeaders.getFrameLength();
  dataKey_=getDataKey(ciphertextHeaders);
  try {
    decryptionKey_=cryptoAlgo_.getEncryptionKeyFromDataKey(dataKey_.getKey(),ciphertextHeaders);
  }
 catch (  final InvalidKeyException ex) {
    throw new AwsCryptoException(ex);
  }
  verifyHeaderIntegrity(ciphertextHeaders);
switch (contentType) {
case FRAME:
    contentCryptoHandler_=new FrameDecryptionHandler(decryptionKey_,(byte)nonceLen,cryptoAlgo_,messageId,frameLen);
  break;
case SINGLEBLOCK:
contentCryptoHandler_=new BlockDecryptionHandler(decryptionKey_,(byte)nonceLen,cryptoAlgo_,messageId);
break;
default :
break;
}
}

private void readHeaderFields ( final CiphertextHeaders ciphertextHeaders ) { final byte version = ciphertextHeaders . getVersion ( ) ; if ( version != VersionInfo . CURRENT_CIPHERTEXT_VERSION ) { throw new BadCiphertextException ( "Invalid version in ciphertext." ) ; } cryptoAlgo_ = ciphertextHeaders . getCryptoAlgoId ( ) ; final CiphertextType ciphertextType = ciphertextHeaders . getType ( ) ; if ( ciphertextType != CiphertextType . CUSTOMER_AUTHENTICATED_ENCRYPTED_DATA ) { throw new BadCiphertextException ( "Invalid type in ciphertext." ) ; } final byte [ ] messageId = ciphertextHeaders . getMessageId ( ) ; encryptionContext_ = ciphertextHeaders . getEncryptionContextMap ( ) ; if ( cryptoAlgo_ . getTrailingSignatureLength ( ) > 0 ) { try { trailingPublicKey_ = deserializeTrailingKeyFromEc ( encryptionContext_ . get ( Constants . EC_PUBLIC_KEY_FIELD ) ) ; trailingSig_ = Signature . getInstance ( cryptoAlgo_ . getTrailingSignatureAlgo ( ) , "BC" ) ; trailingSig_ . initVerify ( trailingPublicKey_ ) ; } catch ( final GeneralSecurityException ex ) { throw new AwsCryptoException ( ex ) ; } } else { trailingPublicKey_ = null ; trailingSig_ = null ; } final ContentType contentType = ciphertextHeaders . getContentType ( ) ; final short nonceLen = ciphertextHeaders . getNonceLength ( ) ; final int frameLen = ciphertextHeaders . getFrameLength ( ) ; dataKey_ = getDataKey ( ciphertextHeaders ) ; try { decryptionKey_ = cryptoAlgo_ . getEncryptionKeyFromDataKey ( dataKey_ . getKey ( ) , ciphertextHeaders ) ; } catch ( final InvalidKeyException ex ) { throw new AwsCryptoException ( ex ) ; } verifyHeaderIntegrity ( ciphertextHeaders ) ; switch ( contentType ) { case FRAME : contentCryptoHandler_ = new FrameDecryptionHandler ( decryptionKey_ , ( byte ) nonceLen , cryptoAlgo_ , messageId , frameLen ) ; break ; case SINGLEBLOCK : contentCryptoHandler_ = new BlockDecryptionHandler ( decryptionKey_ , ( byte ) nonceLen , cryptoAlgo_ , messageId ) ; break ; default : break ; } }
read the fields in the ciphertext headers to populate the corresponding instance variables used during decryption .
