diff options
author | Azul <azul@riseup.net> | 2016-06-14 09:36:29 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-06-14 10:36:58 +0200 |
commit | 48502085e5aa7a1d8d430fc1dd4913f34e818afa (patch) | |
tree | 4eaf2f01a70affd185cb4b3c98cdd4f291a8c53b /lib/nickserver/hkp/client.rb | |
parent | f567ed80427d43019ceb1aaf77d4bc6c01e62729 (diff) |
introduce Hkp::Client
wraps the hkp protocol
Diffstat (limited to 'lib/nickserver/hkp/client.rb')
-rw-r--r-- | lib/nickserver/hkp/client.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/nickserver/hkp/client.rb b/lib/nickserver/hkp/client.rb new file mode 100644 index 0000000..6bd239d --- /dev/null +++ b/lib/nickserver/hkp/client.rb @@ -0,0 +1,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 |