Module: PQCrypto::JWT::Keys

Defined in:
lib/pq_crypto/jwt/keys.rb

Constant Summary collapse

EXPECT_VALUES =
[:auto, :signature].freeze

Class Method Summary collapse

Class Method Details

.generate(alg) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
# File 'lib/pq_crypto/jwt/keys.rb', line 14

def generate(alg)
  algorithm = PQCrypto::JWT.algorithm_for(alg)
  raise ArgumentError, "Unsupported PQCrypto JOSE algorithm: #{alg.inspect}" unless algorithm
  raise ArgumentError, "Unsupported key kind for #{alg.inspect}" unless algorithm.key_kind == :signature

  PQCrypto::Signature.generate(algorithm.pq_crypto_algorithm)
end

.public_from_pem(pem, expect: :auto) ⇒ Object



22
23
24
25
26
27
# File 'lib/pq_crypto/jwt/keys.rb', line 22

def public_from_pem(pem, expect: :auto)
  validate_expect!(expect)
  return PQCrypto::Signature.public_key_from_spki_pem(pem) if expect == :signature

  dispatch_public_from_pem(pem)
end

.secret_from_pem(pem, expect: :auto) ⇒ Object



29
30
31
32
33
34
# File 'lib/pq_crypto/jwt/keys.rb', line 29

def secret_from_pem(pem, expect: :auto)
  validate_expect!(expect)
  return PQCrypto::Signature.secret_key_from_pkcs8_pem(pem) if expect == :signature

  dispatch_secret_from_pem(pem)
end