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

Commit

Permalink
Prepare primitive wrappers to the switch in the Registry where Mutabl…
Browse files Browse the repository at this point in the history
…ePrimitiveRegistry will be used under the hood for wrapper registration, and this does not tolerate when a different wrapper object is attempted to be registered for a primitive class for which a wrapper object is already registered.

PiperOrigin-RevId: 495833830
  • Loading branch information
LizaTretyakova authored and copybara-github committed Dec 16, 2022
1 parent 683e6cc commit 7b6ae29
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
public class AeadWrapper implements PrimitiveWrapper<Aead, Aead> {
private static final Logger logger = Logger.getLogger(AeadWrapper.class.getName());

private static final AeadWrapper WRAPPER = new AeadWrapper();

private static class WrappedAead implements Aead {
private final PrimitiveSet<Aead> pSet;
private final MonitoringClient.Logger encLogger;
Expand Down Expand Up @@ -131,6 +133,6 @@ public Class<Aead> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new AeadWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
*/
public class DeterministicAeadWrapper
implements PrimitiveWrapper<DeterministicAead, DeterministicAead> {

private static final Logger logger = Logger.getLogger(DeterministicAeadWrapper.class.getName());
private static final DeterministicAeadWrapper WRAPPER = new DeterministicAeadWrapper();

private static class WrappedDeterministicAead implements DeterministicAead {
private final PrimitiveSet<DeterministicAead> primitives;
Expand Down Expand Up @@ -138,6 +140,6 @@ public Class<DeterministicAead> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new DeterministicAeadWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
* com.google.crypto.tink.proto.OutputPrefixType#RAW}.
*/
public class HybridDecryptWrapper implements PrimitiveWrapper<HybridDecrypt, HybridDecrypt> {

private static final Logger logger = Logger.getLogger(HybridDecryptWrapper.class.getName());
private static final HybridDecryptWrapper WRAPPER = new HybridDecryptWrapper();

private static class WrappedHybridDecrypt implements HybridDecrypt {
private final PrimitiveSet<HybridDecrypt> primitives;
Expand Down Expand Up @@ -116,6 +118,6 @@ public Class<HybridDecrypt> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new HybridDecryptWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* with the primary key.
*/
public class HybridEncryptWrapper implements PrimitiveWrapper<HybridEncrypt, HybridEncrypt> {

private static final HybridEncryptWrapper WRAPPER = new HybridEncryptWrapper();

private static class WrappedHybridEncrypt implements HybridEncrypt {
final PrimitiveSet<HybridEncrypt> primitives;

Expand Down Expand Up @@ -95,6 +98,6 @@ public Class<HybridEncrypt> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new HybridEncryptWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* JwtMacWrapper is the implementation of {@link PrimitiveWrapper} for the {@link JwtMac} primitive.
*/
class JwtMacWrapper implements PrimitiveWrapper<JwtMacInternal, JwtMac> {

private static final JwtMacWrapper WRAPPER = new JwtMacWrapper();

private static void validate(PrimitiveSet<JwtMacInternal> primitiveSet)
throws GeneralSecurityException {
if (primitiveSet.getPrimary() == null) {
Expand Down Expand Up @@ -105,6 +108,6 @@ public Class<JwtMacInternal> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new JwtMacWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
class JwtPublicKeySignWrapper
implements PrimitiveWrapper<JwtPublicKeySignInternal, JwtPublicKeySign> {

private static final JwtPublicKeySignWrapper WRAPPER = new JwtPublicKeySignWrapper();

private static void validate(PrimitiveSet<JwtPublicKeySignInternal> primitiveSet)
throws GeneralSecurityException {
if (primitiveSet.getPrimary() == null) {
Expand Down Expand Up @@ -94,6 +96,6 @@ public Class<JwtPublicKeySignInternal> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new JwtPublicKeySignWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
class JwtPublicKeyVerifyWrapper
implements PrimitiveWrapper<JwtPublicKeyVerifyInternal, JwtPublicKeyVerify> {

private static final JwtPublicKeyVerifyWrapper WRAPPER = new JwtPublicKeyVerifyWrapper();

private static void validate(PrimitiveSet<JwtPublicKeyVerifyInternal> primitiveSet)
throws GeneralSecurityException {
for (List<PrimitiveSet.Entry<JwtPublicKeyVerifyInternal>> entries : primitiveSet.getAll()) {
Expand Down Expand Up @@ -100,6 +102,6 @@ public Class<JwtPublicKeyVerifyInternal> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new JwtPublicKeyVerifyWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MacWrapper implements PrimitiveWrapper<Mac, Mac> {
private static final Logger logger = Logger.getLogger(MacWrapper.class.getName());

private static final byte[] FORMAT_VERSION = new byte[] {0};
private static final MacWrapper WRAPPER = new MacWrapper();

private static class WrappedMac implements Mac {
private final PrimitiveSet<Mac> primitives;
Expand Down Expand Up @@ -169,6 +170,6 @@ public Class<Mac> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new MacWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
*/
@Immutable
public class PrfSetWrapper implements PrimitiveWrapper<Prf, PrfSet> {

private static final PrfSetWrapper WRAPPER = new PrfSetWrapper();

private static class WrappedPrfSet extends PrfSet {
// This map is constructed using Collections.unmodifiableMap
@SuppressWarnings("Immutable")
Expand Down Expand Up @@ -131,6 +134,6 @@ public Class<Prf> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new PrfSetWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public class PublicKeySignWrapper implements PrimitiveWrapper<PublicKeySign, PublicKeySign> {

private static final byte[] FORMAT_VERSION = new byte[] {0};
private static final PublicKeySignWrapper WRAPPER = new PublicKeySignWrapper();

private static class WrappedPublicKeySign implements PublicKeySign {
private final PrimitiveSet<PublicKeySign> primitives;
Expand Down Expand Up @@ -99,6 +100,6 @@ public Class<PublicKeySign> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new PublicKeySignWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
* @since 1.0.0
*/
class PublicKeyVerifyWrapper implements PrimitiveWrapper<PublicKeyVerify, PublicKeyVerify> {

private static final Logger logger = Logger.getLogger(PublicKeyVerifyWrapper.class.getName());

private static final byte[] FORMAT_VERSION = new byte[] {0};
private static final PublicKeyVerifyWrapper WRAPPER = new PublicKeyVerifyWrapper();

private static class WrappedPublicKeyVerify implements PublicKeyVerify {
private final PrimitiveSet<PublicKeyVerify> primitives;
Expand Down Expand Up @@ -131,6 +133,6 @@ public Class<PublicKeyVerify> getInputPrimitiveClass() {
* argument.
*/
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new PublicKeyVerifyWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* {@link com.google.crypto.tink.proto.OutputPrefixType#RAW}.
*/
public class StreamingAeadWrapper implements PrimitiveWrapper<StreamingAead, StreamingAead> {

private static final StreamingAeadWrapper WRAPPER = new StreamingAeadWrapper();

StreamingAeadWrapper() {}

/**
Expand All @@ -54,6 +57,6 @@ public Class<StreamingAead> getInputPrimitiveClass() {
}

public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new StreamingAeadWrapper());
Registry.registerPrimitiveWrapper(WRAPPER);
}
}

0 comments on commit 7b6ae29

Please sign in to comment.