test_class.declarator: UTF_8 = Charset.forName("UTF-8")
test_class.modifier: private static final
test_class.original_string: private static final Charset UTF_8 = Charset.forName("UTF-8");
test_class.type: Charset
test_class.var_name: UTF_8
test_class.declarator: keyTemplates
test_class.modifier: private
test_class.original_string: private KeyTemplate[] keyTemplates;
test_class.type: KeyTemplate[]
test_class.var_name: keyTemplates
test_class.file: java_src/src/test/java/com/google/crypto/tink/hybrid/RegistryEciesAeadHkdfDemHelperTest.java
test_class.identifier: RegistryEciesAeadHkdfDemHelperTest
test_case.body: @Test
    public void testGetAead() throws Exception {
      byte[] plaintext = "some plaintext string".getBytes(UTF_8);
      byte[] associatedData = "some associated data".getBytes(UTF_8);
      int count = 0;
      for (KeyTemplate template : keyTemplates) {
        RegistryEciesAeadHkdfDemHelper helper = new RegistryEciesAeadHkdfDemHelper(template);
        byte[] symmetricKey = Random.randBytes(helper.getSymmetricKeySizeInBytes());
        Aead aead = helper.getAead(symmetricKey);
        byte[] ciphertext = aead.encrypt(plaintext, associatedData);
        byte[] decrypted = aead.decrypt(ciphertext, associatedData);
        assertArrayEquals(plaintext, decrypted);
  
        // Try using a symmetric key that is too short.
        symmetricKey = Random.randBytes(helper.getSymmetricKeySizeInBytes() - 1);
        try {
          aead = helper.getAead(symmetricKey);
          fail("Symmetric key too short, should have thrown exception:\n" + template.toString());
        } catch (GeneralSecurityException e) {
          // Expected.
          assertExceptionContains(e, "incorrect length");
        }
  
        // Try using a symmetric key that is too long.
        symmetricKey = Random.randBytes(helper.getSymmetricKeySizeInBytes() + 1);
        try {
          aead = helper.getAead(symmetricKey);
          fail("Symmetric key too long, should have thrown exception:\n" + template.toString());
        } catch (GeneralSecurityException e) {
          // Expected.
          assertExceptionContains(e, "incorrect length");
        }
        count++;
      }
      assertEquals(keyTemplates.length, count);
    }
test_case.class_method_signature: RegistryEciesAeadHkdfDemHelperTest.testGetAead()
test_case.full_signature: @Test public void testGetAead()
test_case.identifier: testGetAead
test_case.invocations: getBytes getBytes randBytes getSymmetricKeySizeInBytes getAead encrypt decrypt assertArrayEquals randBytes getSymmetricKeySizeInBytes getAead fail toString assertExceptionContains randBytes getSymmetricKeySizeInBytes getAead fail toString assertExceptionContains assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetAead()
focal_class.declarator: demKeyTypeUrl
focal_class.modifier: private final
focal_class.original_string: private final String demKeyTypeUrl;
focal_class.type: String
focal_class.var_name: demKeyTypeUrl
focal_class.declarator: symmetricKeySize
focal_class.modifier: private final
focal_class.original_string: private final int symmetricKeySize;
focal_class.type: int
focal_class.var_name: symmetricKeySize
focal_class.declarator: aesGcmKey
focal_class.modifier: private
focal_class.original_string: private AesGcmKey aesGcmKey;
focal_class.type: AesGcmKey
focal_class.var_name: aesGcmKey
focal_class.declarator: aesCtrHmacAeadKey
focal_class.modifier: private
focal_class.original_string: private AesCtrHmacAeadKey aesCtrHmacAeadKey;
focal_class.type: AesCtrHmacAeadKey
focal_class.var_name: aesCtrHmacAeadKey
focal_class.declarator: aesCtrKeySize
focal_class.modifier: private
focal_class.original_string: private int aesCtrKeySize;
focal_class.type: int
focal_class.var_name: aesCtrKeySize
focal_class.file: java_src/src/main/java/com/google/crypto/tink/hybrid/RegistryEciesAeadHkdfDemHelper.java
focal_class.identifier: RegistryEciesAeadHkdfDemHelper
focal_class.interfaces: implements EciesAeadHkdfDemHelper
focal_class.class_method_signature: RegistryEciesAeadHkdfDemHelper.RegistryEciesAeadHkdfDemHelper(KeyTemplate demTemplate)
focal_class.full_signature:   RegistryEciesAeadHkdfDemHelper(KeyTemplate demTemplate)
focal_class.identifier: RegistryEciesAeadHkdfDemHelper
focal_class.parameters: (KeyTemplate demTemplate)
focal_class.signature:  RegistryEciesAeadHkdfDemHelper(KeyTemplate demTemplate)
focal_class.class_method_signature: RegistryEciesAeadHkdfDemHelper.getSymmetricKeySizeInBytes()
focal_class.full_signature: @Override public int getSymmetricKeySizeInBytes()
focal_class.identifier: getSymmetricKeySizeInBytes
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getSymmetricKeySizeInBytes()
focal_class.class_method_signature: RegistryEciesAeadHkdfDemHelper.getAead(final byte[] symmetricKeyValue)
focal_class.full_signature: @Override public Aead getAead(final byte[] symmetricKeyValue)
focal_class.identifier: getAead
focal_class.modifiers: @Override public
focal_class.parameters: (final byte[] symmetricKeyValue)
focal_class.return: Aead
focal_class.signature: Aead getAead(final byte[] symmetricKeyValue)
focal_method.body: @Override
    public Aead getAead(final byte[] symmetricKeyValue) throws GeneralSecurityException {
      if (symmetricKeyValue.length != getSymmetricKeySizeInBytes()) {
        throw new GeneralSecurityException("Symmetric key has incorrect length");
      }
      if (demKeyTypeUrl.equals(AeadConfig.AES_GCM_TYPE_URL)) {
        AesGcmKey aeadKey = AesGcmKey.newBuilder()
            .mergeFrom(aesGcmKey)
            .setKeyValue(ByteString.copyFrom(symmetricKeyValue, 0, symmetricKeySize))
            .build();
        return Registry.getPrimitive(demKeyTypeUrl, aeadKey, Aead.class);
      } else if (demKeyTypeUrl.equals(AeadConfig.AES_CTR_HMAC_AEAD_TYPE_URL)) {
        byte[] aesCtrKeyValue = Arrays.copyOfRange(symmetricKeyValue, 0, aesCtrKeySize);
        byte[] hmacKeyValue = Arrays.copyOfRange(symmetricKeyValue, aesCtrKeySize, symmetricKeySize);
        AesCtrKey aesCtrKey =
            AesCtrKey.newBuilder()
                .mergeFrom(aesCtrHmacAeadKey.getAesCtrKey())
                .setKeyValue(ByteString.copyFrom(aesCtrKeyValue))
                .build();
        HmacKey hmacKey =
            HmacKey.newBuilder()
                .mergeFrom(aesCtrHmacAeadKey.getHmacKey())
                .setKeyValue(ByteString.copyFrom(hmacKeyValue))
                .build();
        AesCtrHmacAeadKey aeadKey =
            AesCtrHmacAeadKey.newBuilder()
                .setVersion(aesCtrHmacAeadKey.getVersion())
                .setAesCtrKey(aesCtrKey)
                .setHmacKey(hmacKey)
                .build();
        return Registry.getPrimitive(demKeyTypeUrl, aeadKey, Aead.class);
      } else {
        throw new GeneralSecurityException("unknown DEM key type");
      }
    }
focal_method.class_method_signature: RegistryEciesAeadHkdfDemHelper.getAead(final byte[] symmetricKeyValue)
focal_method.full_signature: @Override public Aead getAead(final byte[] symmetricKeyValue)
focal_method.identifier: getAead
focal_method.invocations: getSymmetricKeySizeInBytes equals build setKeyValue mergeFrom newBuilder copyFrom getPrimitive equals copyOfRange copyOfRange build setKeyValue mergeFrom newBuilder getAesCtrKey copyFrom build setKeyValue mergeFrom newBuilder getHmacKey copyFrom build setHmacKey setAesCtrKey setVersion newBuilder getVersion getPrimitive
focal_method.modifiers: @Override public
focal_method.parameters: (final byte[] symmetricKeyValue)
focal_method.return: Aead
focal_method.signature: Aead getAead(final byte[] symmetricKeyValue)