Class KeyParser<SerializationT extends Serialization>


  • public abstract class KeyParser<SerializationT extends Serialization>
    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​(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 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 SerializationT, the registry will then obtain the objectIdentifier of this serialization object, and call the parser corresponding to this object.

      • getSerializationClass

        public final java.lang.Class<SerializationT> getSerializationClass()
      • create

        public static <SerializationT extends SerializationKeyParser<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

        
         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.
        Parameters:
        function - The function used to parse a Key
        objectIdentifier - The identifier to be returned by getObjectIdentifier()
        serializationClass - The class object corresponding to SerializationT