From 9e3341b7a230eddb69ee91c34f4d588ae186044d Mon Sep 17 00:00:00 2001 From: Moreno Ambrosin Date: Mon, 25 Nov 2024 04:52:02 -0800 Subject: [PATCH] Rename `newXYZ` test helper functions in signature/rsassapkcs1 to `mustCreateXYZ` PiperOrigin-RevId: 699939084 Change-Id: Ib711ebbf4bb7adf59a3cf37208c0289a9dd97a86 --- signature/rsassapkcs1/key_test.go | 48 ++-- .../rsassapkcs1/protoserialization_test.go | 228 +++++++++--------- signature/rsassapkcs1/signer_verifier_test.go | 12 +- 3 files changed, 144 insertions(+), 144 deletions(-) diff --git a/signature/rsassapkcs1/key_test.go b/signature/rsassapkcs1/key_test.go index 6e44bb3..a7f4dbf 100644 --- a/signature/rsassapkcs1/key_test.go +++ b/signature/rsassapkcs1/key_test.go @@ -440,32 +440,32 @@ func TestNewPublicKeyMinMaxValues(t *testing.T) { { name: "min module 2048 bit", module: minModulus2048.Bytes(), - params: newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink), + params: mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink), }, { name: "max module 2048 bit", module: maxModulus2048.Bytes(), - params: newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink), + params: mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink), }, { name: "min module 3072 bit", module: minModulus3072.Bytes(), - params: newParameters(t, 3072, rsassapkcs1.SHA384, f4, rsassapkcs1.VariantTink), + params: mustCreateParameters(t, 3072, rsassapkcs1.SHA384, f4, rsassapkcs1.VariantTink), }, { name: "max module 3072 bit", module: maxModulus3072.Bytes(), - params: newParameters(t, 3072, rsassapkcs1.SHA384, f4, rsassapkcs1.VariantTink), + params: mustCreateParameters(t, 3072, rsassapkcs1.SHA384, f4, rsassapkcs1.VariantTink), }, { name: "min module 4096 bit", module: minModulus4096.Bytes(), - params: newParameters(t, 4096, rsassapkcs1.SHA512, f4, rsassapkcs1.VariantTink), + params: mustCreateParameters(t, 4096, rsassapkcs1.SHA512, f4, rsassapkcs1.VariantTink), }, { name: "max module 4096 bit", module: maxModulus4096.Bytes(), - params: newParameters(t, 4096, rsassapkcs1.SHA512, f4, rsassapkcs1.VariantTink), + params: mustCreateParameters(t, 4096, rsassapkcs1.SHA512, f4, rsassapkcs1.VariantTink), }, } { t.Run(tc.name, func(t *testing.T) { @@ -476,7 +476,7 @@ func TestNewPublicKeyMinMaxValues(t *testing.T) { } } -func newParameters(t *testing.T, modulusSizeBits int, hashType rsassapkcs1.HashType, publicExponent int, variant rsassapkcs1.Variant) *rsassapkcs1.Parameters { +func mustCreateParameters(t *testing.T, modulusSizeBits int, hashType rsassapkcs1.HashType, publicExponent int, variant rsassapkcs1.Variant) *rsassapkcs1.Parameters { t.Helper() params, err := rsassapkcs1.NewParameters(modulusSizeBits, hashType, publicExponent, variant) if err != nil { @@ -485,7 +485,7 @@ func newParameters(t *testing.T, modulusSizeBits int, hashType rsassapkcs1.HashT return params } -func newPublicKey(t *testing.T, modulus []byte, idRequirement uint32, parameters *rsassapkcs1.Parameters) *rsassapkcs1.PublicKey { +func mustCreatePublicKey(t *testing.T, modulus []byte, idRequirement uint32, parameters *rsassapkcs1.Parameters) *rsassapkcs1.PublicKey { t.Helper() key, err := rsassapkcs1.NewPublicKey(modulus, idRequirement, parameters) if err != nil { @@ -508,23 +508,23 @@ func TestNewPublicKeyEqualsFailsIfDifferentKeys(t *testing.T) { }{ { name: "different modulus", - this: newPublicKey(t, validModulus2048, 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), - that: newPublicKey(t, otherValidModulus2048, 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), + this: mustCreatePublicKey(t, validModulus2048, 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), + that: mustCreatePublicKey(t, otherValidModulus2048, 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), }, { name: "different parameters", - this: newPublicKey(t, validModulus2048, 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), - that: newPublicKey(t, validModulus2048, 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantCrunchy)), + this: mustCreatePublicKey(t, validModulus2048, 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), + that: mustCreatePublicKey(t, validModulus2048, 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantCrunchy)), }, { name: "different ID requirement", - this: newPublicKey(t, validModulus2048, 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), - that: newPublicKey(t, validModulus2048, 234, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), + this: mustCreatePublicKey(t, validModulus2048, 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), + that: mustCreatePublicKey(t, validModulus2048, 234, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), }, { name: "different modulus size", - this: newPublicKey(t, validModulus2048, 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), - that: newPublicKey(t, validModulus3072, 123, newParameters(t, 3072, rsassapkcs1.SHA384, f4, rsassapkcs1.VariantTink)), + this: mustCreatePublicKey(t, validModulus2048, 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), + that: mustCreatePublicKey(t, validModulus3072, 123, mustCreateParameters(t, 3072, rsassapkcs1.SHA384, f4, rsassapkcs1.VariantTink)), }, } { t.Run(tc.name, func(t *testing.T) { @@ -696,7 +696,7 @@ func privateKeyTestCases(t *testing.T) []privateKeyTestCase { token := insecuresecretdataaccess.Token{} testCases = append(testCases, privateKeyTestCase{ name: fmt.Sprintf("%v-%v-%v", 2048, hashType, variant), - publicKey: newPublicKey(t, base64Decode(t, n2048Base64), idRequirement, newParameters(t, 2048, hashType, f4, variant)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n2048Base64), idRequirement, mustCreateParameters(t, 2048, hashType, f4, variant)), privateKeyValues: rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), @@ -709,7 +709,7 @@ func privateKeyTestCases(t *testing.T) []privateKeyTestCase { testCases = append(testCases, privateKeyTestCase{ name: fmt.Sprintf("%v-%v-%v-android", 2048, hashType, variant), - publicKey: newPublicKey(t, setStringToBigInt(t, n2048BigInt16, 16).Bytes(), idRequirement, newParameters(t, 2048, hashType, f4, variant)), + publicKey: mustCreatePublicKey(t, setStringToBigInt(t, n2048BigInt16, 16).Bytes(), idRequirement, mustCreateParameters(t, 2048, hashType, f4, variant)), privateKeyValues: rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(setStringToBigInt(t, p2048BigInt10, 10).Bytes(), token), Q: secretdata.NewBytesFromData(setStringToBigInt(t, q2048BigInt10, 10).Bytes(), token), @@ -838,7 +838,7 @@ func TestNewPrivateKeyEqualsFailsIfKeysAreDifferent(t *testing.T) { { name: "different RSA keys", this: func() *rsassapkcs1.PrivateKey { - publicKey := newPublicKey(t, base64Decode(t, n2048Base64), 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) + publicKey := mustCreatePublicKey(t, base64Decode(t, n2048Base64), 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) privateKeyValue := rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), @@ -851,7 +851,7 @@ func TestNewPrivateKeyEqualsFailsIfKeysAreDifferent(t *testing.T) { return privateKey }(), that: func() *rsassapkcs1.PrivateKey { - publicKey := newPublicKey(t, base64Decode(t, differentN2048Base64), 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) + publicKey := mustCreatePublicKey(t, base64Decode(t, differentN2048Base64), 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) privateKeyValue := rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, differentP2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, differentQ2048Base64), token), @@ -867,7 +867,7 @@ func TestNewPrivateKeyEqualsFailsIfKeysAreDifferent(t *testing.T) { { name: "different parameters - ID requirement", this: func() *rsassapkcs1.PrivateKey { - publicKey := newPublicKey(t, base64Decode(t, n2048Base64), 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) + publicKey := mustCreatePublicKey(t, base64Decode(t, n2048Base64), 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) privateKeyValue := rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), @@ -880,7 +880,7 @@ func TestNewPrivateKeyEqualsFailsIfKeysAreDifferent(t *testing.T) { return privateKey }(), that: func() *rsassapkcs1.PrivateKey { - publicKey := newPublicKey(t, base64Decode(t, n2048Base64), 456, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) + publicKey := mustCreatePublicKey(t, base64Decode(t, n2048Base64), 456, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) privateKeyValue := rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), @@ -896,7 +896,7 @@ func TestNewPrivateKeyEqualsFailsIfKeysAreDifferent(t *testing.T) { { name: "different parameters - variant", this: func() *rsassapkcs1.PrivateKey { - publicKey := newPublicKey(t, base64Decode(t, n2048Base64), 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) + publicKey := mustCreatePublicKey(t, base64Decode(t, n2048Base64), 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)) privateKeyValue := rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), @@ -909,7 +909,7 @@ func TestNewPrivateKeyEqualsFailsIfKeysAreDifferent(t *testing.T) { return privateKey }(), that: func() *rsassapkcs1.PrivateKey { - publicKey := newPublicKey(t, base64Decode(t, n2048Base64), 123, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantCrunchy)) + publicKey := mustCreatePublicKey(t, base64Decode(t, n2048Base64), 123, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantCrunchy)) privateKeyValue := rsassapkcs1.PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), diff --git a/signature/rsassapkcs1/protoserialization_test.go b/signature/rsassapkcs1/protoserialization_test.go index 7a18dbd..6aa308a 100644 --- a/signature/rsassapkcs1/protoserialization_test.go +++ b/signature/rsassapkcs1/protoserialization_test.go @@ -72,7 +72,7 @@ func base64Decode(t *testing.T, value string) []byte { return decoded } -func newKeySerialization(t *testing.T, keyData *tinkpb.KeyData, outputPrefixType tinkpb.OutputPrefixType, idRequirement uint32) *protoserialization.KeySerialization { +func mustCreateKeySerialization(t *testing.T, keyData *tinkpb.KeyData, outputPrefixType tinkpb.OutputPrefixType, idRequirement uint32) *protoserialization.KeySerialization { t.Helper() ks, err := protoserialization.NewKeySerialization(keyData, outputPrefixType, idRequirement) if err != nil { @@ -100,11 +100,11 @@ func TestParsePublicKeyFails(t *testing.T) { }{ { name: "key data is nil", - keySerialization: newKeySerialization(t, nil, tinkpb.OutputPrefixType_TINK, 123), + keySerialization: mustCreateKeySerialization(t, nil, tinkpb.OutputPrefixType_TINK, 123), }, { name: "wrong type URL", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "invalid_type_url", Value: serializedPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, @@ -112,7 +112,7 @@ func TestParsePublicKeyFails(t *testing.T) { }, { name: "wrong key material type", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serializedPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, @@ -120,7 +120,7 @@ func TestParsePublicKeyFails(t *testing.T) { }, { name: "wrong key version", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: func() []byte { publicKey := rsassapkcs1pb.RsaSsaPkcs1PublicKey{ @@ -142,7 +142,7 @@ func TestParsePublicKeyFails(t *testing.T) { }, { name: "invalid modulus", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: func() []byte { publicKey := rsassapkcs1pb.RsaSsaPkcs1PublicKey{ @@ -164,7 +164,7 @@ func TestParsePublicKeyFails(t *testing.T) { }, { name: "invalid exponent", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: func() []byte { publicKey := rsassapkcs1pb.RsaSsaPkcs1PublicKey{ @@ -194,7 +194,7 @@ func TestParsePublicKeyFails(t *testing.T) { } } -func newParameters(t *testing.T, modulusSizeBits int, hashType HashType, publicExponent int, variant Variant) *Parameters { +func mustCreateParameters(t *testing.T, modulusSizeBits int, hashType HashType, publicExponent int, variant Variant) *Parameters { t.Helper() params, err := NewParameters(modulusSizeBits, hashType, publicExponent, variant) if err != nil { @@ -203,7 +203,7 @@ func newParameters(t *testing.T, modulusSizeBits int, hashType HashType, publicE return params } -func newPublicKey(t *testing.T, modulus []byte, idRequirement uint32, parameters *Parameters) *PublicKey { +func mustCreatePublicKey(t *testing.T, modulus []byte, idRequirement uint32, parameters *Parameters) *PublicKey { t.Helper() key, err := NewPublicKey(modulus, idRequirement, parameters) if err != nil { @@ -227,14 +227,14 @@ func TestParsePublicKeyWithZeroPaddingModulus(t *testing.T) { t.Fatalf("proto.Marshal(%v) err = %v, want nil", publicKey, err) } - keySerialization := newKeySerialization(t, &tinkpb.KeyData{ + keySerialization := mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PublicKey", Value: serializedPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_TINK, 123) wantPublicKey := - newPublicKey(t, n, 123, newParameters(t, 2048, SHA256, f4, VariantTink)) + mustCreatePublicKey(t, n, 123, mustCreateParameters(t, 2048, SHA256, f4, VariantTink)) parser := &publicKeyParser{} parsedPublicKey, err := parser.ParseKey(keySerialization) @@ -303,147 +303,147 @@ func TestParseAndSerializePublicKey(t *testing.T) { }{ { name: "2048-SHA256-TINK", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized2048ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_TINK, 123), - publicKey: newPublicKey(t, base64Decode(t, n2048Base64), 123, newParameters(t, 2048, SHA256, f4, VariantTink)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n2048Base64), 123, mustCreateParameters(t, 2048, SHA256, f4, VariantTink)), }, { name: "2048-SHA256-LEGACY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized2048ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_LEGACY, 123), - publicKey: newPublicKey(t, base64Decode(t, n2048Base64), 123, newParameters(t, 2048, SHA256, f4, VariantLegacy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n2048Base64), 123, mustCreateParameters(t, 2048, SHA256, f4, VariantLegacy)), }, { name: "2048-SHA256-CRUNCHY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized2048ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_CRUNCHY, 123), - publicKey: newPublicKey(t, base64Decode(t, n2048Base64), 123, newParameters(t, 2048, SHA256, f4, VariantCrunchy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n2048Base64), 123, mustCreateParameters(t, 2048, SHA256, f4, VariantCrunchy)), }, { name: "2048-SHA256-RAW", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized2048ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_RAW, 0), - publicKey: newPublicKey(t, base64Decode(t, n2048Base64), 0, newParameters(t, 2048, SHA256, f4, VariantNoPrefix)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n2048Base64), 0, mustCreateParameters(t, 2048, SHA256, f4, VariantNoPrefix)), }, { name: "3072-SHA384-TINK", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA384ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_TINK, 123), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 123, newParameters(t, 3072, SHA384, f4, VariantTink)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 123, mustCreateParameters(t, 3072, SHA384, f4, VariantTink)), }, { name: "3072-SHA384-LEGACY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA384ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_LEGACY, 123), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 123, newParameters(t, 3072, SHA384, f4, VariantLegacy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 123, mustCreateParameters(t, 3072, SHA384, f4, VariantLegacy)), }, { name: "3072-SHA384-CRUNCHY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA384ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_CRUNCHY, 123), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 123, newParameters(t, 3072, SHA384, f4, VariantCrunchy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 123, mustCreateParameters(t, 3072, SHA384, f4, VariantCrunchy)), }, { name: "3072-SHA384-RAW", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA384ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_RAW, 0), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 0, newParameters(t, 3072, SHA384, f4, VariantNoPrefix)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 0, mustCreateParameters(t, 3072, SHA384, f4, VariantNoPrefix)), }, { name: "3072-SHA512-TINK", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA512ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_TINK, 123), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 123, newParameters(t, 3072, SHA512, f4, VariantTink)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 123, mustCreateParameters(t, 3072, SHA512, f4, VariantTink)), }, { name: "3072-SHA512-LEGACY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA512ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_LEGACY, 123), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 123, newParameters(t, 3072, SHA512, f4, VariantLegacy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 123, mustCreateParameters(t, 3072, SHA512, f4, VariantLegacy)), }, { name: "3072-SHA512-CRUNCHY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA512ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_CRUNCHY, 123), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 123, newParameters(t, 3072, SHA512, f4, VariantCrunchy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 123, mustCreateParameters(t, 3072, SHA512, f4, VariantCrunchy)), }, { name: "3072-SHA512-RAW", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized3072SHA512ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_RAW, 0), - publicKey: newPublicKey(t, base64Decode(t, n3072Base64), 0, newParameters(t, 3072, SHA512, f4, VariantNoPrefix)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n3072Base64), 0, mustCreateParameters(t, 3072, SHA512, f4, VariantNoPrefix)), }, { name: "4096-SHA512-TINK", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized4096ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_TINK, 123), - publicKey: newPublicKey(t, base64Decode(t, n4096Base64), 123, newParameters(t, 4096, SHA512, f4, VariantTink)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n4096Base64), 123, mustCreateParameters(t, 4096, SHA512, f4, VariantTink)), }, { name: "4096-SHA512-LEGACY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized4096ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_LEGACY, 123), - publicKey: newPublicKey(t, base64Decode(t, n4096Base64), 123, newParameters(t, 4096, SHA512, f4, VariantLegacy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n4096Base64), 123, mustCreateParameters(t, 4096, SHA512, f4, VariantLegacy)), }, { name: "4096-SHA512-CRUNCHY", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized4096ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_CRUNCHY, 123), - publicKey: newPublicKey(t, base64Decode(t, n4096Base64), 123, newParameters(t, 4096, SHA512, f4, VariantCrunchy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n4096Base64), 123, mustCreateParameters(t, 4096, SHA512, f4, VariantCrunchy)), }, { name: "4096-SHA512-RAW", - publicKeySerialization: newKeySerialization(t, &tinkpb.KeyData{ + publicKeySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: verifierTypeURL, Value: serialized4096ProtoPublicKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, }, tinkpb.OutputPrefixType_RAW, 0), - publicKey: newPublicKey(t, base64Decode(t, n4096Base64), 0, newParameters(t, 4096, SHA512, f4, VariantNoPrefix)), + publicKey: mustCreatePublicKey(t, base64Decode(t, n4096Base64), 0, mustCreateParameters(t, 4096, SHA512, f4, VariantNoPrefix)), }, } { t.Run(tc.name, func(t *testing.T) { @@ -569,11 +569,11 @@ func TestParsePrivateKeyFails(t *testing.T) { }{ { name: "key data is nil", - keySerialization: newKeySerialization(t, nil, tinkpb.OutputPrefixType_TINK, 12345), + keySerialization: mustCreateKeySerialization(t, nil, tinkpb.OutputPrefixType_TINK, 12345), }, { name: "wrong type URL", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "invalid_type_url", Value: serializedPrivateKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, @@ -581,7 +581,7 @@ func TestParsePrivateKeyFails(t *testing.T) { }, { name: "wrong output prefix type", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, @@ -589,7 +589,7 @@ func TestParsePrivateKeyFails(t *testing.T) { }, { name: "wrong private key material type", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PUBLIC, @@ -597,7 +597,7 @@ func TestParsePrivateKeyFails(t *testing.T) { }, { name: "wrong private key version", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKeyWithWrongPrivateKeyVersion, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, @@ -605,7 +605,7 @@ func TestParsePrivateKeyFails(t *testing.T) { }, { name: "wrong public key version", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKeyWithWrongPublicKeyVersion, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, @@ -613,7 +613,7 @@ func TestParsePrivateKeyFails(t *testing.T) { }, { name: "wrong public key bytes", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKeyWithWrongPublicKeyBytes, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, @@ -629,7 +629,7 @@ func TestParsePrivateKeyFails(t *testing.T) { } } -func newPrivateKey(t *testing.T, publicKey *PublicKey, privateKeyValues PrivateKeyValues) *PrivateKey { +func mustCreatePrivateKey(t *testing.T, publicKey *PublicKey, privateKeyValues PrivateKeyValues) *PrivateKey { t.Helper() privateKey, err := NewPrivateKey(publicKey, privateKeyValues) if err != nil { @@ -669,12 +669,12 @@ func TestParsePrivateKeyWithZeroPaddingModulus(t *testing.T) { t.Fatalf("proto.Marshal(%v) err = %v, want nil", privateKey, err) } token := insecuresecretdataaccess.Token{} - keySerialization := newKeySerialization(t, &tinkpb.KeyData{ + keySerialization := mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_TINK, 12345) - wantPrivateKey := newPrivateKey(t, newPublicKey(t, n, 12345, newParameters(t, 2048, SHA256, f4, VariantTink)), PrivateKeyValues{ + wantPrivateKey := mustCreatePrivateKey(t, mustCreatePublicKey(t, n, 12345, mustCreateParameters(t, 2048, SHA256, f4, VariantTink)), PrivateKeyValues{ P: secretdata.NewBytesFromData(p, token), Q: secretdata.NewBytesFromData(q, token), D: secretdata.NewBytesFromData(d, token), @@ -764,12 +764,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }{ { name: "2048-SHA256-TINK", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey2048, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_TINK, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n2048Base64), 12345, newParameters(t, 2048, SHA256, f4, VariantTink)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n2048Base64), 12345, mustCreateParameters(t, 2048, SHA256, f4, VariantTink)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d2048Base64), token), @@ -777,12 +777,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "2048-SHA256-LEGACY", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey2048, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_LEGACY, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n2048Base64), 12345, newParameters(t, 2048, SHA256, f4, VariantLegacy)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n2048Base64), 12345, mustCreateParameters(t, 2048, SHA256, f4, VariantLegacy)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d2048Base64), token), @@ -790,12 +790,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "2048-SHA256-CRUNCHY", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey2048, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_CRUNCHY, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n2048Base64), 12345, newParameters(t, 2048, SHA256, f4, VariantCrunchy)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n2048Base64), 12345, mustCreateParameters(t, 2048, SHA256, f4, VariantCrunchy)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d2048Base64), token), @@ -803,12 +803,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "2048-SHA256-RAW", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey2048, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_RAW, 0), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n2048Base64), 0, newParameters(t, 2048, SHA256, f4, VariantNoPrefix)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n2048Base64), 0, mustCreateParameters(t, 2048, SHA256, f4, VariantNoPrefix)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p2048Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q2048Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d2048Base64), token), @@ -816,12 +816,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "3072-SHA256-TINK", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey3072, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_TINK, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n3072Base64), 12345, newParameters(t, 3072, SHA256, f4, VariantTink)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n3072Base64), 12345, mustCreateParameters(t, 3072, SHA256, f4, VariantTink)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p3072Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q3072Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d3072Base64), token), @@ -829,12 +829,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "3072-SHA256-LEGACY", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey3072, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_LEGACY, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n3072Base64), 12345, newParameters(t, 3072, SHA256, f4, VariantLegacy)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n3072Base64), 12345, mustCreateParameters(t, 3072, SHA256, f4, VariantLegacy)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p3072Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q3072Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d3072Base64), token), @@ -842,12 +842,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "3072-SHA256-CRUNCHY", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey3072, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_CRUNCHY, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n3072Base64), 12345, newParameters(t, 3072, SHA256, f4, VariantCrunchy)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n3072Base64), 12345, mustCreateParameters(t, 3072, SHA256, f4, VariantCrunchy)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p3072Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q3072Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d3072Base64), token), @@ -855,12 +855,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "3072-SHA256-RAW", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey3072, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_RAW, 0), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n3072Base64), 0, newParameters(t, 3072, SHA256, f4, VariantNoPrefix)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n3072Base64), 0, mustCreateParameters(t, 3072, SHA256, f4, VariantNoPrefix)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p3072Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q3072Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d3072Base64), token), @@ -868,12 +868,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "4096-SHA256-TINK", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey4096, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_TINK, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n4096Base64), 12345, newParameters(t, 4096, SHA256, f4, VariantTink)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n4096Base64), 12345, mustCreateParameters(t, 4096, SHA256, f4, VariantTink)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p4096Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q4096Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d4096Base64), token), @@ -881,12 +881,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "4096-SHA256-LEGACY", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey4096, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_LEGACY, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n4096Base64), 12345, newParameters(t, 4096, SHA256, f4, VariantLegacy)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n4096Base64), 12345, mustCreateParameters(t, 4096, SHA256, f4, VariantLegacy)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p4096Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q4096Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d4096Base64), token), @@ -894,12 +894,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "4096-SHA256-CRUNCHY", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey4096, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_CRUNCHY, 12345), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n4096Base64), 12345, newParameters(t, 4096, SHA256, f4, VariantCrunchy)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n4096Base64), 12345, mustCreateParameters(t, 4096, SHA256, f4, VariantCrunchy)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p4096Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q4096Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d4096Base64), token), @@ -907,12 +907,12 @@ func TestParseAndSerializePrivateKey(t *testing.T) { }, { name: "4096-SHA256-RAW", - keySerialization: newKeySerialization(t, &tinkpb.KeyData{ + keySerialization: mustCreateKeySerialization(t, &tinkpb.KeyData{ TypeUrl: "type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey", Value: serializedPrivateKey4096, KeyMaterialType: tinkpb.KeyData_ASYMMETRIC_PRIVATE, }, tinkpb.OutputPrefixType_RAW, 0), - privateKey: newPrivateKey(t, newPublicKey(t, base64Decode(t, n4096Base64), 0, newParameters(t, 4096, SHA256, f4, VariantNoPrefix)), PrivateKeyValues{ + privateKey: mustCreatePrivateKey(t, mustCreatePublicKey(t, base64Decode(t, n4096Base64), 0, mustCreateParameters(t, 4096, SHA256, f4, VariantNoPrefix)), PrivateKeyValues{ P: secretdata.NewBytesFromData(base64Decode(t, p4096Base64), token), Q: secretdata.NewBytesFromData(base64Decode(t, q4096Base64), token), D: secretdata.NewBytesFromData(base64Decode(t, d4096Base64), token), @@ -995,7 +995,7 @@ func TestSerializeParametersFailsWithWrongParameters(t *testing.T) { } } -func newKeyTemplate(t *testing.T, outputPrefixType tinkpb.OutputPrefixType, format *rsassapkcs1pb.RsaSsaPkcs1KeyFormat) *tinkpb.KeyTemplate { +func mustCreateKeyTemplate(t *testing.T, outputPrefixType tinkpb.OutputPrefixType, format *rsassapkcs1pb.RsaSsaPkcs1KeyFormat) *tinkpb.KeyTemplate { t.Helper() serializedFormat, err := proto.Marshal(format) if err != nil { @@ -1022,7 +1022,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1038,7 +1038,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1054,7 +1054,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1070,7 +1070,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1086,7 +1086,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1102,7 +1102,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1118,7 +1118,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1134,7 +1134,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1150,7 +1150,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1166,7 +1166,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1182,7 +1182,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1198,7 +1198,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 2048, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1214,7 +1214,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1230,7 +1230,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1246,7 +1246,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1262,7 +1262,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1278,7 +1278,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1294,7 +1294,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1310,7 +1310,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1326,7 +1326,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1342,7 +1342,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1358,7 +1358,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1374,7 +1374,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1390,7 +1390,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 3072, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1406,7 +1406,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1422,7 +1422,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1438,7 +1438,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1454,7 +1454,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA256, }, @@ -1470,7 +1470,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1486,7 +1486,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1502,7 +1502,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1518,7 +1518,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA384, }, @@ -1534,7 +1534,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_TINK, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1550,7 +1550,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_CRUNCHY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1566,7 +1566,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_LEGACY, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, @@ -1582,7 +1582,7 @@ func TestSerializeParameters(t *testing.T) { modulusSizeBits: 4096, publicExponent: f4, }, - wantKeyTemplate: newKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ + wantKeyTemplate: mustCreateKeyTemplate(t, tinkpb.OutputPrefixType_RAW, &rsassapkcs1pb.RsaSsaPkcs1KeyFormat{ Params: &rsassapkcs1pb.RsaSsaPkcs1Params{ HashType: commonpb.HashType_SHA512, }, diff --git a/signature/rsassapkcs1/signer_verifier_test.go b/signature/rsassapkcs1/signer_verifier_test.go index 2f3b686..4181911 100644 --- a/signature/rsassapkcs1/signer_verifier_test.go +++ b/signature/rsassapkcs1/signer_verifier_test.go @@ -54,7 +54,7 @@ func TestVerifyWorks(t *testing.T) { }{ { name: "2048-SHA256-RAW", - publicKey: newPublicKey(t, base64Decode(t, modulus2048Base64), 0, newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantNoPrefix)), + publicKey: mustCreatePublicKey(t, base64Decode(t, modulus2048Base64), 0, mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantNoPrefix)), signature: func() []byte { signatureHex := "3d10ce911833c1fe3f3356580017d159e1557e019096499950f62c3768c716bca418828dc140e930ecceff" + "ebc532db66c77b433e51cef6dfbac86cb3aff6f5fc2a488faf35199b2e12c9fe2de7be3eea63bdc9" + @@ -73,7 +73,7 @@ func TestVerifyWorks(t *testing.T) { }, { name: "2048-SHA512-RAW", - publicKey: newPublicKey(t, base64Decode(t, modulus2048Base64), 0, newParameters(t, 2048, rsassapkcs1.SHA512, f4, rsassapkcs1.VariantNoPrefix)), + publicKey: mustCreatePublicKey(t, base64Decode(t, modulus2048Base64), 0, mustCreateParameters(t, 2048, rsassapkcs1.SHA512, f4, rsassapkcs1.VariantNoPrefix)), signature: func() []byte { signatureHex := "67cbf2475fff2908ba2fbde91e5ac21901427cf3328b17a41a1ba41f955d64b6358c78417ca19d1bd83f36" + "0fe28e48c7e4fd3946349e19812d9fa41b546c6751fd49b4ad986c9f38c3af9993a8466b91839415" + @@ -92,7 +92,7 @@ func TestVerifyWorks(t *testing.T) { }, { name: "2048-SHA256-TINK", - publicKey: newPublicKey(t, base64Decode(t, modulus2048Base64), uint32(0x99887766), newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), + publicKey: mustCreatePublicKey(t, base64Decode(t, modulus2048Base64), uint32(0x99887766), mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantTink)), signature: func() []byte { signatureHex := "01998877663d10ce911833c1fe3f3356580017d159e1557e019096499950f62c3768c716bca418828dc140" + "e930ecceffebc532db66c77b433e51cef6dfbac86cb3aff6f5fc2a488faf35199b2e12c9fe2de7be" + @@ -111,7 +111,7 @@ func TestVerifyWorks(t *testing.T) { }, { name: "2048-SHA256-CRUNCHY", - publicKey: newPublicKey(t, base64Decode(t, modulus2048Base64), uint32(0x99887766), newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantCrunchy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, modulus2048Base64), uint32(0x99887766), mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantCrunchy)), signature: func() []byte { signatureHex := "00998877663d10ce911833c1fe3f3356580017d159e1557e019096499950f62c3768c716bca418828dc140" + "e930ecceffebc532db66c77b433e51cef6dfbac86cb3aff6f5fc2a488faf35199b2e12c9fe2de7be" + @@ -130,7 +130,7 @@ func TestVerifyWorks(t *testing.T) { }, { name: "2048-SHA256-LEGACY", - publicKey: newPublicKey(t, base64Decode(t, modulus2048Base64), uint32(0x99887766), newParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantLegacy)), + publicKey: mustCreatePublicKey(t, base64Decode(t, modulus2048Base64), uint32(0x99887766), mustCreateParameters(t, 2048, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantLegacy)), signature: func() []byte { signatureHex := "00998877668aece22c45c0db3db64e00416ed906b45e9c8ffedc1715cb3ea6cd9855a16f1c25375dbdd902" + "8c79ad5ee192f1fa60d54efbe3d753e1c604ee7104398e2bae28d1690d8984155b0de78ab52d90d3" + @@ -149,7 +149,7 @@ func TestVerifyWorks(t *testing.T) { }, { name: "4096-SHA256-RAW", - publicKey: newPublicKey(t, base64Decode(t, modulus4096Base64), 0, newParameters(t, 4096, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantNoPrefix)), + publicKey: mustCreatePublicKey(t, base64Decode(t, modulus4096Base64), 0, mustCreateParameters(t, 4096, rsassapkcs1.SHA256, f4, rsassapkcs1.VariantNoPrefix)), signature: func() []byte { signatureHex := "122a08c6e8b9bf4cb437a00e55cf6ac96e216c4580af87e40be6227504e163c0c516b747d38a81f087f387" + "8242008e4d0ef400d02f5bdc6629bb2f323241fcbbaa84aa173324359bdf7e35becd68b3977367ae" +