public abstract class KeyParser<SerializationT extends Serialization> extends Object
Serialization objects into Key objects of a certain kind.
This class should eventually be in Tinks public API -- however, it might still change before that.
| Modifier and Type | Class and Description |
|---|---|
static interface |
KeyParser.KeyParsingFunction<SerializationT extends Serialization>
A function which parses a key.
|
| Modifier and Type | Method and Description |
|---|---|
static <SerializationT extends Serialization> |
create(KeyParser.KeyParsingFunction<SerializationT> function,
Bytes objectIdentifier,
Class<SerializationT> serializationClass)
Creates a KeyParser object.
|
Bytes |
getObjectIdentifier()
Returns the
objectIdentifier for this serialization. |
Class<SerializationT> |
getSerializationClass() |
abstract Key |
parseKey(SerializationT serialization,
SecretKeyAccess access)
Parses a serialization into a key.
|
public abstract Key parseKey(SerializationT serialization, @Nullable SecretKeyAccess access) throws GeneralSecurityException
This function is usually called with a Serialization matching the result of getObjectIdentifier. However, implementations should check that this is the case.
GeneralSecurityExceptionpublic final Bytes getObjectIdentifier()
objectIdentifier for this serialization.
The object identifier is a unique identifier per registry for this object (in the standard
proto serialization, it is the typeUrl). In other words, when registering a KeyParser,
the registry will invoke this to get the handled object identifier. In order to parse an object
of type SerializationT, the registry will then obtain the objectIdentifier of
this serialization object, and call the parser corresponding to this object.
public final Class<SerializationT> getSerializationClass()
public static <SerializationT extends Serialization> KeyParser<SerializationT> create(KeyParser.KeyParsingFunction<SerializationT> function, Bytes objectIdentifier, Class<SerializationT> serializationClass)
In order to create a KeyParser object, one typically writes a function
class MyClass {
private static MyKey parse(MySerialization key, @Nullable SecretKeyAccess access)
throws GeneralSecurityException {
...
}
}
This function can then be used to create a KeyParser:
KeyParser<MyKey, MySerialization> parser =
KeyParser.create(MyClass::parse, objectIdentifier, MySerialization.class);
Note that calling this function twice will result in objects which are not equal according to
Object.equals, and hence cannot be used to re-register a previously registered object.function - The function used to parse a KeyobjectIdentifier - The identifier to be returned by getObjectIdentifier()serializationClass - The class object corresponding to SerializationT