use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class CompareKeysetsTest method testCompareKeysets_twoKeys_equal.
@Test
public void testCompareKeysets_twoKeys_equal() throws Exception {
Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
Keyset keyset2 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
CompareKeysets.compareKeysets(keyset1, keyset2);
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class CompareKeysetsTest method testCompareKeysets_twoKeysDifferentPrimary_throws.
@Test
public void testCompareKeysets_twoKeysDifferentPrimary_throws() throws Exception {
Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
Keyset keyset2 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(18).build();
try {
CompareKeysets.compareKeysets(keyset1, keyset2);
fail();
} catch (Exception e) {
// expected.
}
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class CompareKeysetsTest method testCompareKeysets_singleKeyDifferentKeyMaterial_throws.
@Test
public void testCompareKeysets_singleKeyDifferentKeyMaterial_throws() throws Exception {
Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
Keyset.Key key = keyset1.getKey(0);
Keyset keyset2 = Keyset.newBuilder().addKey(Keyset.Key.newBuilder(key).setKeyData(KeyData.newBuilder(key.getKeyData()).setKeyMaterialType(KeyMaterialType.UNKNOWN_KEYMATERIAL))).setPrimaryKeyId(17).build();
try {
CompareKeysets.compareKeysets(keyset1, keyset2);
fail();
} catch (Exception e) {
// expected.
}
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class RotateKeysetCommandTest method testRotateCleartext_shouldAddNewKey.
@Test
public void testRotateCleartext_shouldAddNewKey() throws Exception {
// Create an input stream containing a cleartext keyset.
String masterKeyUri = null;
String credentialPath = null;
InputStream inputStream = TinkeyUtil.createKeyset(existingTemplate, INPUT_FORMAT, masterKeyUri, credentialPath);
// Add a new key to the existing keyset.
Keyset keyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, newTemplate).read();
assertThat(keyset.getKeyCount()).isEqualTo(2);
assertThat(keyset.getPrimaryKeyId()).isEqualTo(keyset.getKey(1).getKeyId());
TestUtil.assertHmacKey(existingTemplate, keyset.getKey(0));
TestUtil.assertHmacKey(newTemplate, keyset.getKey(1));
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class AddKeyCommandTest method testAddCleartext_shouldAddNewKey.
@Test
public void testAddCleartext_shouldAddNewKey() throws Exception {
// Create an input stream containing a cleartext keyset.
String masterKeyUri = null;
String credentialPath = null;
InputStream inputStream = TinkeyUtil.createKeyset(existingTemplate, INPUT_FORMAT, masterKeyUri, credentialPath);
// Add a new key to the existing keyset.
Keyset keyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, newTemplate).read();
assertThat(keyset.getKeyCount()).isEqualTo(2);
assertThat(keyset.getPrimaryKeyId()).isEqualTo(keyset.getKey(0).getKeyId());
TestUtil.assertHmacKey(existingTemplate, keyset.getKey(0));
TestUtil.assertHmacKey(newTemplate, keyset.getKey(1));
}
Aggregations