class JWT::JWK::HMAC
Constants
- HMAC_KEY_ELEMENTS
- HMAC_PRIVATE_KEY_ELEMENTS
- HMAC_PUBLIC_KEY_ELEMENTS
- KTY
- KTYS
Public Class Methods
Source
# File lib/jwt/jwk/hmac.rb, line 13 def initialize(key, params = nil, options = {}) params ||= {} # For backwards compatibility when kid was a String params = { kid: params } if params.is_a?(String) key_params = extract_key_params(key) params = params.transform_keys(&:to_sym) check_jwk(key_params, params) super(options, key_params.merge(params)) end
Calls superclass method
Public Instance Methods
Source
# File lib/jwt/jwk/hmac.rb, line 64 def []=(key, value) raise ArgumentError, 'cannot overwrite cryptographic key attributes' if HMAC_KEY_ELEMENTS.include?(key.to_sym) super(key, value) end
Calls superclass method
Source
# File lib/jwt/jwk/hmac.rb, line 48 def export(options = {}) exported = parameters.clone exported.reject! { |k, _| HMAC_PRIVATE_KEY_ELEMENTS.include? k } unless private? && options[:include_private] == true exported end
Source
# File lib/jwt/jwk/hmac.rb, line 58 def key_digest sequence = OpenSSL::ASN1::Sequence([OpenSSL::ASN1::UTF8String.new(signing_key), OpenSSL::ASN1::UTF8String.new(KTY)]) OpenSSL::Digest::SHA256.hexdigest(sequence.to_der) end
Source
# File lib/jwt/jwk/hmac.rb, line 54 def members HMAC_KEY_ELEMENTS.each_with_object({}) { |i, h| h[i] = self[i] } end
Private Instance Methods
Source
# File lib/jwt/jwk/hmac.rb, line 89 def check_jwk(keypair, params) raise ArgumentError, 'cannot overwrite cryptographic key attributes' unless (HMAC_KEY_ELEMENTS & params.keys).empty? raise JWT::JWKError, "Incorrect 'kty' value: #{keypair[:kty]}, expected #{KTY}" unless keypair[:kty] == KTY raise JWT::JWKError, 'Key format is invalid for HMAC' unless keypair[:k] end
Source
# File lib/jwt/jwk/hmac.rb, line 76 def extract_key_params(key) case key when JWT::JWK::HMAC key.export(include_private: true) when String # Accept String key as input { kty: KTY, k: key } when Hash key.transform_keys(&:to_sym) else raise ArgumentError, 'key must be of type String or Hash with key parameters' end end