Sha256: 7f7a82cb268575283aa70cb736f641b24ae45d2344580dd7ff812e9dc9cfed5e
Contents?: true
Size: 1.52 KB
Versions: 3
Compression:
Stored size: 1.52 KB
Contents
# frozen_string_literal: true begin require 'rbnacl' rescue LoadError raise if defined?(RbNaCl) end require 'openssl' require 'jwt/security_utils' require 'jwt/algos/hmac' require 'jwt/algos/eddsa' require 'jwt/algos/ecdsa' require 'jwt/algos/rsa' require 'jwt/algos/ps' require 'jwt/algos/none' require 'jwt/algos/unsupported' require 'jwt/algos/algo_wrapper' module JWT module Algos extend self ALGOS = [Algos::Ecdsa, Algos::Rsa, Algos::Eddsa, Algos::Ps, Algos::None, Algos::Unsupported].tap do |l| if ::JWT.rbnacl_6_or_greater? require_relative 'algos/hmac_rbnacl' l.unshift(Algos::HmacRbNaCl) elsif ::JWT.rbnacl? require_relative 'algos/hmac_rbnacl_fixed' l.unshift(Algos::HmacRbNaClFixed) else l.unshift(Algos::Hmac) end end.freeze def find(algorithm) indexed[algorithm && algorithm.downcase] end def create(algorithm) Algos::AlgoWrapper.new(*find(algorithm)) end def implementation?(algorithm) (algorithm.respond_to?(:valid_alg?) && algorithm.respond_to?(:verify)) || (algorithm.respond_to?(:alg) && algorithm.respond_to?(:sign)) end private def indexed @indexed ||= begin fallback = [nil, Algos::Unsupported] ALGOS.each_with_object(Hash.new(fallback)) do |cls, hash| cls.const_get(:SUPPORTED).each do |alg| hash[alg.downcase] = [alg, cls] end 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.rb |
jwt-2.7.0 | lib/jwt/algos.rb |
jwt-2.6.0 | lib/jwt/algos.rb |