Skip to content

Commit

Permalink
Adapt HMAC to JWK RSA code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
phlegx authored and excpt committed Oct 5, 2020
1 parent 98ae462 commit ac4f4e8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/jwt/jwk/hmac.rb
Expand Up @@ -9,7 +9,7 @@ def initialize(keypair, kid = nil)
raise ArgumentError, 'keypair must be of type String' unless keypair.is_a?(String)

super
@kid = kid || generate_kid(@keypair)
@kid = kid || generate_kid
end

def private?
Expand All @@ -22,22 +22,22 @@ def public_key

# See https://tools.ietf.org/html/rfc7517#appendix-A.3
def export(options = {})
ret = {
exported_hash = {
kty: KTY,
kid: kid
}

return ret unless private? && options[:include_private] == true
return exported_hash unless private? && options[:include_private] == true

ret.merge(
exported_hash.merge(
k: keypair
)
end

private

def generate_kid(hmac_key)
sequence = OpenSSL::ASN1::Sequence([OpenSSL::ASN1::UTF8String.new(hmac_key),
def generate_kid
sequence = OpenSSL::ASN1::Sequence([OpenSSL::ASN1::UTF8String.new(keypair),
OpenSSL::ASN1::UTF8String.new(KTY)])
OpenSSL::Digest::SHA256.hexdigest(sequence.to_der)
end
Expand Down

0 comments on commit ac4f4e8

Please sign in to comment.