Class: Pwnedkeys::Response
- Inherits:
-
Object
- Object
- Pwnedkeys::Response
- Defined in:
- lib/pwnedkeys/response.rb
Overview
Generate a v1 compromise attestation.
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#initialize(key) ⇒ Response
constructor
Create a new response.
-
#to_json(*spki_format) ⇒ String
Produce a JSON format compromise attestation.
Constructor Details
#initialize(key) ⇒ Response
Create a new response.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pwnedkeys/response.rb', line 25 def initialize(key) @key = if key.kind_of?(OpenSSL::PKey::PKey) key elsif key.is_a?(String) begin OpenSSL::PKey.read(key) rescue OpenSSL::PKey::PKeyError raise Error, "Unable to parse provided key data" end else raise Error, "Invalid argument type passed to Pwnedkeys::Response.new (need OpenSSL::PKey::PKey or string, got #{key.class})" end unless @key.private? raise Error, "Provided key is not a private key." end end |
Instance Method Details
#to_json(*spki_format) ⇒ String
Produce a JSON format compromise attestation.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pwnedkeys/response.rb', line 57 def to_json(*spki_format) header = { alg: key_alg, kid: @key.to_spki(*spki_format).spki_fingerprint.hexdigest, } obj = { payload: b64("This key is pwned! See https://pwnedkeys.com for more info."), protected: b64(header.to_json), } obj[:signature] = b64(sign(obj)) obj.to_json end |