Class KeySerializer<KeyT extends Key>


  • public abstract class KeySerializer<KeyT extends Key>
    extends java.lang.Object
    Serializes Key objects into Serialization objects of a certain kind.

    This class should eventually be in Tinks public API -- however, it might still change before that.

    • Method Detail

      • serializeKey

        public abstract ProtoKeySerialization serializeKey​(KeyT key,
                                                           @Nullable
                                                           SecretKeyAccess access)
                                                    throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • getKeyClass

        public java.lang.Class<KeyT> getKeyClass()
      • create

        public static <KeyT extends Key> KeySerializer<KeyT> create​(KeySerializer.KeySerializationFunction<KeyT> function,
                                                                    java.lang.Class<KeyT> keyClass)
        Creates a KeySerializer object.

        In order to create a KeySerializer object, one typically writes a function

        
         class MyClass {
           private static ProtoKeySerialization serialize(MyKey key, @Nullable SecretKeyAccess access)
                     throws GeneralSecurityException {
             ...
           }
         }
         
        This function can then be used to create a KeySerializer:
        
         KeySerializer<MyKey> serializer =
             KeySerializer.create(MyClass::serialize, MyKey.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.