class EncryptThenAuthenticate implements Aead {

  @Override
  public byte[] decrypt(final byte[] ciphertext, final byte[] associatedData)
      throws GeneralSecurityException {
    if (ciphertext.length < macLength) {
      throw new GeneralSecurityException("ciphertext too short");
    }
    byte[] rawCiphertext = Arrays.copyOfRange(ciphertext, 0, ciphertext.length - macLength);
    byte[] macValue =
        Arrays.copyOfRange(ciphertext, ciphertext.length - macLength, ciphertext.length);
    byte[] aad = associatedData;
    if (aad == null) {
      aad = new byte[0];
    }
    byte[] aadLengthInBits =
        Arrays.copyOf(ByteBuffer.allocate(8).putLong(8L * aad.length).array(), 8);
    mac.verifyMac(macValue, Bytes.concat(aad, rawCiphertext, aadLengthInBits));
    return cipher.decrypt(rawCiphertext);
  }

  public  EncryptThenAuthenticate(final IndCpaCipher cipher, final Mac mac, int macLength);

}