Make all AEAD key managers public; their constructor private, and add a static method "register()".
Also do the same transformation to the wrappers and use the new functions in the config.
PiperOrigin-RevId: 269550398
diff --git a/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java b/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java
index 7f303a1..d311175 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java
@@ -97,13 +97,13 @@
*/
public static void register() throws GeneralSecurityException {
MacConfig.register();
- Registry.registerKeyManager(new AesCtrHmacAeadKeyManager(), /*newKeyAllowed=*/ true);
- Registry.registerKeyManager(new AesEaxKeyManager(), /*newKeyAllowed=*/ true);
+ AesCtrHmacAeadKeyManager.register(/*newKeyAllowed=*/ true);
+ AesEaxKeyManager.register(/*newKeyAllowed=*/ true);
AesGcmKeyManager.register(/*newKeyAllowed=*/ true);
- Registry.registerKeyManager(new ChaCha20Poly1305KeyManager(), /*newKeyAllowed=*/ true);
- Registry.registerKeyManager(new KmsAeadKeyManager(), /*newKeyAllowed=*/ true);
- Registry.registerKeyManager(new KmsEnvelopeAeadKeyManager(), /*newKeyAllowed=*/ true);
- Registry.registerKeyManager(new XChaCha20Poly1305KeyManager(), /*newKeyAllowed=*/ true);
+ ChaCha20Poly1305KeyManager.register(/*newKeyAllowed=*/ true);
+ KmsAeadKeyManager.register(/*newKeyAllowed=*/ true);
+ KmsEnvelopeAeadKeyManager.register(/*newKeyAllowed=*/ true);
+ XChaCha20Poly1305KeyManager.register(/*newKeyAllowed=*/ true);
AeadWrapper.register();
}
diff --git a/java/src/main/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManager.java b/java/src/main/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManager.java
index db261b8..50368d8 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManager.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManager.java
@@ -19,6 +19,7 @@
import com.google.crypto.tink.Aead;
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.Mac;
+import com.google.crypto.tink.Registry;
import com.google.crypto.tink.mac.HmacKeyManager;
import com.google.crypto.tink.proto.AesCtrHmacAeadKey;
import com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat;
@@ -36,8 +37,8 @@
* This key manager generates new {@link AesCtrHmacAeadKey} keys and produces new instances of
* {@link EncryptThenAuthenticate}.
*/
-class AesCtrHmacAeadKeyManager extends KeyTypeManager<AesCtrHmacAeadKey> {
- public AesCtrHmacAeadKeyManager() {
+public class AesCtrHmacAeadKeyManager extends KeyTypeManager<AesCtrHmacAeadKey> {
+ AesCtrHmacAeadKeyManager() {
super(
AesCtrHmacAeadKey.class,
new PrimitiveFactory<Aead, AesCtrHmacAeadKey>(Aead.class) {
@@ -110,4 +111,8 @@
}
};
}
+
+ public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
+ Registry.registerKeyManager(new AesCtrHmacAeadKeyManager(), newKeyAllowed);
+ }
}
diff --git a/java/src/main/java/com/google/crypto/tink/aead/AesCtrKeyManager.java b/java/src/main/java/com/google/crypto/tink/aead/AesCtrKeyManager.java
index 968a1ed..30eebec 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/AesCtrKeyManager.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/AesCtrKeyManager.java
@@ -17,6 +17,7 @@
package com.google.crypto.tink.aead;
import com.google.crypto.tink.KeyTypeManager;
+import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.AesCtrKey;
import com.google.crypto.tink.proto.AesCtrKeyFormat;
import com.google.crypto.tink.proto.AesCtrParams;
@@ -33,8 +34,8 @@
* This key manager generates new {@code AesCtrKey} keys and produces new instances of {@code
* AesCtrJceCipher}.
*/
-class AesCtrKeyManager extends KeyTypeManager<AesCtrKey> {
- public AesCtrKeyManager() {
+public class AesCtrKeyManager extends KeyTypeManager<AesCtrKey> {
+ AesCtrKeyManager() {
super(
AesCtrKey.class,
new PrimitiveFactory<IndCpaCipher, AesCtrKey>(IndCpaCipher.class) {
@@ -113,4 +114,8 @@
throw new GeneralSecurityException("invalid IV size");
}
}
+
+ public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
+ Registry.registerKeyManager(new AesCtrKeyManager(), newKeyAllowed);
+ }
}
diff --git a/java/src/main/java/com/google/crypto/tink/aead/AesEaxKeyManager.java b/java/src/main/java/com/google/crypto/tink/aead/AesEaxKeyManager.java
index bbdfb39..bb7b6ed 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/AesEaxKeyManager.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/AesEaxKeyManager.java
@@ -18,6 +18,7 @@
import com.google.crypto.tink.Aead;
import com.google.crypto.tink.KeyTypeManager;
+import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.AesEaxKey;
import com.google.crypto.tink.proto.AesEaxKeyFormat;
import com.google.crypto.tink.proto.KeyData.KeyMaterialType;
@@ -32,8 +33,8 @@
* This key manager generates new {@code AesEaxKey} keys and produces new instances of {@code
* AesEaxJce}.
*/
-class AesEaxKeyManager extends KeyTypeManager<AesEaxKey> {
- public AesEaxKeyManager() {
+public class AesEaxKeyManager extends KeyTypeManager<AesEaxKey> {
+ AesEaxKeyManager() {
super(
AesEaxKey.class,
new PrimitiveFactory<Aead, AesEaxKey>(Aead.class) {
@@ -102,4 +103,8 @@
}
};
}
+
+ public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
+ Registry.registerKeyManager(new AesEaxKeyManager(), newKeyAllowed);
+ }
}
diff --git a/java/src/main/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManager.java b/java/src/main/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManager.java
index e047b84..bae2303 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManager.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManager.java
@@ -18,6 +18,7 @@
import com.google.crypto.tink.Aead;
import com.google.crypto.tink.KeyTypeManager;
+import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.ChaCha20Poly1305Key;
import com.google.crypto.tink.proto.ChaCha20Poly1305KeyFormat;
import com.google.crypto.tink.proto.KeyData.KeyMaterialType;
@@ -32,8 +33,8 @@
* This instance of {@code KeyManager} generates new {@code ChaCha20Poly1305} keys and produces new
* instances of {@code ChaCha20Poly1305}.
*/
-class ChaCha20Poly1305KeyManager extends KeyTypeManager<ChaCha20Poly1305Key> {
- public ChaCha20Poly1305KeyManager() {
+public class ChaCha20Poly1305KeyManager extends KeyTypeManager<ChaCha20Poly1305Key> {
+ ChaCha20Poly1305KeyManager() {
super(
ChaCha20Poly1305Key.class,
new PrimitiveFactory<Aead, ChaCha20Poly1305Key>(Aead.class) {
@@ -98,4 +99,8 @@
}
};
}
+
+ public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
+ Registry.registerKeyManager(new ChaCha20Poly1305KeyManager(), newKeyAllowed);
+ }
}
diff --git a/java/src/main/java/com/google/crypto/tink/aead/KmsAeadKeyManager.java b/java/src/main/java/com/google/crypto/tink/aead/KmsAeadKeyManager.java
index b3af757..4eaff5a 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/KmsAeadKeyManager.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/KmsAeadKeyManager.java
@@ -20,6 +20,7 @@
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.KmsClient;
import com.google.crypto.tink.KmsClients;
+import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.KeyData.KeyMaterialType;
import com.google.crypto.tink.proto.KmsAeadKey;
import com.google.crypto.tink.proto.KmsAeadKeyFormat;
@@ -32,8 +33,8 @@
* This key manager produces new instances of {@code Aead} that forwards encrypt/decrypt requests to
* a key residing in a remote KMS.
*/
-class KmsAeadKeyManager extends KeyTypeManager<KmsAeadKey> {
- public KmsAeadKeyManager() {
+public class KmsAeadKeyManager extends KeyTypeManager<KmsAeadKey> {
+ KmsAeadKeyManager() {
super(
KmsAeadKey.class,
new PrimitiveFactory<Aead, KmsAeadKey>(Aead.class) {
@@ -89,4 +90,8 @@
}
};
}
+
+ public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
+ Registry.registerKeyManager(new KmsAeadKeyManager(), newKeyAllowed);
+ }
}
diff --git a/java/src/main/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManager.java b/java/src/main/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManager.java
index 3dddb30..c900c18 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManager.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManager.java
@@ -20,6 +20,7 @@
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.KmsClient;
import com.google.crypto.tink.KmsClients;
+import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.KeyData.KeyMaterialType;
import com.google.crypto.tink.proto.KmsEnvelopeAeadKey;
import com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat;
@@ -32,8 +33,8 @@
* This key manager generates new {@code KmsEnvelopeAeadKey} keys and produces new instances of
* {@code KmsEnvelopeAead}.
*/
-class KmsEnvelopeAeadKeyManager extends KeyTypeManager<KmsEnvelopeAeadKey> {
- public KmsEnvelopeAeadKeyManager() {
+public class KmsEnvelopeAeadKeyManager extends KeyTypeManager<KmsEnvelopeAeadKey> {
+ KmsEnvelopeAeadKeyManager() {
super(
KmsEnvelopeAeadKey.class,
new PrimitiveFactory<Aead, KmsEnvelopeAeadKey>(Aead.class) {
@@ -93,4 +94,8 @@
}
};
}
+
+ public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
+ Registry.registerKeyManager(new KmsEnvelopeAeadKeyManager(), newKeyAllowed);
+ }
}
diff --git a/java/src/main/java/com/google/crypto/tink/aead/XChaCha20Poly1305KeyManager.java b/java/src/main/java/com/google/crypto/tink/aead/XChaCha20Poly1305KeyManager.java
index 8b123f3..ec4c8ad 100644
--- a/java/src/main/java/com/google/crypto/tink/aead/XChaCha20Poly1305KeyManager.java
+++ b/java/src/main/java/com/google/crypto/tink/aead/XChaCha20Poly1305KeyManager.java
@@ -18,6 +18,7 @@
import com.google.crypto.tink.Aead;
import com.google.crypto.tink.KeyTypeManager;
+import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.KeyData.KeyMaterialType;
import com.google.crypto.tink.proto.XChaCha20Poly1305Key;
import com.google.crypto.tink.proto.XChaCha20Poly1305KeyFormat;
@@ -32,8 +33,8 @@
* This instance of {@code KeyManager} generates new {@code XChaCha20Poly1305} keys and produces new
* instances of {@code XChaCha20Poly1305}.
*/
-class XChaCha20Poly1305KeyManager extends KeyTypeManager<XChaCha20Poly1305Key> {
- public XChaCha20Poly1305KeyManager() {
+public class XChaCha20Poly1305KeyManager extends KeyTypeManager<XChaCha20Poly1305Key> {
+ XChaCha20Poly1305KeyManager() {
super(
XChaCha20Poly1305Key.class,
new PrimitiveFactory<Aead, XChaCha20Poly1305Key>(Aead.class) {
@@ -99,4 +100,8 @@
}
};
}
+
+ public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
+ Registry.registerKeyManager(new XChaCha20Poly1305KeyManager(), newKeyAllowed);
+ }
}