Class: JWT::JWK::HMAC
Overview
Constant Summary
collapse
- KTY =
'oct'
- KTYS =
[KTY, String, JWT::JWK::HMAC].freeze
- HMAC_PUBLIC_KEY_ELEMENTS =
%i[kty].freeze
- HMAC_PRIVATE_KEY_ELEMENTS =
%i[k].freeze
- HMAC_KEY_ELEMENTS =
(HMAC_PRIVATE_KEY_ELEMENTS + HMAC_PUBLIC_KEY_ELEMENTS).freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from KeyBase
#<=>, #==, #[], #hash, inherited, #kid
Constructor Details
permalink
#initialize(key, params = nil, options = {}) ⇒ HMAC
Returns a new instance of HMAC.
[View source] [
View on GitHub]
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/jwt/jwk/hmac.rb', line 13
def initialize(key, params = nil, options = {})
params ||= {}
params = { kid: params } if params.is_a?(String)
key_params = (key)
params = params.transform_keys(&:to_sym)
check_jwk(key_params, params)
super(options, key_params.merge(params))
end
|
Instance Method Details
permalink
#[]=(key, value) ⇒ Object
[View source] [
View on GitHub]
64
65
66
67
68
|
# 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
|
permalink
#export(options = {}) ⇒ Object
[View source] [
View on GitHub]
48
49
50
51
52
|
# 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
|
permalink
#key_digest ⇒ Object
[View source] [
View on GitHub]
58
59
60
61
62
|
# 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
|