Class AlgorithmRegistry


  • public class AlgorithmRegistry
    extends Object
    A registry of AlgorithmDescriptor instances, to support various use cases for working with algorithm URIs.
    • Constructor Detail

      • AlgorithmRegistry

        public AlgorithmRegistry()
        Constructor.
    • Method Detail

      • get

        @Nullable
        public AlgorithmDescriptor get​(@Nullable
                                       String algorithmURI)
        Get the algorithm descriptor instance associated with the specified algorithm URI.
        Parameters:
        algorithmURI - the algorithm URI to resolve
        Returns:
        the resolved algorithm descriptor or null
      • isRuntimeSupported

        public boolean isRuntimeSupported​(@Nullable
                                          String algorithmURI)
        Retrieve indication of whether the runtime environment supports the algorithm.

        This evaluation is performed dynamically when the algorithm is registered.

        Parameters:
        algorithmURI - the algorithm URI to evaluate
        Returns:
        true if the algorithm is supported by the current runtime environment, false otherwise
      • clear

        public void clear()
        Clear all registered algorithms.
      • register

        public void register​(@Nonnull
                             AlgorithmDescriptor descriptor)
        Register an algorithm.
        Parameters:
        descriptor - the algorithm
      • deregister

        public void deregister​(@Nonnull
                               AlgorithmDescriptor descriptor)
        Deregister an algorithm.
        Parameters:
        descriptor - the algorithm
      • deregister

        public void deregister​(@Nonnull
                               String uri)
        Deregister an algorithm.
        Parameters:
        uri - the algorithm URI
      • getDigestAlgorithm

        @Nullable
        public DigestAlgorithm getDigestAlgorithm​(@Nonnull
                                                  String digestMethod)
        Lookup a digest method algorithm descriptor by the JCA digest method ID.
        Parameters:
        digestMethod - the JCA digest method ID.
        Returns:
        the algorithm descriptor, or null
      • getSignatureAlgorithm

        @Nullable
        public SignatureAlgorithm getSignatureAlgorithm​(@Nonnull
                                                        String keyType,
                                                        @Nonnull
                                                        String digestMethod)
        Lookup a signature algorithm descriptor by the JCA key algorithm and digest method IDs.
        Parameters:
        keyType - the JCA key algorithm ID.
        digestMethod - the JCA digest method ID.
        Returns:
        the algorithm descriptor, or null
      • index

        private void index​(AlgorithmDescriptor descriptor)
        Add the algorithm descriptor to the indexes which support the various lookup methods available via the registry's API.
        Parameters:
        descriptor - the algorithm
      • deindex

        private void deindex​(AlgorithmDescriptor descriptor)
        Remove the algorithm descriptor from the indexes which support the various lookup methods available via the registry's API.
        Parameters:
        descriptor - the algorithm
      • checkRuntimeSupports

        private boolean checkRuntimeSupports​(AlgorithmDescriptor descriptor)
        Evaluate whether the algorithm is supported by the current runtime environment.
        Parameters:
        descriptor - the algorithm
        Returns:
        true if runtime supports the algorithm, false otherwise
      • checkCipherSupportedKeyLength

        private boolean checkCipherSupportedKeyLength​(AlgorithmDescriptor descriptor)
                                               throws NoSuchAlgorithmException
        Check if the key length of the specified Cipher-based algorithm, if known, is supported by the current runtime.
        Parameters:
        descriptor - the algorithm
        Returns:
        true if key length supported, false otherwise
        Throws:
        NoSuchAlgorithmException - if the associated JCA algorithm is not supported by the runtime
      • checkSpecialCasesRuntimeSupport

        private boolean checkSpecialCasesRuntimeSupport​(AlgorithmDescriptor descriptor)
        Check for special cases of runtime support which failed the initial simple service class load check.
        Parameters:
        descriptor - the algorithm
        Returns:
        true if algorithm is supported by the runtime environment, false otherwise