Sha256: 5081a61a08e0779aef0e926026cf897e444007c326020c8554915090424e6ca3

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module JWT
  module Algos
    module Ps
      # RSASSA-PSS signing algorithms

      module_function

      SUPPORTED = %w[PS256 PS384 PS512].freeze

      def sign(algorithm, msg, key)
        require_openssl!

        key_class = key.class

        raise EncodeError, "The given key is a #{key_class}. It has to be an OpenSSL::PKey::RSA instance." if key_class == String

        translated_algorithm = algorithm.sub('PS', 'sha')

        key.sign_pss(translated_algorithm, msg, salt_length: :digest, mgf1_hash: translated_algorithm)
      end

      def verify(algorithm, public_key, signing_input, signature)
        require_openssl!

        SecurityUtils.verify_ps(algorithm, public_key, signing_input, signature)
      end

      def require_openssl!
        if Object.const_defined?('OpenSSL')
          if ::Gem::Version.new(OpenSSL::VERSION) < ::Gem::Version.new('2.1')
            raise JWT::RequiredDependencyError, "You currently have OpenSSL #{OpenSSL::VERSION}. PS support requires >= 2.1"
          end
        else
          raise JWT::RequiredDependencyError, 'PS signing requires OpenSSL +2.1'
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/jwt-2.7.0/lib/jwt/algos/ps.rb
jwt-2.7.0 lib/jwt/algos/ps.rb
jwt-2.6.0 lib/jwt/algos/ps.rb