public void sharedBufferBasedAssessment(Cipher cipher, byte[] aad, byte[] tag, byte[] _plaintext,
                                      byte[] _ciphertext, Key key, AlgorithmParameterSpec params,
                                      String transformation, Provider p) throws Exception {
        // 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);
        }
        byte[] _combinedOutput = new byte[_ciphertext.length + tag.length];
        byte[] _commonBacking = new byte[_plaintext.length + _combinedOutput.length];

        assertEquals("Provider " + p.getName()
                        + ", algorithm " + transformation
                        + " reported the wrong output size",
                _combinedOutput.length, cipher.getOutputSize(_plaintext.length));
        System.arraycopy(_ciphertext, 0, _combinedOutput, 0, _ciphertext.length);
        System.arraycopy(tag, 0, _combinedOutput, _ciphertext.length, tag.length);
        System.arraycopy(_plaintext, 0, _commonBacking, 0, _plaintext.length);
        System.arraycopy(_combinedOutput, 0, _commonBacking, _plaintext.length, _combinedOutput.length);
        ByteBuffer combinedOutput = ByteBuffer.wrap(_commonBacking);
        ByteBuffer plaintext = combinedOutput.slice();
        plaintext.limit(_plaintext.length);
        combinedOutput.position(_plaintext.length);
        // both byte buffers have been created from common backed array and have correct respecting positions and limits

        combinedOutput.position(combinedOutput.limit());
        ByteBuffer outputbuffer = ByteBuffer.allocate(cipher.getOutputSize(plaintext.remaining()));

        cipher.doFinal(plaintext, outputbuffer);
        assertEquals("Cipher doFinal did not encrypt correctly", combinedOutput, outputbuffer);
        assertEquals(" input was not shifted", plaintext.position(), plaintext.limit());

        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(_combinedOutput.length));
        combinedOutput.position(_plaintext.length);

        outputbuffer = ByteBuffer.allocate(cipher.getOutputSize(combinedOutput.remaining()));

        combinedOutput.position(_plaintext.length);
        plaintext.position(plaintext.limit());
        cipher.doFinal(combinedOutput, outputbuffer);
        assertEquals("Cipher doFinal did not decrypt correctly", plaintext, outputbuffer);
        assertEquals(" input was not shifted", combinedOutput.position(), combinedOutput.limit());
    }
Calls an initialized cipher with different equivalent call patterns.
common/src/test/java/org/conscrypt/javax/crypto/CipherBasicsTest.java