summaryrefslogtreecommitdiff
path: root/lib/nickserver/hkp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nickserver/hkp')
-rw-r--r--lib/nickserver/hkp/client.rb7
-rw-r--r--lib/nickserver/hkp/parse_key_info.rb10
-rw-r--r--lib/nickserver/hkp/source.rb36
3 files changed, 27 insertions, 26 deletions
diff --git a/lib/nickserver/hkp/client.rb b/lib/nickserver/hkp/client.rb
index 6bd239d..1fbe7a2 100644
--- a/lib/nickserver/hkp/client.rb
+++ b/lib/nickserver/hkp/client.rb
@@ -21,7 +21,7 @@ module Nickserver; module Hkp
# 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
+ get op: 'vindex', search: email.to_s, fingerprint: 'on'
end
#
@@ -35,10 +35,11 @@ module Nickserver; module Hkp
attr_reader :adapter
- def get(query, &block)
+ def get(query)
# in practice, exact=on seems to have no effect
query = {exact: 'on', options: 'mr'}.merge query
- adapter.get Config.hkp_url, query: query, &block
+ response = adapter.get Config.hkp_url, query: query
+ return response
end
end
end; end
diff --git a/lib/nickserver/hkp/parse_key_info.rb b/lib/nickserver/hkp/parse_key_info.rb
index 9d59d6b..2f928a0 100644
--- a/lib/nickserver/hkp/parse_key_info.rb
+++ b/lib/nickserver/hkp/parse_key_info.rb
@@ -19,7 +19,8 @@ module Nickserver; module Hkp
@vindex_result = vindex_result
end
- def status_for(uid)
+ def status_for(email)
+ uid = email.to_s
if hkp_ok? && keys(uid).empty?
error_status(uid)
else
@@ -27,7 +28,8 @@ module Nickserver; module Hkp
end
end
- def response_for(uid)
+ def response_for(email)
+ uid = email.to_s
if keys(uid).any?
keys(uid)
else
@@ -35,6 +37,8 @@ module Nickserver; module Hkp
end
end
+ protected
+
def keys(uid)
key_infos(uid).reject { |key| error_for_key(key) }
end
@@ -47,8 +51,6 @@ module Nickserver; module Hkp
end
end
- protected
-
attr_reader :status
attr_reader :vindex_result
diff --git a/lib/nickserver/hkp/source.rb b/lib/nickserver/hkp/source.rb
index 8b2a62b..0d79856 100644
--- a/lib/nickserver/hkp/source.rb
+++ b/lib/nickserver/hkp/source.rb
@@ -1,3 +1,4 @@
+require 'nickserver/source'
require 'nickserver/response'
require 'nickserver/hkp/response'
require 'nickserver/hkp/client'
@@ -13,22 +14,20 @@ require "nickserver/hkp/key_info"
module Nickserver; module Hkp
class Source < Nickserver::Source
- def query(nick, &block)
- search(nick) do |status, response|
- if status == 200
- best = pick_best_key(response)
- get_key_by_fingerprint(nick, best.keyid, &block)
- else
- yield Nickserver::Response.new(status, response)
- end
+ def query(nick)
+ status, response = search(nick)
+ if status == 200
+ best = pick_best_key(response)
+ get_key_by_fingerprint(nick, best.keyid)
+ else
+ Nickserver::Response.new(status, response)
end
end
- def search(nick, &block)
- client.get_key_infos_by_email(nick) do |status, response|
- parser = ParseKeyInfo.new status, response
- yield parser.status_for(nick), parser.response_for(nick)
- end
+ def search(nick)
+ status, response = client.get_key_infos_by_email(nick)
+ parser = ParseKeyInfo.new status, response
+ return parser.status_for(nick), parser.response_for(nick)
end
protected
@@ -44,12 +43,11 @@ module Nickserver; module Hkp
end
def get_key_by_fingerprint(nick, fingerprint)
- client.get_key_by_fingerprint fingerprint do |status, response|
- if status == 200
- yield Response.new nick, response
- else
- yield Nickserver::Response.new status, "HKP Request failed"
- end
+ status, response = client.get_key_by_fingerprint fingerprint
+ if status == 200
+ Response.new nick, response
+ else
+ Nickserver::Response.new status, "HKP Request failed"
end
end