Search in sources :

Example 21 with RegistryConfig

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

the class StreamingAeadConfigTest method aaaTestInitialization.

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

Example 22 with RegistryConfig

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

the class AeadCatalogueTest method testBasic.

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

Example 23 with RegistryConfig

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

the class AeadConfigTest method aaaTestInitialization.

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

Example 24 with RegistryConfig

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

the class MacCatalogueTest method testBasic.

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

Example 25 with RegistryConfig

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

the class MacConfigTest method aaaTestInitialization.

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