Class: CertificateTransparency::Client
- Inherits:
-
Object
- Object
- CertificateTransparency::Client
- Defined in:
- lib/certificate-transparency/client.rb
Overview
Interact with a Certificate Transparency server.
Defined Under Namespace
Instance Attribute Summary collapse
-
#public_key ⇒ OpenSSL::PKey
readonly
The public key of the log, as specified in the constructor.
Instance Method Summary collapse
-
#get_entries(first, last = nil) ⇒ Array<CT::LogEntry>
Retrieve one or more entries from the log.
-
#get_sth ⇒ CT::SignedTreeHead
Retrieve the current Signed Tree Head from the log.
-
#initialize(url, opts = {}) ⇒ CT::Client
constructor
Create thyself a new CT::Client.
Constructor Details
#initialize(url, opts = {}) ⇒ CT::Client
Create thyself a new CT::Client.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/certificate-transparency/client.rb', line 34 def initialize(url, opts = {}) unless opts.is_a? Hash raise ArgumentError, "Must pass a hash of options as second argument" end if opts[:public_key] begin @public_key = if opts[:public_key].valid_encoding? && opts[:public_key] =~ /^[A-Za-z0-9+\/]+=*$/ OpenSSL::PKey::EC.new(opts[:public_key].unpack("m").first) else OpenSSL::PKey::EC.new(opts[:public_key]) end rescue OpenSSL::PKey::ECError raise ArgumentError, "Invalid public key" end end @url = URI(url) end |
Instance Attribute Details
#public_key ⇒ OpenSSL::PKey (readonly)
The public key of the log, as specified in the constructor.
20 21 22 |
# File 'lib/certificate-transparency/client.rb', line 20 def public_key @public_key end |
Instance Method Details
#get_entries(first, last = nil) ⇒ Array<CT::LogEntry>
Retrieve one or more entries from the log.
85 86 87 88 89 90 91 92 |
# File 'lib/certificate-transparency/client.rb', line 85 def get_entries(first, last = nil) last ||= get_sth.tree_size - 1 entries_json = make_request("get-entries", :start => first, :end => last) JSON.parse(entries_json)["entries"].map do |entry| CT::LogEntry.from_json(entry.to_json) end end |
#get_sth ⇒ CT::SignedTreeHead
Retrieve the current Signed Tree Head from the log.
63 64 65 |
# File 'lib/certificate-transparency/client.rb', line 63 def get_sth CT::SignedTreeHead.from_json(make_request("get-sth")) end |