use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.
the class HybridConfigTest 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("tinkhybridencrypt");
fail("Expected GeneralSecurityException");
} catch (GeneralSecurityException e) {
assertThat(e.toString()).contains("no catalogue found");
assertThat(e.toString()).contains("HybridConfig.init()");
}
try {
Registry.getCatalogue("tinkhybriddecrypt");
fail("Expected GeneralSecurityException");
} catch (GeneralSecurityException e) {
assertThat(e.toString()).contains("no catalogue found");
assertThat(e.toString()).contains("HybridConfig.init()");
}
// Get the config proto, now the catalogues should be present,
// as init() was triggered by a static block.
RegistryConfig unused = HybridConfig.TINK_1_1_0;
Registry.getCatalogue("tinkmac");
Registry.getCatalogue("tinkhybriddecrypt");
Registry.getCatalogue("tinkhybridencrypt");
// Running init() manually again should succeed.
HybridConfig.init();
}
use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.
the class HybridConfigTest method testConfigContents1_0_0.
@Test
public void testConfigContents1_0_0() throws Exception {
RegistryConfig config = HybridConfig.TINK_1_0_0;
assertEquals(9, config.getEntryCount());
assertEquals("TINK_HYBRID_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);
}
use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.
the class HybridConfigTest method testConfigContents1_1_0.
@Test
public void testConfigContents1_1_0() throws Exception {
RegistryConfig config = HybridConfig.TINK_1_1_0;
assertEquals(9, config.getEntryCount());
assertEquals("TINK_HYBRID_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);
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);
}
use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.
the class HybridDecryptCatalogueTest method testBasic.
@Test
public void testBasic() throws Exception {
HybridDecryptCatalogue catalogue = new HybridDecryptCatalogue();
// Check a single key type for decryption, incl. case-insensitve primitive name.
String keyType = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey";
{
KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(keyType, "HybridDecrypt", 0);
assertThat(manager.doesSupport(keyType)).isTrue();
}
{
KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(keyType, "HyBRidDeCRYPt", 0);
assertThat(manager.doesSupport(keyType)).isTrue();
}
{
KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(keyType, "HYBRIDDecRYPT", 0);
assertThat(manager.doesSupport(keyType)).isTrue();
}
// Check all entries from the current HybridConfig.
RegistryConfig config = HybridConfig.TINK_1_0_0;
int count = 0;
for (KeyTypeEntry entry : config.getEntryList()) {
if ("HybridDecrypt".equals(entry.getPrimitiveName())) {
count = count + 1;
KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(entry.getTypeUrl(), "hybriddecrypt", entry.getKeyManagerVersion());
assertThat(manager.doesSupport(entry.getTypeUrl())).isTrue();
}
}
assertEquals(1, count);
}
use of com.google.crypto.tink.proto.RegistryConfig in project tink by google.
the class HybridEncryptCatalogueTest method testBasic.
@Test
public void testBasic() throws Exception {
HybridEncryptCatalogue catalogue = new HybridEncryptCatalogue();
// Check a single key type for encryption, incl. case-insensitve primitive name.
String keyType = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPublicKey";
{
KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(keyType, "HybridEncrypt", 0);
assertThat(manager.doesSupport(keyType)).isTrue();
}
{
KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(keyType, "HybRIdEncRYPt", 0);
assertThat(manager.doesSupport(keyType)).isTrue();
}
{
KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(keyType, "HYBRIdeNCRYPT", 0);
assertThat(manager.doesSupport(keyType)).isTrue();
}
// Check all entries from the current HybridConfig.
RegistryConfig config = HybridConfig.TINK_1_0_0;
int count = 0;
for (KeyTypeEntry entry : config.getEntryList()) {
if ("HybridEncrypt".equals(entry.getPrimitiveName())) {
count = count + 1;
KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(entry.getTypeUrl(), "hybridencrypt", entry.getKeyManagerVersion());
assertThat(manager.doesSupport(entry.getTypeUrl())).isTrue();
}
}
assertEquals(1, count);
}
Aggregations