Skip to content

Commit f8ab316

Browse files
kluevercopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 671036914
1 parent fe376d9 commit f8ab316

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

java/src/main/java/com/google/rcat/RcatTinkCrypto.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.crypto.tink.KeysetHandle;
2222
import com.google.crypto.tink.PublicKeySign;
2323
import com.google.crypto.tink.PublicKeyVerify;
24+
import com.google.crypto.tink.RegistryConfiguration;
2425
import com.google.errorprone.annotations.CheckReturnValue;
2526
import com.google.rcat.error.RcatDecryptionException;
2627
import com.google.rcat.error.RcatEncryptionException;
@@ -46,7 +47,8 @@ public static class Signer implements RcatCrypto.Signer {
4647
@Override
4748
public byte[] sign(byte[] data) throws RcatSigningException {
4849
try {
49-
PublicKeySign signer = this.privateKeysetHandle.getPrimitive(PublicKeySign.class);
50+
PublicKeySign signer =
51+
this.privateKeysetHandle.getPrimitive(RegistryConfiguration.get(), PublicKeySign.class);
5052
return signer.sign(data);
5153
} catch (GeneralSecurityException e) {
5254
throw new RcatSigningException("Unable to create signature for payload bytes.", e);
@@ -82,7 +84,9 @@ public static class Verifier implements RcatCrypto.Verifier {
8284
@Override
8385
public void verify(byte[] signature, byte[] data) throws RcatSignatureValidationException {
8486
try {
85-
PublicKeyVerify verifier = this.publicKeysetHandle.getPrimitive(PublicKeyVerify.class);
87+
PublicKeyVerify verifier =
88+
this.publicKeysetHandle.getPrimitive(
89+
RegistryConfiguration.get(), PublicKeyVerify.class);
8690
verifier.verify(signature, data);
8791
} catch (GeneralSecurityException e) {
8892
throw new RcatSignatureValidationException(
@@ -120,7 +124,8 @@ public static class Encrypter implements RcatCrypto.Encrypter {
120124
@Override
121125
public byte[] encrypt(byte[] plaintext, byte[] contextInfo) throws RcatEncryptionException {
122126
try {
123-
HybridEncrypt encrypter = this.publicKeysetHandle.getPrimitive(HybridEncrypt.class);
127+
HybridEncrypt encrypter =
128+
this.publicKeysetHandle.getPrimitive(RegistryConfiguration.get(), HybridEncrypt.class);
124129
return encrypter.encrypt(plaintext, contextInfo);
125130
} catch (GeneralSecurityException e) {
126131
throw new RcatEncryptionException("Unable to encrypt RCAT token envelope.", e);
@@ -156,7 +161,8 @@ public static class Decrypter implements RcatCrypto.Decrypter {
156161
@Override
157162
public byte[] decrypt(byte[] ciphertext, byte[] contextInfo) throws RcatDecryptionException {
158163
try {
159-
HybridDecrypt decrypter = this.privateKeysetHandle.getPrimitive(HybridDecrypt.class);
164+
HybridDecrypt decrypter =
165+
this.privateKeysetHandle.getPrimitive(RegistryConfiguration.get(), HybridDecrypt.class);
160166
return decrypter.decrypt(ciphertext, contextInfo);
161167
} catch (GeneralSecurityException e) {
162168
throw new RcatDecryptionException("Unable to decrypt RCAT token envelope.", e);

java/src/test/java/com/google/rcat/RcatExceptionTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.crypto.tink.KeyTemplates;
2424
import com.google.crypto.tink.KeysetHandle;
2525
import com.google.crypto.tink.PublicKeySign;
26+
import com.google.crypto.tink.RegistryConfiguration;
2627
import com.google.protobuf.ByteString;
2728
import com.google.rcat.error.RcatDecryptionException;
2829
import com.google.rcat.error.RcatExpiredException;
@@ -258,7 +259,8 @@ private byte[] sign(byte[] data) throws GeneralSecurityException {
258259

259260
private byte[] sign(byte[] data, KeysetHandle privateKeysetHandle)
260261
throws GeneralSecurityException {
261-
PublicKeySign signer = privateKeysetHandle.getPrimitive(PublicKeySign.class);
262+
PublicKeySign signer =
263+
privateKeysetHandle.getPrimitive(RegistryConfiguration.get(), PublicKeySign.class);
262264
return signer.sign(data);
263265
}
264266

@@ -268,7 +270,8 @@ private byte[] encrypt(byte[] data) throws GeneralSecurityException {
268270

269271
private byte[] encrypt(byte[] data, KeysetHandle publicKeysetHandle)
270272
throws GeneralSecurityException {
271-
HybridEncrypt encrypter = publicKeysetHandle.getPrimitive(HybridEncrypt.class);
273+
HybridEncrypt encrypter =
274+
publicKeysetHandle.getPrimitive(RegistryConfiguration.get(), HybridEncrypt.class);
272275
return encrypter.encrypt(data, new byte[0]);
273276
}
274277
}

0 commit comments

Comments
 (0)