Class MutableSerializationRegistry
- java.lang.Object
-
- com.google.crypto.tink.internal.MutableSerializationRegistry
-
public final class MutableSerializationRegistry extends java.lang.ObjectA Mutable version of theSerializationRegistry.This class probably shouldn't exist; it would be better if we had only the SerializationRegistry. However, at the moment, we need this, since a call to e.g.
AesCmacKeyManager.register()
should register such an object into a global, mutable registry.
-
-
Constructor Summary
Constructors Constructor Description MutableSerializationRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MutableSerializationRegistryglobalInstance()<SerializationT extends Serialization>
booleanhasParserForKey(SerializationT serializedKey)Returns true if a parser for thisserializedKeyhas been registered.<SerializationT extends Serialization>
booleanhasParserForParameters(SerializationT serializedParameters)Returns true if a parser for thisserializedKeyhas been registered.<KeyT extends Key,SerializationT extends Serialization>
booleanhasSerializerForKey(KeyT key, java.lang.Class<SerializationT> serializationClass)Returns true if a parser for thisserializedKeyhas been registered.<ParametersT extends Parameters,SerializationT extends Serialization>
booleanhasSerializerForParameters(ParametersT parameters, java.lang.Class<SerializationT> serializationClass)Returns true if a parser for thisserializedKeyhas been registered.<SerializationT extends Serialization>
KeyparseKey(SerializationT serializedKey, SecretKeyAccess access)Parses the given serialization into a Key.KeyparseKeyWithLegacyFallback(ProtoKeySerialization protoKeySerialization, SecretKeyAccess access)Returns a Key object from a protoKeySerialization, even if no parser has been registered.<SerializationT extends Serialization>
ParametersparseParameters(SerializationT serializedParameters)Parses the given serialization into a Parameters object.ParametersparseParametersWithLegacyFallback(ProtoParametersSerialization protoParametersSerialization)Returns a Parameters object from a protoKeySerialization, even if no parser has been registered.<SerializationT extends Serialization>
voidregisterKeyParser(KeyParser<SerializationT> parser)Registers a key parser for later use inparseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess).<KeyT extends Key,SerializationT extends Serialization>
voidregisterKeySerializer(KeySerializer<KeyT,SerializationT> serializer)Registers a key serializer for later use inserializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess).<SerializationT extends Serialization>
voidregisterParametersParser(ParametersParser<SerializationT> parser)Registers a key parser for later use inparseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess).<ParametersT extends Parameters,SerializationT extends Serialization>
voidregisterParametersSerializer(ParametersSerializer<ParametersT,SerializationT> serializer)Registers a key serializer for later use inserializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess).<KeyT extends Key,SerializationT extends Serialization>
SerializationTserializeKey(KeyT key, java.lang.Class<SerializationT> serializationClass, SecretKeyAccess access)Serializes a given Key into a "SerializationT" object.<ParametersT extends Parameters,SerializationT extends Serialization>
SerializationTserializeParameters(ParametersT parameters, java.lang.Class<SerializationT> serializationClass)Serializes a given Parameters object into a "SerializationT" object.
-
-
-
Method Detail
-
globalInstance
public static MutableSerializationRegistry globalInstance()
-
registerKeySerializer
public <KeyT extends Key,SerializationT extends Serialization> void registerKeySerializer(KeySerializer<KeyT,SerializationT> serializer) throws java.security.GeneralSecurityException
Registers a key serializer for later use inserializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
serializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess). If a serializer for the pair(KeyT, SerializationT)has already been registered, this checks if they are the same. If they are, the call is ignored, otherwise an exception is thrown, and the object is unchanged.- Throws:
java.security.GeneralSecurityException
-
registerKeyParser
public <SerializationT extends Serialization> void registerKeyParser(KeyParser<SerializationT> parser) throws java.security.GeneralSecurityException
Registers a key parser for later use inparseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
parseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess). If a parser for the pair(SerializationT, parser.getObjectIdentifier())has already been registered, this checks if they are the same. If they are, the call is ignored, otherwise an exception is thrown, and the object is unchanged.- Throws:
java.security.GeneralSecurityException
-
registerParametersSerializer
public <ParametersT extends Parameters,SerializationT extends Serialization> void registerParametersSerializer(ParametersSerializer<ParametersT,SerializationT> serializer) throws java.security.GeneralSecurityException
Registers a key serializer for later use inserializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
serializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess). If a serializer for the pair(KeyT, SerializationT)has already been registered, this checks if they are the same. If they are, the call is ignored, otherwise an exception is thrown, and the object is unchanged.- Throws:
java.security.GeneralSecurityException
-
registerParametersParser
public <SerializationT extends Serialization> void registerParametersParser(ParametersParser<SerializationT> parser) throws java.security.GeneralSecurityException
Registers a key parser for later use inparseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
parseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess). If a parser for the pair(SerializationT, parser.getObjectIdentifier())has already been registered, this checks if they are the same. If they are, the call is ignored, otherwise an exception is thrown, and the object is unchanged.- Throws:
java.security.GeneralSecurityException
-
hasParserForKey
public <SerializationT extends Serialization> boolean hasParserForKey(SerializationT serializedKey)
Returns true if a parser for thisserializedKeyhas been registered.
-
parseKey
public <SerializationT extends Serialization> Key parseKey(SerializationT serializedKey, @Nullable SecretKeyAccess access) throws java.security.GeneralSecurityException
Parses the given serialization into a Key.This will look up a previously registered parser for the passed in
SerializationTclass, and the used object identifier (as indicated byserializedKey.getObjectIdentifier()), and then parse the object with this parsers.- Throws:
java.security.GeneralSecurityException
-
parseKeyWithLegacyFallback
public Key parseKeyWithLegacyFallback(ProtoKeySerialization protoKeySerialization, @Nullable SecretKeyAccess access) throws java.security.GeneralSecurityException
Returns a Key object from a protoKeySerialization, even if no parser has been registered.Falling back is useful because we want users to be able to call
#getAteven for key types for which we did not yet register a parser; in this case we simply fall back to return a LegacyProtoKey.- Throws:
java.security.GeneralSecurityException- if a parser is registered but parsing fails or required SecretKeyAccess is missing
-
hasSerializerForKey
public <KeyT extends Key,SerializationT extends Serialization> boolean hasSerializerForKey(KeyT key, java.lang.Class<SerializationT> serializationClass)
Returns true if a parser for thisserializedKeyhas been registered.
-
serializeKey
public <KeyT extends Key,SerializationT extends Serialization> SerializationT serializeKey(KeyT key, java.lang.Class<SerializationT> serializationClass, @Nullable SecretKeyAccess access) throws java.security.GeneralSecurityException
Serializes a given Key into a "SerializationT" object.This will look up a previously registered serializer for the requested
SerializationTclass and the passed in key type, and then call serializeKey on the result.- Throws:
java.security.GeneralSecurityException
-
hasParserForParameters
public <SerializationT extends Serialization> boolean hasParserForParameters(SerializationT serializedParameters)
Returns true if a parser for thisserializedKeyhas been registered.
-
parseParameters
public <SerializationT extends Serialization> Parameters parseParameters(SerializationT serializedParameters) throws java.security.GeneralSecurityException
Parses the given serialization into a Parameters object.This will look up a previously registered parser for the passed in
SerializationTclass, and the used object identifier (as indicated byserializedKey.getObjectIdentifier()), and then parse the object with this parsers.- Throws:
java.security.GeneralSecurityException
-
parseParametersWithLegacyFallback
public Parameters parseParametersWithLegacyFallback(ProtoParametersSerialization protoParametersSerialization) throws java.security.GeneralSecurityException
Returns a Parameters object from a protoKeySerialization, even if no parser has been registered.Falling back is useful because we need to have a parameters object even if no parser is registered (e.g. for when we create a Key from a key template/parameters name object).
- Throws:
java.security.GeneralSecurityException
-
hasSerializerForParameters
public <ParametersT extends Parameters,SerializationT extends Serialization> boolean hasSerializerForParameters(ParametersT parameters, java.lang.Class<SerializationT> serializationClass)
Returns true if a parser for thisserializedKeyhas been registered.
-
serializeParameters
public <ParametersT extends Parameters,SerializationT extends Serialization> SerializationT serializeParameters(ParametersT parameters, java.lang.Class<SerializationT> serializationClass) throws java.security.GeneralSecurityException
Serializes a given Parameters object into a "SerializationT" object.This will look up a previously registered serializer for the requested
SerializationTclass and the passed in key type, and then call serializeKey on the result.- Throws:
java.security.GeneralSecurityException
-
-