summaryrefslogtreecommitdiff
path: root/lib/nickserver/hkp/client.rb
blob: 6bd239deef2fe0482790eaeab71f350d7adab5f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'nickserver/hkp'

#
# Client for the HKP protocol.
#
# This is not a complete implementation - only the parts we need.
# Instantiate with an adapter that will take care of the http requests.
#
# For each request we yield http_status and the response content just
# like the adapter does.


module Nickserver; module Hkp
  class Client

    def initialize(adapter)
      @adapter = adapter
    end

    #
    # used to fetch an array of KeyInfo objects that match the given email
    #
    def get_key_infos_by_email(email, &block)
      get op: 'vindex', search: email, fingerprint: 'on', &block
    end

    #
    # fetches ascii armored OpenPGP public key from the keyserver
    #
    def get_key_by_fingerprint(fingerprint, &block)
      get op: 'get', search: "0x" + fingerprint, &block
    end

    protected

    attr_reader :adapter

    def get(query, &block)
      # in practice, exact=on seems to have no effect
      query = {exact: 'on', options: 'mr'}.merge query
      adapter.get Config.hkp_url, query: query, &block
    end
  end
end; end