Class: Acme::Client::Crypto

Inherits:
Object
  • Object
show all
Defined in:
lib/acme/client/crypto.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key) ⇒ Crypto

Returns a new instance of Crypto.



4
5
6
# File 'lib/acme/client/crypto.rb', line 4

def initialize(private_key)
  @private_key = private_key
end

Instance Attribute Details

#private_keyObject (readonly)

Returns the value of attribute private_key.



2
3
4
# File 'lib/acme/client/crypto.rb', line 2

def private_key
  @private_key
end

Instance Method Details

#digestObject



20
21
22
# File 'lib/acme/client/crypto.rb', line 20

def digest
  OpenSSL::Digest::SHA256.new
end

#generate_signed_jws(header:, payload:) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/acme/client/crypto.rb', line 8

def generate_signed_jws(header:, payload:)
  jwt = JSON::JWT.new(payload || {})
  jwt.header.merge!(header || {})
  jwt.header[:jwk] = jwk
  jwt.signature = jwt.sign(private_key, :RS256).signature
  jwt.to_json(syntax: :flattened)
end

#thumbprintObject



16
17
18
# File 'lib/acme/client/crypto.rb', line 16

def thumbprint
  jwk.thumbprint
end