Skip to content
Snippets Groups Projects
Commit ce44cd4f authored by tholenst's avatar tholenst Committed by Copybara-Service
Browse files

Make all remaining symmetric key managers public; their constructor package...

Make all remaining symmetric key managers public; their constructor package 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: 269555278
parent 6b912510
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 18 deletions
......@@ -18,6 +18,7 @@ package com.google.crypto.tink.daead;
import com.google.crypto.tink.DeterministicAead;
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.AesSivKey;
import com.google.crypto.tink.proto.AesSivKeyFormat;
import com.google.crypto.tink.proto.KeyData.KeyMaterialType;
......@@ -34,8 +35,8 @@ import java.security.InvalidKeyException;
* This key manager generates new {@code AesSivKey} keys and produces new instances of {@code
* AesSiv}.
*/
class AesSivKeyManager extends KeyTypeManager<AesSivKey> {
public AesSivKeyManager() {
public class AesSivKeyManager extends KeyTypeManager<AesSivKey> {
AesSivKeyManager() {
super(
AesSivKey.class,
new PrimitiveFactory<DeterministicAead, AesSivKey>(DeterministicAead.class) {
......@@ -101,4 +102,8 @@ class AesSivKeyManager extends KeyTypeManager<AesSivKey> {
}
};
}
public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
Registry.registerKeyManager(new AesSivKeyManager(), newKeyAllowed);
}
}
......@@ -80,7 +80,7 @@ public final class DeterministicAeadConfig {
* @since 1.2.0
*/
public static void register() throws GeneralSecurityException {
Registry.registerKeyManager(new AesSivKeyManager(), /* newKeyAllowed = */ true);
Registry.registerPrimitiveWrapper(new DeterministicAeadWrapper());
AesSivKeyManager.register(/* newKeyAllowed = */ true);
DeterministicAeadWrapper.register();
}
}
......@@ -20,6 +20,7 @@ import com.google.crypto.tink.CryptoFormat;
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.subtle.Bytes;
import java.security.GeneralSecurityException;
import java.util.Arrays;
......@@ -35,7 +36,7 @@ import java.util.logging.Logger;
* select the right key in the set. If the keys associated with the prefix do not work, the
* primitive tries all keys with {@link com.google.crypto.tink.proto.OutputPrefixType#RAW}.
*/
class DeterministicAeadWrapper implements PrimitiveWrapper<DeterministicAead> {
public class DeterministicAeadWrapper implements PrimitiveWrapper<DeterministicAead> {
private static final Logger logger = Logger.getLogger(DeterministicAeadWrapper.class.getName());
private static class WrappedDeterministicAead implements DeterministicAead {
......@@ -90,6 +91,8 @@ class DeterministicAeadWrapper implements PrimitiveWrapper<DeterministicAead> {
}
}
DeterministicAeadWrapper() {}
@Override
public DeterministicAead wrap(final PrimitiveSet<DeterministicAead> primitives) {
return new WrappedDeterministicAead(primitives);
......@@ -99,4 +102,8 @@ class DeterministicAeadWrapper implements PrimitiveWrapper<DeterministicAead> {
public Class<DeterministicAead> getPrimitiveClass() {
return DeterministicAead.class;
}
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new DeterministicAeadWrapper());
}
}
......@@ -18,6 +18,7 @@ package com.google.crypto.tink.mac;
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.Mac;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.AesCmacKey;
import com.google.crypto.tink.proto.AesCmacKeyFormat;
import com.google.crypto.tink.proto.AesCmacParams;
......@@ -33,9 +34,9 @@ import java.security.GeneralSecurityException;
* This key manager generates new {@code AesCmacKey} keys and produces new instances of {@code
* AesCmac}.
*/
class AesCmacKeyManager extends KeyTypeManager<AesCmacKey> {
public class AesCmacKeyManager extends KeyTypeManager<AesCmacKey> {
public AesCmacKeyManager() {
AesCmacKeyManager() {
super(
AesCmacKey.class,
new PrimitiveFactory<Mac, AesCmacKey>(Mac.class) {
......@@ -118,4 +119,8 @@ class AesCmacKeyManager extends KeyTypeManager<AesCmacKey> {
}
};
}
public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
Registry.registerKeyManager(new AesCmacKeyManager(), newKeyAllowed);
}
}
......@@ -18,6 +18,7 @@ package com.google.crypto.tink.mac;
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.Mac;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.proto.HashType;
import com.google.crypto.tink.proto.HmacKey;
import com.google.crypto.tink.proto.HmacKeyFormat;
......@@ -148,4 +149,8 @@ public class HmacKeyManager extends KeyTypeManager<HmacKey> {
}
};
}
public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
Registry.registerKeyManager(new HmacKeyManager(), newKeyAllowed);
}
}
......@@ -83,9 +83,9 @@ public final class MacConfig {
* @since 1.2.0
*/
public static void register() throws GeneralSecurityException {
Registry.registerKeyManager(new HmacKeyManager(), true);
Registry.registerKeyManager(new AesCmacKeyManager(), true);
Registry.registerPrimitiveWrapper(new MacWrapper());
HmacKeyManager.register(true);
AesCmacKeyManager.register(true);
MacWrapper.register();
}
/**
......
......@@ -20,6 +20,7 @@ import com.google.crypto.tink.CryptoFormat;
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.proto.OutputPrefixType;
import com.google.crypto.tink.subtle.Bytes;
import java.security.GeneralSecurityException;
......@@ -100,6 +101,8 @@ class MacWrapper implements PrimitiveWrapper<Mac> {
}
}
MacWrapper() {}
@Override
public Mac wrap(final PrimitiveSet<Mac> primitives) throws GeneralSecurityException {
return new WrappedMac(primitives);
......@@ -109,4 +112,8 @@ class MacWrapper implements PrimitiveWrapper<Mac> {
public Class<Mac> getPrimitiveClass() {
return Mac.class;
}
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new MacWrapper());
}
}
......@@ -17,6 +17,7 @@
package com.google.crypto.tink.streamingaead;
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.StreamingAead;
import com.google.crypto.tink.proto.AesCtrHmacStreamingKey;
import com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat;
......@@ -35,8 +36,8 @@ import java.security.GeneralSecurityException;
* This key manager generates new {@code AesCtrHmacStreamingKey} keys and produces new instances of
* {@code AesCtrHmacStreaming}.
*/
class AesCtrHmacStreamingKeyManager extends KeyTypeManager<AesCtrHmacStreamingKey> {
public AesCtrHmacStreamingKeyManager() {
public class AesCtrHmacStreamingKeyManager extends KeyTypeManager<AesCtrHmacStreamingKey> {
AesCtrHmacStreamingKeyManager() {
super(
AesCtrHmacStreamingKey.class,
new PrimitiveFactory<StreamingAead, AesCtrHmacStreamingKey>(StreamingAead.class) {
......@@ -171,4 +172,8 @@ class AesCtrHmacStreamingKeyManager extends KeyTypeManager<AesCtrHmacStreamingKe
throw new GeneralSecurityException("unknown hash type");
}
}
public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
Registry.registerKeyManager(new AesCtrHmacStreamingKeyManager(), newKeyAllowed);
}
}
......@@ -17,6 +17,7 @@
package com.google.crypto.tink.streamingaead;
import com.google.crypto.tink.KeyTypeManager;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.StreamingAead;
import com.google.crypto.tink.proto.AesGcmHkdfStreamingKey;
import com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat;
......@@ -34,8 +35,8 @@ import java.security.GeneralSecurityException;
* This key manager generates new {@code AesGcmHkdfStreamingKey} keys and produces new instances of
* {@code AesGcmHkdfStreaming}.
*/
class AesGcmHkdfStreamingKeyManager extends KeyTypeManager<AesGcmHkdfStreamingKey> {
public AesGcmHkdfStreamingKeyManager() {
public class AesGcmHkdfStreamingKeyManager extends KeyTypeManager<AesGcmHkdfStreamingKey> {
AesGcmHkdfStreamingKeyManager() {
super(
AesGcmHkdfStreamingKey.class,
new PrimitiveFactory<StreamingAead, AesGcmHkdfStreamingKey>(StreamingAead.class) {
......@@ -126,4 +127,8 @@ class AesGcmHkdfStreamingKeyManager extends KeyTypeManager<AesGcmHkdfStreamingKe
+ "TAG_SIZE_IN_BYTES + 2)");
}
}
public static void register(boolean newKeyAllowed) throws GeneralSecurityException {
Registry.registerKeyManager(new AesGcmHkdfStreamingKeyManager(), newKeyAllowed);
}
}
......@@ -74,8 +74,8 @@ public final class StreamingAeadConfig {
* @since 1.2.0
*/
public static void register() throws GeneralSecurityException {
Registry.registerKeyManager(new AesCtrHmacStreamingKeyManager(), /* newKeyAllowed = */ true);
Registry.registerKeyManager(new AesGcmHkdfStreamingKeyManager(), /* newKeyAllowed = */ true);
Registry.registerPrimitiveWrapper(new StreamingAeadWrapper());
AesCtrHmacStreamingKeyManager.register(/* newKeyAllowed = */ true);
AesGcmHkdfStreamingKeyManager.register(/* newKeyAllowed = */ true);
StreamingAeadWrapper.register();
}
}
......@@ -18,6 +18,7 @@ package com.google.crypto.tink.streamingaead;
import com.google.crypto.tink.PrimitiveSet;
import com.google.crypto.tink.PrimitiveWrapper;
import com.google.crypto.tink.Registry;
import com.google.crypto.tink.StreamingAead;
import java.security.GeneralSecurityException;
......@@ -29,7 +30,9 @@ import java.security.GeneralSecurityException;
* keyset to select the right key for decryption. All keys in a keyset of StreamingAead have type
* {@link com.google.crypto.tink.proto.OutputPrefixType#RAW}.
*/
class StreamingAeadWrapper implements PrimitiveWrapper<StreamingAead> {
public class StreamingAeadWrapper implements PrimitiveWrapper<StreamingAead> {
StreamingAeadWrapper() {}
/**
* @return a StreamingAead primitive from a {@code keysetHandle}.
* @throws GeneralSecurityException
......@@ -44,4 +47,8 @@ class StreamingAeadWrapper implements PrimitiveWrapper<StreamingAead> {
public Class<StreamingAead> getPrimitiveClass() {
return StreamingAead.class;
}
public static void register() throws GeneralSecurityException {
Registry.registerPrimitiveWrapper(new StreamingAeadWrapper());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment