Search in sources :

Example 76 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_differentKeyIdButRawOutputPrefix_throws.

@Test
public void testCompareKeysets_differentKeyIdButRawOutputPrefix_throws() throws Exception {
    Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 18, KeyStatusType.ENABLED, OutputPrefixType.RAW)).setPrimaryKeyId(18).build();
    Keyset keyset2 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.RAW)).setPrimaryKeyId(17).build();
    try {
        CompareKeysets.compareKeysets(keyset1, keyset2);
        fail();
    } catch (Exception e) {
    // expected.
    }
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Example 77 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_singleKeyDifferentOutputPrefix_throws.

@Test
public void testCompareKeysets_singleKeyDifferentOutputPrefix_throws() throws Exception {
    Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    Keyset keyset2 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.RAW)).setPrimaryKeyId(17).build();
    try {
        CompareKeysets.compareKeysets(keyset1, keyset2);
        fail();
    } catch (Exception e) {
    // expected.
    }
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Example 78 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_twoKeysDifferentOrder_equal.

@Test
public void testCompareKeysets_twoKeysDifferentOrder_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_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    CompareKeysets.compareKeysets(keyset1, keyset2);
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Example 79 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_differentKeysSameIdsSimlarOrder_throws.

@Test
public void testCompareKeysets_differentKeysSameIdsSimlarOrder_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)).addKey(aesGcmKey(KEY_2, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_3, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_4, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_5, 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)).addKey(aesGcmKey(KEY_2, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(// != KEY_3
    aesGcmKey(KEY_6, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_4, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_5, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    try {
        CompareKeysets.compareKeysets(keyset1, keyset2);
        fail();
    } catch (Exception e) {
    // expected.
    }
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Example 80 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_singleKey_equal.

@Test
public void testCompareKeysets_singleKey_equal() throws Exception {
    Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    Keyset keyset2 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    CompareKeysets.compareKeysets(keyset1, keyset2);
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Aggregations

Keyset (com.google.crypto.tink.proto.Keyset)108 Test (org.junit.Test)81 GeneralSecurityException (java.security.GeneralSecurityException)22 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)17 KeysetHandle (com.google.crypto.tink.KeysetHandle)17 KeyData (com.google.crypto.tink.proto.KeyData)17 KeyTemplate (com.google.crypto.tink.KeyTemplate)12 EncryptedKeyset (com.google.crypto.tink.proto.EncryptedKeyset)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ByteString (com.google.protobuf.ByteString)10 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)10 Key (com.google.crypto.tink.proto.Keyset.Key)9 JsonObject (com.google.gson.JsonObject)9 AesGcmKey (com.google.crypto.tink.proto.AesGcmKey)8 KeysetReader (com.google.crypto.tink.KeysetReader)7 IOException (java.io.IOException)7 AesEaxKey (com.google.crypto.tink.proto.AesEaxKey)6 AesGcmKeyFormat (com.google.crypto.tink.proto.AesGcmKeyFormat)6 Enums (com.google.crypto.tink.subtle.Enums)6 KeyHandle (com.google.crypto.tink.tinkkey.KeyHandle)6