public void arrayBasedAssessment(Cipher cipher, byte[] aad, byte[] tag, byte[] plaintext,
                                     byte[] ciphertext, Key key, AlgorithmParameterSpec params,
                                     String transformation, Provider p, String[] line) throws Exception {
        byte[] combinedCiphertext = new byte[ciphertext.length + tag.length];
        System.arraycopy(ciphertext, 0, combinedCiphertext, 0, ciphertext.length);
        System.arraycopy(tag, 0, combinedCiphertext, ciphertext.length, tag.length);

        for (CallPattern callPattern: CallPattern.values()) {
            // We first initialize the cipher with a modified IV to make sure that we don't trigger
            // an IV reuse check.
            cipher.init(Cipher.ENCRYPT_MODE, key, modifiedParams(params));

            cipher.init(Cipher.ENCRYPT_MODE, key, params);
            if (aad.length > 0) {
                cipher.updateAAD(aad);
            }
            assertEquals("Provider " + p.getName()
                            + ", algorithm " + transformation
                            + " reported the wrong output size",
                    combinedCiphertext.length, cipher.getOutputSize(plaintext.length));
            byte[] encrypted = callCipher(cipher, plaintext, combinedCiphertext.length, callPattern);
            assertArrayEquals("Provider " + p.getName()
                + ", algorithm " + transformation + ", CallPattern " + callPattern
                + " failed on encryption, data is " + Arrays.toString(line),
                combinedCiphertext, encrypted);
        }

        for (CallPattern callPattern: CallPattern.values()) {
            cipher.init(Cipher.DECRYPT_MODE, key, params);
            if (aad.length > 0) {
                cipher.updateAAD(aad);
            }
            assertEquals("Provider " + p.getName()
                            + ", algorithm " + transformation
                            + " reported the wrong output size",
                    plaintext.length, cipher.getOutputSize(combinedCiphertext.length));
            byte[] decrypted;
            try {
                decrypted = callCipher(cipher, combinedCiphertext, plaintext.length, callPattern);
            } catch (GeneralSecurityException e) {
                throw new GeneralSecurityException("Provider " + p.getName()
                + ", algorithm " + transformation + ", CallPattern " + callPattern
                + " failed on decryption, data is " + Arrays.toString(line), e);
            }
            assertArrayEquals("Provider " + p.getName()
                + ", algorithm " + transformation + ", CallPattern " + callPattern
                + " failed on decryption, data is " + Arrays.toString(line),
                plaintext, decrypted);
        }
    }
Calls an initialized cipher with different equivalent call patterns.
common/src/test/java/org/conscrypt/javax/crypto/CipherBasicsTest.java