Search in sources :

Example 6 with RegistryConfig

use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.

the class DeterministicAeadCatalogueTest method testBasic.

@Test
public void testBasic() throws Exception {
    DeterministicAeadCatalogue catalogue = new DeterministicAeadCatalogue();
    // Check a single key type, incl. case-insensitve primitive name.
    String keyType = "type.googleapis.com/google.crypto.tink.AesSivKey";
    {
        KeyManager<DeterministicAead> manager = catalogue.getKeyManager(keyType, "DeterministicAead", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<DeterministicAead> manager = catalogue.getKeyManager(keyType, "DeterministicAEaD", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<DeterministicAead> manager = catalogue.getKeyManager(keyType, "dEtermInisticaeAD", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    // Check all entries from the current DeterministicAeadConfig.
    RegistryConfig config = DeterministicAeadConfig.TINK_1_1_0;
    int count = 0;
    for (KeyTypeEntry entry : config.getEntryList()) {
        if ("DeterministicAead".equals(entry.getPrimitiveName())) {
            count = count + 1;
            KeyManager<DeterministicAead> manager = catalogue.getKeyManager(entry.getTypeUrl(), "deterministicaead", entry.getKeyManagerVersion());
            assertThat(manager.doesSupport(entry.getTypeUrl())).isTrue();
        }
    }
    assertEquals(1, count);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) DeterministicAead(com.google.crypto.tink.DeterministicAead) KeyTypeEntry(com.google.crypto.tink.proto.KeyTypeEntry) KeyManager(com.google.crypto.tink.KeyManager) Test(org.junit.Test)

Example 7 with RegistryConfig

use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.

the class DeterministicAeadConfigTest method testConfigContents.

@Test
public void testConfigContents() throws Exception {
    RegistryConfig config = DeterministicAeadConfig.TINK_1_1_0;
    assertEquals(1, config.getEntryCount());
    assertEquals("TINK_DETERMINISTIC_AEAD_1_1_0", config.getConfigName());
    TestUtil.verifyConfigEntry(config.getEntry(0), "TinkDeterministicAead", "DeterministicAead", "type.googleapis.com/google.crypto.tink.AesSivKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) Test(org.junit.Test)

Example 8 with RegistryConfig

use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.

the class DeterministicAeadConfigTest method aaaTestInitialization.

// This test must run first.
@Test
public void aaaTestInitialization() throws Exception {
    try {
        Registry.getCatalogue("tinkdeterministicaead");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("DeterministicAeadConfig.init()");
    }
    // Get the config proto, now the catalogues should be present,
    // as init() was triggered by a static block.
    RegistryConfig unused = DeterministicAeadConfig.TINK_1_1_0;
    Registry.getCatalogue("tinkdeterministicaead");
    // Running init() manually again should succeed.
    DeterministicAeadConfig.init();
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) GeneralSecurityException(java.security.GeneralSecurityException) Test(org.junit.Test)

Example 9 with RegistryConfig

use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.

the class TinkConfigTest method testConfigContentsVersion1_0_0.

@Test
public void testConfigContentsVersion1_0_0() throws Exception {
    RegistryConfig config = TinkConfig.TINK_1_0_0;
    assertEquals(13, config.getEntryCount());
    assertEquals("TINK_1_0_0", config.getConfigName());
    TestUtil.verifyConfigEntry(config.getEntry(0), "TinkMac", "Mac", "type.googleapis.com/google.crypto.tink.HmacKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(1), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(2), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesEaxKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(3), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesGcmKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(4), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.ChaCha20Poly1305Key", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(5), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(6), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsEnvelopeAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(7), "TinkHybridDecrypt", "HybridDecrypt", "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(8), "TinkHybridEncrypt", "HybridEncrypt", "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPublicKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(9), "TinkPublicKeySign", "PublicKeySign", "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(10), "TinkPublicKeySign", "PublicKeySign", "type.googleapis.com/google.crypto.tink.Ed25519PrivateKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(11), "TinkPublicKeyVerify", "PublicKeyVerify", "type.googleapis.com/google.crypto.tink.EcdsaPublicKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(12), "TinkPublicKeyVerify", "PublicKeyVerify", "type.googleapis.com/google.crypto.tink.Ed25519PublicKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) Test(org.junit.Test)

Example 10 with RegistryConfig

use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.

the class AeadConfigTest method testConfigContents1_1_0.

@Test
public void testConfigContents1_1_0() throws Exception {
    RegistryConfig config = AeadConfig.TINK_1_1_0;
    assertEquals(7, config.getEntryCount());
    assertEquals("TINK_AEAD_1_1_0", config.getConfigName());
    TestUtil.verifyConfigEntry(config.getEntry(0), "TinkMac", "Mac", "type.googleapis.com/google.crypto.tink.HmacKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(1), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(2), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesEaxKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(3), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesGcmKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(4), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.ChaCha20Poly1305Key", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(5), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(6), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsEnvelopeAeadKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) Test(org.junit.Test)

Aggregations

RegistryConfig (com.google.crypto.tink.proto.RegistryConfig)27 Test (org.junit.Test)27 KeyManager (com.google.crypto.tink.KeyManager)8 KeyTypeEntry (com.google.crypto.tink.proto.KeyTypeEntry)8 GeneralSecurityException (java.security.GeneralSecurityException)7 Aead (com.google.crypto.tink.Aead)1 DeterministicAead (com.google.crypto.tink.DeterministicAead)1 HybridDecrypt (com.google.crypto.tink.HybridDecrypt)1 HybridEncrypt (com.google.crypto.tink.HybridEncrypt)1 Mac (com.google.crypto.tink.Mac)1 PublicKeySign (com.google.crypto.tink.PublicKeySign)1 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)1 StreamingAead (com.google.crypto.tink.StreamingAead)1