Search in sources :

Example 6 with KeyTypeEntry

use of com.google.crypto.tink.proto.KeyTypeEntry 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 7 with KeyTypeEntry

use of com.google.crypto.tink.proto.KeyTypeEntry 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 8 with KeyTypeEntry

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

the class PublicKeyVerifyCatalogueTest method testBasic.

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

Example 9 with KeyTypeEntry

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

the class PublicKeySignCatalogueTest method testBasic.

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

Example 10 with KeyTypeEntry

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

the class ConfigTest method testRegisterKeyType_noCatalogue_shouldThrowException.

@Test
public void testRegisterKeyType_noCatalogue_shouldThrowException() throws Exception {
    KeyTypeEntry entry = KeyTypeEntry.newBuilder().setCatalogueName("DoesNotExist").build();
    assertThrows(GeneralSecurityException.class, () -> Config.registerKeyType(entry));
}
Also used : KeyTypeEntry(com.google.crypto.tink.proto.KeyTypeEntry) Test(org.junit.Test)

Aggregations

KeyTypeEntry (com.google.crypto.tink.proto.KeyTypeEntry)10 Test (org.junit.Test)10 KeyManager (com.google.crypto.tink.KeyManager)8 RegistryConfig (com.google.crypto.tink.proto.RegistryConfig)8 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 GeneralSecurityException (java.security.GeneralSecurityException)1