Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Replace instances of Registry.registerPrimitiveWrapper with MutablePr…
Browse files Browse the repository at this point in the history
…imitiveRegistry.globalInstance().registerPrimitiveWrapper.

Registry.registerPrimitiveWrapper will most likely be removed. The API only works if used correctly together with what is in KeysetHandle. Furthermore, we are currently changing this, so if users use this API their code will inevitably fail.

I don't expect anyone to use this, otherwise they should contact us and we will find a solution together. (I will add this desclaimer in the upcoming change which removes this as well).

PiperOrigin-RevId: 601441934
  • Loading branch information
tholenst authored and copybara-github committed Jan 25, 2024
1 parent a2c73a9 commit f13be53
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 45 deletions.
2 changes: 2 additions & 0 deletions java_src/src/main/java/com/google/crypto/tink/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ java_library(
":key_manager",
":registry",
"//proto:config_java_proto",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry",
],
)

Expand All @@ -311,6 +312,7 @@ android_library(
":key_manager-android",
":registry-android",
"//proto:config_java_proto_lite",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry-android",
],
)

Expand Down
4 changes: 3 additions & 1 deletion java_src/src/main/java/com/google/crypto/tink/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.crypto.tink;

import com.google.crypto.tink.internal.MutablePrimitiveRegistry;
import com.google.crypto.tink.proto.KeyTypeEntry;
import com.google.crypto.tink.proto.RegistryConfig;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -94,7 +95,8 @@ public static void registerKeyType(KeyTypeEntry entry) throws GeneralSecurityExc
return;
}
Catalogue<?> catalogue = Registry.getCatalogue(entry.getCatalogueName());
Registry.registerPrimitiveWrapper(catalogue.getPrimitiveWrapper());
MutablePrimitiveRegistry.globalInstance()
.registerPrimitiveWrapper(catalogue.getPrimitiveWrapper());
KeyManager<?> keyManager =
catalogue.getKeyManager(
entry.getTypeUrl(), entry.getPrimitiveName(), entry.getKeyManagerVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import com.google.crypto.tink.CryptoFormat;
import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.MonitoringUtil;
import com.google.crypto.tink.internal.MutableMonitoringRegistry;
import com.google.crypto.tink.internal.MutablePrimitiveRegistry;
import com.google.crypto.tink.monitoring.MonitoringClient;
import com.google.crypto.tink.monitoring.MonitoringKeysetInfo;
import com.google.crypto.tink.subtle.Bytes;
Expand Down Expand Up @@ -130,6 +130,6 @@ public Class<Aead> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ java_library(
"//src/main/java/com/google/crypto/tink:crypto_format",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_client",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_keyset_info",
"//src/main/java/com/google/crypto/tink/subtle:bytes",
Expand Down Expand Up @@ -669,9 +669,9 @@ android_library(
"//src/main/java/com/google/crypto/tink:crypto_format-android",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry-android",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_client-android",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_keyset_info-android",
"//src/main/java/com/google/crypto/tink/subtle:bytes-android",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ java_library(
"//src/main/java/com/google/crypto/tink:deterministic_aead",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_client",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_keyset_info",
"//src/main/java/com/google/crypto/tink/subtle:bytes",
Expand All @@ -93,9 +93,9 @@ android_library(
"//src/main/java/com/google/crypto/tink:deterministic_aead-android",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry-android",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_client-android",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_keyset_info-android",
"//src/main/java/com/google/crypto/tink/subtle:bytes-android",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import com.google.crypto.tink.DeterministicAead;
import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.MonitoringUtil;
import com.google.crypto.tink.internal.MutableMonitoringRegistry;
import com.google.crypto.tink.internal.MutablePrimitiveRegistry;
import com.google.crypto.tink.monitoring.MonitoringClient;
import com.google.crypto.tink.monitoring.MonitoringKeysetInfo;
import com.google.crypto.tink.subtle.Bytes;
Expand Down Expand Up @@ -137,6 +137,6 @@ public Class<DeterministicAead> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ java_library(
"//src/main/java/com/google/crypto/tink:hybrid_encrypt",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_client",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_keyset_info",
"//src/main/java/com/google/crypto/tink/subtle:bytes",
Expand Down Expand Up @@ -391,9 +391,9 @@ android_library(
"//src/main/java/com/google/crypto/tink:hybrid_encrypt-android",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry-android",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_client-android",
"//src/main/java/com/google/crypto/tink/monitoring:monitoring_keyset_info-android",
"//src/main/java/com/google/crypto/tink/subtle:bytes-android",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import com.google.crypto.tink.HybridEncrypt;
import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.MonitoringUtil;
import com.google.crypto.tink.internal.MutableMonitoringRegistry;
import com.google.crypto.tink.internal.MutablePrimitiveRegistry;
import com.google.crypto.tink.monitoring.MonitoringClient;
import com.google.crypto.tink.monitoring.MonitoringKeysetInfo;
import com.google.crypto.tink.subtle.Bytes;
Expand Down Expand Up @@ -98,6 +98,6 @@ public Class<HybridEncrypt> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
}
}
8 changes: 4 additions & 4 deletions java_src/src/main/java/com/google/crypto/tink/jwt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ java_library(
"//proto:tink_java_proto",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry",
"@maven//:com_google_errorprone_error_prone_annotations",
],
)
Expand Down Expand Up @@ -505,7 +505,7 @@ java_library(
"//proto:tink_java_proto",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry",
"@maven//:com_google_errorprone_error_prone_annotations",
],
)
Expand All @@ -523,7 +523,7 @@ android_library(
"//proto:tink_java_proto_lite",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry-android",
"@maven//:com_google_errorprone_error_prone_annotations",
],
)
Expand Down Expand Up @@ -688,7 +688,7 @@ android_library(
"//proto:tink_java_proto_lite",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry-android",
"@maven//:com_google_errorprone_error_prone_annotations",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.MutablePrimitiveRegistry;
import com.google.crypto.tink.proto.OutputPrefixType;
import com.google.errorprone.annotations.Immutable;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -108,6 +108,6 @@ public Class<JwtMacInternal> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.MutablePrimitiveRegistry;
import com.google.crypto.tink.proto.OutputPrefixType;
import com.google.errorprone.annotations.Immutable;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -102,6 +102,6 @@ public Class<JwtPublicKeyVerifyInternal> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ android_library(
"//src/main/java/com/google/crypto/tink:key-android",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink:registry_cluster-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry-android",
"//src/main/java/com/google/crypto/tink/keyderivation:keyset_deriver-android",
"@maven//:com_google_errorprone_error_prone_annotations",
],
Expand All @@ -193,8 +193,8 @@ java_library(
"//src/main/java/com/google/crypto/tink:key",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink:registry_cluster",
"//src/main/java/com/google/crypto/tink/internal:mutable_primitive_registry",
"//src/main/java/com/google/crypto/tink/keyderivation:keyset_deriver",
"@maven//:com_google_errorprone_error_prone_annotations",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.MutablePrimitiveRegistry;
import com.google.crypto.tink.keyderivation.KeysetDeriver;
import com.google.errorprone.annotations.Immutable;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -94,6 +94,6 @@ public Class<KeyDeriver> getInputPrimitiveClass() {

/** Registers this wrapper with Tink, allowing to use the primitive. */
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
}
}
2 changes: 0 additions & 2 deletions java_src/src/main/java/com/google/crypto/tink/mac/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ java_library(
"//src/main/java/com/google/crypto/tink:mac",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink/internal:legacy_proto_key",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry",
Expand All @@ -147,7 +146,6 @@ android_library(
"//src/main/java/com/google/crypto/tink:mac-android",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink/internal:legacy_proto_key-android",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry-android",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.crypto.tink.Mac;
import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.LegacyProtoKey;
import com.google.crypto.tink.internal.MonitoringUtil;
import com.google.crypto.tink.internal.MutableMonitoringRegistry;
Expand Down Expand Up @@ -160,7 +159,7 @@ public Class<Mac> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance()
.registerPrimitiveConstructor(LEGACY_FULL_MAC_PRIMITIVE_CONSTRUCTOR);
}
Expand Down
2 changes: 0 additions & 2 deletions java_src/src/main/java/com/google/crypto/tink/prf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ java_library(
"//proto:tink_java_proto",
"//src/main/java/com/google/crypto/tink:primitive_set",
"//src/main/java/com/google/crypto/tink:primitive_wrapper",
"//src/main/java/com/google/crypto/tink:registry",
"//src/main/java/com/google/crypto/tink/internal:legacy_proto_key",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry",
Expand Down Expand Up @@ -363,7 +362,6 @@ android_library(
"//proto:tink_java_proto_lite",
"//src/main/java/com/google/crypto/tink:primitive_set-android",
"//src/main/java/com/google/crypto/tink:primitive_wrapper-android",
"//src/main/java/com/google/crypto/tink:registry-android",
"//src/main/java/com/google/crypto/tink/internal:legacy_proto_key-android",
"//src/main/java/com/google/crypto/tink/internal:monitoring_util-android",
"//src/main/java/com/google/crypto/tink/internal:mutable_monitoring_registry-android",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.internal.LegacyProtoKey;
import com.google.crypto.tink.internal.MonitoringUtil;
import com.google.crypto.tink.internal.MutableMonitoringRegistry;
Expand Down Expand Up @@ -141,7 +140,7 @@ public Class<Prf> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance().registerPrimitiveWrapper(WRAPPER);
MutablePrimitiveRegistry.globalInstance()
.registerPrimitiveConstructor(LEGACY_FULL_PRF_PRIMITIVE_CONSTRUCTOR);
}
Expand Down
Loading

0 comments on commit f13be53

Please sign in to comment.