Class: JWT::JWK::EC
Overview
JWK representation for Elliptic Curve (EC) keys
Constant Summary
collapse
- KTY =
rubocop:disable Metrics/ClassLength
'EC'
- KTYS =
[KTY, OpenSSL::PKey::EC, JWT::JWK::EC].freeze
- BINARY =
2
- EC_PUBLIC_KEY_ELEMENTS =
%i[kty crv x y].freeze
- EC_PRIVATE_KEY_ELEMENTS =
%i[d].freeze
- EC_KEY_ELEMENTS =
(EC_PRIVATE_KEY_ELEMENTS + EC_PUBLIC_KEY_ELEMENTS).freeze
- ZERO_BYTE =
"\0".b.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from KeyBase
#<=>, #==, #[], #hash, inherited, #kid
Constructor Details
permalink
#initialize(key, params = nil, options = {}) ⇒ EC
Returns a new instance of EC.
[View source] [
View on GitHub]
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/jwt/jwk/ec.rb', line 17
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_params!(key_params, params)
super(options, key_params.merge(params))
end
|
Class Method Details
permalink
.to_openssl_curve(crv) ⇒ Object
[View source] [
View on GitHub]
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/jwt/jwk/ec.rb', line 235
def to_openssl_curve(crv)
case crv
when 'P-256' then 'prime256v1'
when 'P-384' then 'secp384r1'
when 'P-521' then 'secp521r1'
when 'P-256K' then 'secp256k1'
else raise JWT::JWKError, 'Invalid curve provided'
end
end
|
Instance Method Details
permalink
#[]=(key, value) ⇒ Object
[View source] [
View on GitHub]
68
69
70
71
72
|
# File 'lib/jwt/jwk/ec.rb', line 68
def []=(key, value)
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if EC_KEY_ELEMENTS.include?(key.to_sym)
super(key, value)
end
|
permalink
#export(options = {}) ⇒ Object
[View source] [
View on GitHub]
55
56
57
58
59
|
# File 'lib/jwt/jwk/ec.rb', line 55
def export(options = {})
exported = parameters.clone
exported.reject! { |k, _| EC_PRIVATE_KEY_ELEMENTS.include? k } unless private? && options[:include_private] == true
exported
end
|
permalink
#key_digest ⇒ Object
[View source] [
View on GitHub]
61
62
63
64
65
66
|
# File 'lib/jwt/jwk/ec.rb', line 61
def key_digest
_crv, x_octets, y_octets = keypair_components(ec_key)
sequence = OpenSSL::ASN1::Sequence([OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(x_octets, BINARY)),
OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(y_octets, BINARY))])
OpenSSL::Digest::SHA256.hexdigest(sequence.to_der)
end
|