test_class.declarator: AES_KEY_SIZE = 16
test_class.modifier: private static final
test_class.original_string: private static final int AES_KEY_SIZE = 16;
test_class.type: int
test_class.var_name: AES_KEY_SIZE
test_class.declarator: HMAC_KEY_SIZE = 20
test_class.modifier: private static final
test_class.original_string: private static final int HMAC_KEY_SIZE = 20;
test_class.type: int
test_class.var_name: HMAC_KEY_SIZE
test_class.file: java_src/src/test/java/com/google/crypto/tink/aead/AeadFactoryTest.java
test_class.identifier: AeadFactoryTest
test_case.body: @Test
    public void testMultipleKeys() throws Exception {
      byte[] aesCtrKeyValue = Random.randBytes(AES_KEY_SIZE);
      byte[] hmacKeyValue = Random.randBytes(HMAC_KEY_SIZE);
      int ivSize = 12;
      int tagSize = 16;
  
      Key primary =
          TestUtil.createKey(
              TestUtil.createAesCtrHmacAeadKeyData(aesCtrKeyValue, ivSize, hmacKeyValue, tagSize),
              42,
              KeyStatusType.ENABLED,
              OutputPrefixType.TINK);
      Key raw =
          TestUtil.createKey(
              TestUtil.createAesCtrHmacAeadKeyData(aesCtrKeyValue, ivSize, hmacKeyValue, tagSize),
              43,
              KeyStatusType.ENABLED,
              OutputPrefixType.RAW);
      Key legacy =
          TestUtil.createKey(
              TestUtil.createAesCtrHmacAeadKeyData(aesCtrKeyValue, ivSize, hmacKeyValue, tagSize),
              44,
              KeyStatusType.ENABLED,
              OutputPrefixType.LEGACY);
  
      Key tink =
          TestUtil.createKey(
              TestUtil.createAesCtrHmacAeadKeyData(aesCtrKeyValue, ivSize, hmacKeyValue, tagSize),
              45,
              KeyStatusType.ENABLED,
              OutputPrefixType.TINK);
  
      KeysetHandle keysetHandle =
          TestUtil.createKeysetHandle(TestUtil.createKeyset(primary, raw, legacy, tink));
      Aead aead = keysetHandle.getPrimitive(Aead.class);
      byte[] plaintext = Random.randBytes(20);
      byte[] associatedData = Random.randBytes(20);
      byte[] ciphertext = aead.encrypt(plaintext, associatedData);
      byte[] prefix = Arrays.copyOfRange(ciphertext, 0, CryptoFormat.NON_RAW_PREFIX_SIZE);
  
      assertArrayEquals(prefix, CryptoFormat.getOutputPrefix(primary));
      assertArrayEquals(plaintext, aead.decrypt(ciphertext, associatedData));
      assertEquals(
          CryptoFormat.NON_RAW_PREFIX_SIZE + plaintext.length + ivSize + tagSize, ciphertext.length);
  
      // encrypt with a non-primary RAW key and decrypt with the keyset
      KeysetHandle keysetHandle2 =
          TestUtil.createKeysetHandle(TestUtil.createKeyset(raw, legacy, tink));
      Aead aead2 = keysetHandle2.getPrimitive(Aead.class);
      ciphertext = aead2.encrypt(plaintext, associatedData);
      assertArrayEquals(plaintext, aead.decrypt(ciphertext, associatedData));
  
      // encrypt with a random key not in the keyset, decrypt with the keyset should fail
      byte[] aesCtrKeyValue2 = Random.randBytes(AES_KEY_SIZE);
      byte[] hmacKeyValue2 = Random.randBytes(HMAC_KEY_SIZE);
      Key random =
          TestUtil.createKey(
              TestUtil.createAesCtrHmacAeadKeyData(aesCtrKeyValue2, ivSize, hmacKeyValue2, tagSize),
              44,
              KeyStatusType.ENABLED,
              OutputPrefixType.TINK);
      keysetHandle2 = TestUtil.createKeysetHandle(TestUtil.createKeyset(random));
      aead2 = keysetHandle2.getPrimitive(Aead.class);
      ciphertext = aead2.encrypt(plaintext, associatedData);
      try {
        aead.decrypt(ciphertext, associatedData);
        fail("Expected GeneralSecurityException");
      } catch (GeneralSecurityException e) {
        assertExceptionContains(e, "decryption failed");
      }
    }
test_case.class_method_signature: AeadFactoryTest.testMultipleKeys()
test_case.full_signature: @Test public void testMultipleKeys()
test_case.identifier: testMultipleKeys
test_case.invocations: randBytes randBytes createKey createAesCtrHmacAeadKeyData createKey createAesCtrHmacAeadKeyData createKey createAesCtrHmacAeadKeyData createKey createAesCtrHmacAeadKeyData createKeysetHandle createKeyset getPrimitive randBytes randBytes encrypt copyOfRange assertArrayEquals getOutputPrefix assertArrayEquals decrypt assertEquals createKeysetHandle createKeyset getPrimitive encrypt assertArrayEquals decrypt randBytes randBytes createKey createAesCtrHmacAeadKeyData createKeysetHandle createKeyset getPrimitive encrypt decrypt fail assertExceptionContains
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMultipleKeys()
focal_class.file: java_src/src/main/java/com/google/crypto/tink/aead/AeadFactory.java
focal_class.identifier: AeadFactory
focal_class.class_method_signature: AeadFactory.getPrimitive(KeysetHandle keysetHandle)
focal_class.full_signature: @Deprecated public static Aead getPrimitive(KeysetHandle keysetHandle)
focal_class.identifier: getPrimitive
focal_class.modifiers: @Deprecated public static
focal_class.parameters: (KeysetHandle keysetHandle)
focal_class.return: Aead
focal_class.signature: Aead getPrimitive(KeysetHandle keysetHandle)
focal_class.class_method_signature: AeadFactory.getPrimitive(KeysetHandle keysetHandle, final KeyManager<Aead> keyManager)
focal_class.full_signature: @Deprecated public static Aead getPrimitive(KeysetHandle keysetHandle, final KeyManager<Aead> keyManager)
focal_class.identifier: getPrimitive
focal_class.modifiers: @Deprecated public static
focal_class.parameters: (KeysetHandle keysetHandle, final KeyManager<Aead> keyManager)
focal_class.return: Aead
focal_class.signature: Aead getPrimitive(KeysetHandle keysetHandle, final KeyManager<Aead> keyManager)
focal_method.body: @Deprecated
    public static Aead getPrimitive(KeysetHandle keysetHandle) throws GeneralSecurityException {
      return getPrimitive(keysetHandle, /* keyManager= */ null);
    }
focal_method.class_method_signature: AeadFactory.getPrimitive(KeysetHandle keysetHandle)
focal_method.full_signature: @Deprecated public static Aead getPrimitive(KeysetHandle keysetHandle)
focal_method.identifier: getPrimitive
focal_method.invocations: getPrimitive
focal_method.modifiers: @Deprecated public static
focal_method.parameters: (KeysetHandle keysetHandle)
focal_method.return: Aead
focal_method.signature: Aead getPrimitive(KeysetHandle keysetHandle)