Sha256: 3ca9dba6862dca6e5426904535e104964e20228087f2b379b2eb475ede693f27

Contents?: true

Size: 532 Bytes

Versions: 3

Compression:

Stored size: 532 Bytes

Contents

module JSON
  class JWK < Hash
    def initialize(public_key, options = {})
      replace encode(public_key, options)
    end

    private

    def encode(public_key, options = {})
      hash = case public_key
      when OpenSSL::PKey::RSA
        {
          alg: :RSA,
          exp: UrlSafeBase64.encode64(public_key.e.to_s(2)),
          mod: UrlSafeBase64.encode64(public_key.n.to_s(2))
        }
      else
        raise "Only RSA is supported now"
      end
      hash.merge(options)
    end
  end
end

require 'json/jwk/set'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json-jwt-0.1.5 lib/json/jwk.rb
json-jwt-0.1.4 lib/json/jwk.rb
json-jwt-0.1.3 lib/json/jwk.rb