Search in sources :

Example 6 with KeyManager

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

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

use of com.google.crypto.tink.KeyManager 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)

Aggregations

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