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()booleanhasParserForKey(ProtoKeySerialization serializedKey)Returns true if a parser for thisserializedKeyhas been registered.booleanhasParserForParameters(ProtoParametersSerialization serializedParameters)Returns true if a parser for thisserializedKeyhas been registered.<KeyT extends Key>
booleanhasSerializerForKey(KeyT key, java.lang.Class<?> serializationClass)Returns true if a parser for thisserializedKeyhas been registered.<ParametersT extends Parameters>
booleanhasSerializerForParameters(ParametersT parameters, java.lang.Class<?> serializationClass)Returns true if a parser for thisserializedKeyhas been registered.KeyparseKey(ProtoKeySerialization 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.ParametersparseParameters(ProtoParametersSerialization 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.voidregisterKeyParser(KeyParser parser)Registers a key parser for later use inparseKey(com.google.crypto.tink.ProtoKeySerialization, com.google.crypto.tink.SecretKeyAccess).<KeyT extends Key>
voidregisterKeySerializer(KeySerializer<KeyT> serializer)Registers a key serializer for later use inserializeKey(KeyT, com.google.crypto.tink.SecretKeyAccess).voidregisterParametersParser(ParametersParser parser)Registers a key parser for later use inparseKey(com.google.crypto.tink.ProtoKeySerialization, com.google.crypto.tink.SecretKeyAccess).<ParametersT extends Parameters>
voidregisterParametersSerializer(ParametersSerializer<ParametersT> serializer)Registers a key serializer for later use inserializeKey(KeyT, com.google.crypto.tink.SecretKeyAccess).<KeyT extends Key>
ProtoKeySerializationserializeKey(KeyT key, SecretKeyAccess access)Serializes a given Key into a "SerializationT" object.<ParametersT extends Parameters>
ProtoParametersSerializationserializeParameters(ParametersT parameters)Serializes a given Parameters object into a "SerializationT" object.
-
-
-
Method Detail
-
globalInstance
public static MutableSerializationRegistry globalInstance()
-
registerKeySerializer
public <KeyT extends Key> void registerKeySerializer(KeySerializer<KeyT> serializer) throws java.security.GeneralSecurityException
Registers a key serializer for later use inserializeKey(KeyT, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
serializeKey(KeyT, 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 void registerKeyParser(KeyParser parser) throws java.security.GeneralSecurityException
Registers a key parser for later use inparseKey(com.google.crypto.tink.ProtoKeySerialization, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
parseKey(com.google.crypto.tink.ProtoKeySerialization, 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> void registerParametersSerializer(ParametersSerializer<ParametersT> serializer) throws java.security.GeneralSecurityException
Registers a key serializer for later use inserializeKey(KeyT, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
serializeKey(KeyT, 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 void registerParametersParser(ParametersParser parser) throws java.security.GeneralSecurityException
Registers a key parser for later use inparseKey(com.google.crypto.tink.ProtoKeySerialization, com.google.crypto.tink.SecretKeyAccess).This registers a key serializer which can later be used to serialize a key by calling
parseKey(com.google.crypto.tink.ProtoKeySerialization, 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 boolean hasParserForKey(ProtoKeySerialization serializedKey)
Returns true if a parser for thisserializedKeyhas been registered.
-
parseKey
public Key parseKey(ProtoKeySerialization 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> boolean hasSerializerForKey(KeyT key, java.lang.Class<?> serializationClass)
Returns true if a parser for thisserializedKeyhas been registered.
-
serializeKey
public <KeyT extends Key> ProtoKeySerialization serializeKey(KeyT key, @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 boolean hasParserForParameters(ProtoParametersSerialization serializedParameters)
Returns true if a parser for thisserializedKeyhas been registered.
-
parseParameters
public Parameters parseParameters(ProtoParametersSerialization 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> boolean hasSerializerForParameters(ParametersT parameters, java.lang.Class<?> serializationClass)
Returns true if a parser for thisserializedKeyhas been registered.
-
serializeParameters
public <ParametersT extends Parameters> ProtoParametersSerialization serializeParameters(ParametersT parameters) 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
-
-