summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-06-10 10:28:09 +0200
committerAzul <azul@riseup.net>2016-06-10 10:28:09 +0200
commit10a57e4f92432ff2b82c4a6bb5027bb3bcbdfab9 (patch)
treebcd543481044813f3d556fba6f833f4555d8d453 /lib
parentb4075771b2b1f3c688496d18d7a5a5f1db952004 (diff)
turn Hkp::FetchKey into Hkp::Source
The source was really just an empty shell now that we pushed the em specific stuff further down.
Diffstat (limited to 'lib')
-rw-r--r--lib/nickserver.rb1
-rw-r--r--lib/nickserver/hkp/fetch_key.rb59
-rw-r--r--lib/nickserver/hkp/source.rb51
3 files changed, 44 insertions, 67 deletions
diff --git a/lib/nickserver.rb b/lib/nickserver.rb
index 22d4b43..16f7e85 100644
--- a/lib/nickserver.rb
+++ b/lib/nickserver.rb
@@ -3,7 +3,6 @@ require "nickserver/version"
require "nickserver/config"
require "nickserver/email_address"
-require "nickserver/hkp/fetch_key"
require "nickserver/hkp/fetch_key_info"
require "nickserver/hkp/parse_key_info"
require "nickserver/hkp/key_info"
diff --git a/lib/nickserver/hkp/fetch_key.rb b/lib/nickserver/hkp/fetch_key.rb
deleted file mode 100644
index 10c4926..0000000
--- a/lib/nickserver/hkp/fetch_key.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require 'em-http'
-require 'nickserver/response'
-require 'nickserver/hkp/response'
-
-#
-# Fetch keys via HKP
-# http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00
-#
-
-module Nickserver; module Hkp
-
- class FetchKey
-
- def initialize(adapter)
- @adapter = adapter
- end
-
- def get(nick, &block)
- FetchKeyInfo.new.search(nick).callback {|key_info_list|
- best = pick_best_key(key_info_list)
- get_key_by_fingerprint(nick, best.keyid, &block)
- }.errback {|status, msg|
- yield Nickserver::Response.new(status, msg)
- }
- end
-
- #
- # fetches ascii armored OpenPGP public key from the keyserver
- #
- def get_key_by_fingerprint(nick, key_id)
- params = {op: 'get', search: "0x" + key_id, exact: 'on', options: 'mr'}
- http = EventMachine::HttpRequest.new(Config.hkp_url).get(query: params)
- http.callback {
- status = http.response_header.status
- if status != 200
- yield Nickserver::Response.new status, "HKP Request failed"
- else
- yield Response.new nick, http.response
- end
- }
- http.errback {
- yield Nickserver::Response.new 500, http.error
- }
- end
-
- protected
-
- #
- # for now, just pick the newest key.
- #
- # in the future, we should perhaps pick the newest key
- # that is signed by the oldest key.
- #
- def pick_best_key(key_info_list)
- key_info_list.sort {|a,b| a.creationdate <=> b.creationdate}.last
- end
- end
-
-end; end
diff --git a/lib/nickserver/hkp/source.rb b/lib/nickserver/hkp/source.rb
index f06a931..1dd386d 100644
--- a/lib/nickserver/hkp/source.rb
+++ b/lib/nickserver/hkp/source.rb
@@ -1,4 +1,12 @@
-module Nickserver::Hkp
+require 'nickserver/response'
+require 'nickserver/hkp/response'
+
+#
+# Fetch keys via HKP
+# http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00
+#
+
+module Nickserver; module Hkp
class Source
def initialize(adapter)
@@ -6,15 +14,44 @@ module Nickserver::Hkp
end
def query(nick, &block)
- fetcher.get(nick, &block)
+ FetchKeyInfo.new.search(nick).callback {|key_info_list|
+ best = pick_best_key(key_info_list)
+ get_key_by_fingerprint(nick, best.keyid, &block)
+ }.errback {|status, msg|
+ yield Nickserver::Response.new(status, msg)
+ }
end
- protected
+ #
+ # fetches ascii armored OpenPGP public key from the keyserver
+ #
+ def get_key_by_fingerprint(nick, key_id)
+ params = {op: 'get', search: "0x" + key_id, exact: 'on', options: 'mr'}
+ http = EventMachine::HttpRequest.new(Config.hkp_url).get(query: params)
+ http.callback {
+ status = http.response_header.status
+ if status != 200
+ yield Nickserver::Response.new status, "HKP Request failed"
+ else
+ yield Response.new nick, http.response
+ end
+ }
+ http.errback {
+ yield Nickserver::Response.new 500, http.error
+ }
+ end
- attr_reader :adapter
+ protected
- def fetcher
- Nickserver::Hkp::FetchKey.new(adapter)
+ #
+ # for now, just pick the newest key.
+ #
+ # in the future, we should perhaps pick the newest key
+ # that is signed by the oldest key.
+ #
+ def pick_best_key(key_info_list)
+ key_info_list.sort {|a,b| a.creationdate <=> b.creationdate}.last
end
end
-end
+
+end; end