Class KeyParser


  • public abstract class KeyParser
    extends java.lang.Object
    Parses 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.

    • 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 the 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 ProtoKeySerialization, the registry will then obtain the objectIdentifier of this serialization object, and call the parser corresponding to this object.

      • 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

        
         class MyClass {
           private static MyKey parse(ProtoKeySerialization s, @Nullable SecretKeyAccess access)
                     throws GeneralSecurityException {
             ...
           }
         }
         
        This function can then be used to create a KeyParser:
        
         KeyParser parser =
               KeyParser.create(MyClass::parse, objectIdentifier);
         
        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.
        Parameters:
        function - The function used to parse a Key
        objectIdentifier - The identifier to be returned by #getObjectIdentifier