Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt HMAC to JWK RSA code style. #378

Merged
merged 1 commit into from Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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