Class LegacyKeyManagerImpl<P>

  • All Implemented Interfaces:
    KeyManager<P>

    public class LegacyKeyManagerImpl<P>
    extends java.lang.Object
    implements KeyManager<P>
    A composed KeyManager implements a KeyManager by accessing the internal specific registries.

    Tink offers Registry.getKeyManager in the public API. While this shouldn't be used by users, we still want to be backwards compatible for users which use it.

    In this class we use the global instances of the following classes to implement the KeyManager interface.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <P> KeyManager<P> create​(java.lang.String typeUrl, java.lang.Class<P> primitiveClass, com.google.crypto.tink.proto.KeyData.KeyMaterialType keyMaterialType, com.google.protobuf.Parser<? extends com.google.protobuf.MessageLite> protobufKeyParser)  
      static <P> PrivateKeyManager<P> createPrivateKeyManager​(java.lang.String typeUrl, java.lang.Class<P> primitiveClass, com.google.protobuf.Parser<? extends com.google.protobuf.MessageLite> protobufKeyParser)  
      boolean doesSupport​(java.lang.String typeUrl)
      Returns true iff this KeyManager supports key type identified by typeUrl.
      java.lang.String getKeyType()
      Returns the type URL that identifies the key type of keys managed by this KeyManager.
      P getPrimitive​(com.google.protobuf.ByteString serializedKey)
      Constructs an instance of P for the key given in serializedKey, which must be a serialized key protocol buffer handled by this manager.
      P getPrimitive​(com.google.protobuf.MessageLite key)
      Constructs an instance of P for the key given in key.
      java.lang.Class<P> getPrimitiveClass()
      Returns the primitive class object of the P.
      int getVersion()
      Returns the version number of this KeyManager.
      com.google.protobuf.MessageLite newKey​(com.google.protobuf.ByteString serializedKeyFormat)
      Generates a new key according to specification in serializedKeyFormat, which must be a serialized key format protocol buffer handled by this manager.
      com.google.protobuf.MessageLite newKey​(com.google.protobuf.MessageLite keyFormat)
      Generates a new key according to specification in keyFormat.
      com.google.crypto.tink.proto.KeyData newKeyData​(com.google.protobuf.ByteString serializedKeyFormat)
      Generates a new KeyData according to specification in serializedKeyFormat.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public static <P> KeyManager<P> create​(java.lang.String typeUrl,
                                               java.lang.Class<P> primitiveClass,
                                               com.google.crypto.tink.proto.KeyData.KeyMaterialType keyMaterialType,
                                               com.google.protobuf.Parser<? extends com.google.protobuf.MessageLite> protobufKeyParser)
      • getPrimitive

        public P getPrimitive​(com.google.protobuf.ByteString serializedKey)
                       throws java.security.GeneralSecurityException
        Description copied from interface: KeyManager
        Constructs an instance of P for the key given in serializedKey, which must be a serialized key protocol buffer handled by this manager.

        For primitives of type Mac, Aead, PublicKeySign, PublicKeyVerify, DeterministicAead, HybridEncrypt, and HybridDecrypt this should be a primitive which ignores the output prefix and assumes "RAW".

        Specified by:
        getPrimitive in interface KeyManager<P>
        Returns:
        the new constructed P
        Throws:
        java.security.GeneralSecurityException - if the key given in serializedKey is corrupted or not supported
      • getPrimitive

        public final P getPrimitive​(com.google.protobuf.MessageLite key)
                             throws java.security.GeneralSecurityException
        Description copied from interface: KeyManager
        Constructs an instance of P for the key given in key.

        For primitives of type Mac, Aead, PublicKeySign, PublicKeyVerify, DeterministicAead, HybridEncrypt, and HybridDecrypt this should be a primitive which ignores the output prefix and assumes "RAW".

        This method is not used by Tink. It does not need to be implemented.

        Specified by:
        getPrimitive in interface KeyManager<P>
        Returns:
        the new constructed P
        Throws:
        java.security.GeneralSecurityException - if the key given in key is corrupted or not supported
      • newKey

        public final com.google.protobuf.MessageLite newKey​(com.google.protobuf.ByteString serializedKeyFormat)
                                                     throws java.security.GeneralSecurityException
        Description copied from interface: KeyManager
        Generates a new key according to specification in serializedKeyFormat, which must be a serialized key format protocol buffer handled by this manager.

        This method is not used by Tink anymore. It does not need to be implemented.

        Specified by:
        newKey in interface KeyManager<P>
        Returns:
        the new generated key
        Throws:
        java.security.GeneralSecurityException - if the specified format is wrong or not supported
      • newKey

        public final com.google.protobuf.MessageLite newKey​(com.google.protobuf.MessageLite keyFormat)
                                                     throws java.security.GeneralSecurityException
        Description copied from interface: KeyManager
        Generates a new key according to specification in keyFormat.

        This method is only used by Registry.newKey which is deprecated and not used by Tink anymore. This method does not need to be implemented.

        Specified by:
        newKey in interface KeyManager<P>
        Returns:
        the new generated key
        Throws:
        java.security.GeneralSecurityException - if the specified format is wrong or not supported
      • doesSupport

        public final boolean doesSupport​(java.lang.String typeUrl)
        Description copied from interface: KeyManager
        Returns true iff this KeyManager supports key type identified by typeUrl.

        This method is not used by Tink anymore. It does not need to be implemented.

        Specified by:
        doesSupport in interface KeyManager<P>
      • getKeyType

        public final java.lang.String getKeyType()
        Description copied from interface: KeyManager
        Returns the type URL that identifies the key type of keys managed by this KeyManager.
        Specified by:
        getKeyType in interface KeyManager<P>
      • getVersion

        public int getVersion()
        Description copied from interface: KeyManager
        Returns the version number of this KeyManager.

        This method is not used by Tink anymore. It does not need to be implemented.

        Specified by:
        getVersion in interface KeyManager<P>
      • newKeyData

        public final com.google.crypto.tink.proto.KeyData newKeyData​(com.google.protobuf.ByteString serializedKeyFormat)
                                                              throws java.security.GeneralSecurityException
        Description copied from interface: KeyManager
        Generates a new KeyData according to specification in serializedKeyFormat.
        Specified by:
        newKeyData in interface KeyManager<P>
        Returns:
        the new generated key
        Throws:
        java.security.GeneralSecurityException - if the specified format is wrong or not supported
      • getPrimitiveClass

        public final java.lang.Class<P> getPrimitiveClass()
        Description copied from interface: KeyManager
        Returns the primitive class object of the P. Should be implemented as return P.class; when implementing a key manager for primitive {$code P}.
        Specified by:
        getPrimitiveClass in interface KeyManager<P>
        Returns:
        P.class
      • createPrivateKeyManager

        public static <P> PrivateKeyManager<P> createPrivateKeyManager​(java.lang.String typeUrl,
                                                                       java.lang.Class<P> primitiveClass,
                                                                       com.google.protobuf.Parser<? extends com.google.protobuf.MessageLite> protobufKeyParser)