Sha256: d6151733e004e78634893841bc15413a15f5c7409fc274ad034724343a7581b2

Contents?: true

Size: 775 Bytes

Versions: 3

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

module JWT
  module Algos
    class AlgoWrapper
      attr_reader :alg, :cls

      def initialize(alg, cls)
        @alg = alg
        @cls = cls
      end

      def valid_alg?(alg_to_check)
        alg.casecmp(alg_to_check)&.zero? == true
      end

      def sign(data:, signing_key:)
        cls.sign(alg, data, signing_key)
      end

      def verify(data:, signature:, verification_key:)
        cls.verify(alg, verification_key, data, signature)
      rescue OpenSSL::PKey::PKeyError # These should be moved to the algorithms that actually need this, but left here to ensure nothing will break.
        raise JWT::VerificationError, 'Signature verification raised'
      ensure
        OpenSSL.errors.clear
      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/algo_wrapper.rb
jwt-2.7.0 lib/jwt/algos/algo_wrapper.rb
jwt-2.6.0 lib/jwt/algos/algo_wrapper.rb