use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class JsonKeysetReaderTest method testReadKeyset_negativeKeyId_works.
@Test
public void testReadKeyset_negativeKeyId_works() throws Exception {
String jsonKeysetString = createJsonKeysetWithId("-21");
Keyset keyset = JsonKeysetReader.withString(jsonKeysetString).read();
assertThat(keyset.getPrimaryKeyId()).isEqualTo(-21);
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class UtilTest method testValidateKeyset_multiplePrimaryKeys_shouldFail.
@Test
public void testValidateKeyset_multiplePrimaryKeys_shouldFail() throws Exception {
String keyValue = "01234567890123456";
// Multiple primary keys.
Keyset invalidKeyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK), TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK));
GeneralSecurityException e = assertThrows(GeneralSecurityException.class, () -> Util.validateKeyset(invalidKeyset));
assertExceptionContains(e, "keyset contains multiple primary keys");
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class UtilTest method testValidateKeyset_withDestroyedKey_shouldWork.
@Test
public void testValidateKeyset_withDestroyedKey_shouldWork() throws Exception {
String keyValue = "01234567890123456";
Keyset validKeyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK), TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16), 42, KeyStatusType.DESTROYED, OutputPrefixType.TINK));
try {
Util.validateKeyset(validKeyset);
} catch (GeneralSecurityException e) {
fail("Valid keyset, should not fail: " + e);
}
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class UtilTest method testValidateKeyset_shouldWork.
@Test
public void testValidateKeyset_shouldWork() throws Exception {
String keyValue = "01234567890123456";
Keyset keyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16), -42, KeyStatusType.ENABLED, OutputPrefixType.TINK));
try {
Util.validateKeyset(keyset);
} catch (GeneralSecurityException e) {
fail("Valid keyset; should not throw Exception: " + e);
}
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class KeysetManagerTest method testRotate_shouldAddNewKeyAndSetPrimaryKeyId.
@Test
public void testRotate_shouldAddNewKeyAndSetPrimaryKeyId() throws Exception {
// Create a keyset that contains a single HmacKey.
KeyTemplate template = KeyTemplates.get("HMAC_SHA256_128BITTAG");
// Need to test the deprecated function
@SuppressWarnings("deprecation") Keyset keyset = KeysetManager.withEmptyKeyset().rotate(template.getProto()).getKeysetHandle().getKeyset();
assertThat(keyset.getKeyCount()).isEqualTo(1);
assertThat(keyset.getPrimaryKeyId()).isEqualTo(keyset.getKey(0).getKeyId());
TestUtil.assertHmacKey(template, keyset.getKey(0));
}
Aggregations