public final class MutableSerializationRegistry extends Object
SerializationRegistry.
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 and Description |
|---|
MutableSerializationRegistry() |
| Modifier and Type | Method and Description |
|---|---|
static MutableSerializationRegistry |
globalInstance() |
<SerializationT extends Serialization> |
hasParserForKey(SerializationT serializedKey)
Returns true if a parser for this
serializedKey has been registered. |
<SerializationT extends Serialization> |
hasParserForParameters(SerializationT serializedParameters)
Returns true if a parser for this
serializedKey has been registered. |
<KeyT extends Key,SerializationT extends Serialization> |
hasSerializerForKey(KeyT key,
Class<SerializationT> serializationClass)
Returns true if a parser for this
serializedKey has been registered. |
<ParametersT extends Parameters,SerializationT extends Serialization> |
hasSerializerForParameters(ParametersT parameters,
Class<SerializationT> serializationClass)
Returns true if a parser for this
serializedKey has been registered. |
<SerializationT extends Serialization> |
parseKey(SerializationT serializedKey,
SecretKeyAccess access)
Parses the given serialization into a Key.
|
Key |
parseKeyWithLegacyFallback(ProtoKeySerialization protoKeySerialization,
SecretKeyAccess access)
Returns a Key object from a protoKeySerialization, even if no parser has been registered.
|
<SerializationT extends Serialization> |
parseParameters(SerializationT serializedParameters)
Parses the given serialization into a Parameters object.
|
Parameters |
parseParametersWithLegacyFallback(ProtoParametersSerialization protoParametersSerialization)
Returns a Parameters object from a protoKeySerialization, even if no parser has been
registered.
|
<SerializationT extends Serialization> |
registerKeyParser(KeyParser<SerializationT> parser)
Registers a key parser for later use in
parseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess). |
<KeyT extends Key,SerializationT extends Serialization> |
registerKeySerializer(KeySerializer<KeyT,SerializationT> serializer)
Registers a key serializer for later use in
serializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess). |
<SerializationT extends Serialization> |
registerParametersParser(ParametersParser<SerializationT> parser)
Registers a key parser for later use in
parseKey(SerializationT, com.google.crypto.tink.SecretKeyAccess). |
<ParametersT extends Parameters,SerializationT extends Serialization> |
registerParametersSerializer(ParametersSerializer<ParametersT,SerializationT> serializer)
Registers a key serializer for later use in
serializeKey(KeyT, java.lang.Class<SerializationT>, com.google.crypto.tink.SecretKeyAccess). |
<KeyT extends Key,SerializationT extends Serialization> |
serializeKey(KeyT key,
Class<SerializationT> serializationClass,
SecretKeyAccess access)
Serializes a given Key into a "SerializationT" object.
|
<ParametersT extends Parameters,SerializationT extends Serialization> |
serializeParameters(ParametersT parameters,
Class<SerializationT> serializationClass)
Serializes a given Parameters object into a "SerializationT" object.
|
public static MutableSerializationRegistry globalInstance()
public <KeyT extends Key,SerializationT extends Serialization> void registerKeySerializer(KeySerializer<KeyT,SerializationT> serializer) throws GeneralSecurityException
serializeKey(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.
GeneralSecurityExceptionpublic <SerializationT extends Serialization> void registerKeyParser(KeyParser<SerializationT> parser) throws GeneralSecurityException
parseKey(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.
GeneralSecurityExceptionpublic <ParametersT extends Parameters,SerializationT extends Serialization> void registerParametersSerializer(ParametersSerializer<ParametersT,SerializationT> serializer) throws GeneralSecurityException
serializeKey(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.
GeneralSecurityExceptionpublic <SerializationT extends Serialization> void registerParametersParser(ParametersParser<SerializationT> parser) throws GeneralSecurityException
parseKey(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.
GeneralSecurityExceptionpublic <SerializationT extends Serialization> boolean hasParserForKey(SerializationT serializedKey)
serializedKey has been registered.public <SerializationT extends Serialization> Key parseKey(SerializationT serializedKey, @Nullable SecretKeyAccess access) throws GeneralSecurityException
This will look up a previously registered parser for the passed in SerializationT
class, and the used object identifier (as indicated by serializedKey.getObjectIdentifier()), and then parse the object with this parsers.
GeneralSecurityExceptionpublic Key parseKeyWithLegacyFallback(ProtoKeySerialization protoKeySerialization, SecretKeyAccess access) throws GeneralSecurityException
Falling back is useful because we want users to be able to call #getAt even for key
types for which we did not yet register a parser; in this case we simply fall back to return a
LegacyProtoKey.
This always requires SecretKeyAccess.
GeneralSecurityException - if a parser is registered but parsing fails.public <KeyT extends Key,SerializationT extends Serialization> boolean hasSerializerForKey(KeyT key, Class<SerializationT> serializationClass)
serializedKey has been registered.public <KeyT extends Key,SerializationT extends Serialization> SerializationT serializeKey(KeyT key, Class<SerializationT> serializationClass, @Nullable SecretKeyAccess access) throws GeneralSecurityException
This will look up a previously registered serializer for the requested SerializationT class and the passed in key type, and then call serializeKey on the result.
GeneralSecurityExceptionpublic <SerializationT extends Serialization> boolean hasParserForParameters(SerializationT serializedParameters)
serializedKey has been registered.public <SerializationT extends Serialization> Parameters parseParameters(SerializationT serializedParameters) throws GeneralSecurityException
This will look up a previously registered parser for the passed in SerializationT
class, and the used object identifier (as indicated by serializedKey.getObjectIdentifier()), and then parse the object with this parsers.
GeneralSecurityExceptionpublic Parameters parseParametersWithLegacyFallback(ProtoParametersSerialization protoParametersSerialization)
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).
public <ParametersT extends Parameters,SerializationT extends Serialization> boolean hasSerializerForParameters(ParametersT parameters, Class<SerializationT> serializationClass)
serializedKey has been registered.public <ParametersT extends Parameters,SerializationT extends Serialization> SerializationT serializeParameters(ParametersT parameters, Class<SerializationT> serializationClass) throws GeneralSecurityException
This will look up a previously registered serializer for the requested SerializationT class and the passed in key type, and then call serializeKey on the result.
GeneralSecurityException