Class KeyParser<SerializationT extends Serialization>
- java.lang.Object
-
- com.google.crypto.tink.internal.KeyParser<SerializationT>
-
public abstract class KeyParser<SerializationT extends Serialization> extends java.lang.ObjectParsesSerializationobjects intoKeyobjects of a certain kind.This class should eventually be in Tinks public API -- however, it might still change before that.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceKeyParser.KeyParsingFunction<SerializationT extends Serialization>A function which parses a key.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <SerializationT extends Serialization>
KeyParser<SerializationT>create(KeyParser.KeyParsingFunction<SerializationT> function, Bytes objectIdentifier, java.lang.Class<SerializationT> serializationClass)Creates a KeyParser object.BytesgetObjectIdentifier()Returns theobjectIdentifierfor this serialization.java.lang.Class<SerializationT>getSerializationClass()abstract KeyparseKey(SerializationT serialization, SecretKeyAccess access)Parses a serialization into a key.
-
-
-
Method Detail
-
parseKey
public abstract Key parseKey(SerializationT serialization, @Nullable SecretKeyAccess access) throws java.security.GeneralSecurityException
Parses a serialization into a key.This function is usually called with a Serialization matching the result of
getObjectIdentifier(). However, implementations should check that this is the case.- Throws:
java.security.GeneralSecurityException
-
getObjectIdentifier
public final Bytes getObjectIdentifier()
Returns theobjectIdentifierfor 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 typeSerializationT, the registry will then obtain theobjectIdentifierof this serialization object, and call the parser corresponding to this object.
-
getSerializationClass
public final java.lang.Class<SerializationT> getSerializationClass()
-
create
public static <SerializationT extends Serialization> KeyParser<SerializationT> create(KeyParser.KeyParsingFunction<SerializationT> function, Bytes objectIdentifier, java.lang.Class<SerializationT> serializationClass)
Creates a KeyParser object.In order to create a KeyParser object, one typically writes a function
This function can then be used to create aclass MyClass { private static MyKey parse(MySerialization key, @Nullable SecretKeyAccess access) throws GeneralSecurityException { ... } }KeyParser:
Note that calling this function twice will result in objects which are not equal according toKeyParser<MyKey, MySerialization> parser = KeyParser.create(MyClass::parse, objectIdentifier, MySerialization.class);Object.equals, and hence cannot be used to re-register a previously registered object.- Parameters:
function- The function used to parse a KeyobjectIdentifier- The identifier to be returned bygetObjectIdentifier()serializationClass- The class object corresponding toSerializationT
-
-