Class KeyParser
- java.lang.Object
-
- com.google.crypto.tink.internal.KeyParser
-
public abstract class KeyParser 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.KeyParsingFunctionA function which parses a key.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static KeyParsercreate(KeyParser.KeyParsingFunction function, java.lang.String typeUrl)Creates a KeyParser object.java.lang.Class<ProtoKeySerialization>getSerializationClass()java.lang.StringgetTypeUrl()Returns theobjectIdentifierfor this serialization.abstract KeyparseKey(ProtoKeySerialization serialization, SecretKeyAccess access)Parses a serialization into a key.
-
-
-
Method Detail
-
parseKey
public abstract Key parseKey(ProtoKeySerialization 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
-
getTypeUrl
public final java.lang.String getTypeUrl()
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 typeProtoKeySerialization, the registry will then obtain theobjectIdentifierof this serialization object, and call the parser corresponding to this object.
-
getSerializationClass
public final java.lang.Class<ProtoKeySerialization> getSerializationClass()
-
create
public static KeyParser create(KeyParser.KeyParsingFunction function, java.lang.String typeUrl)
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(ProtoKeySerialization s, @Nullable SecretKeyAccess access) throws GeneralSecurityException { ... } }KeyParser:
Note that calling this function twice will result in objects which are not equal according toKeyParser parser = KeyParser.create(MyClass::parse, objectIdentifier);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 by#getObjectIdentifier
-
-