mail-gpg 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.0.5 2013-08-28
2
+
3
+ * add some docs to the Hkp client
4
+ * also add convenience method to fetch and import keys
5
+
1
6
  == 0.0.4 2013-08-27
2
7
 
3
8
  * better ActionMailer integration
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'gpgme'
5
5
  def setup_gpghome
6
6
  gpghome = File.join File.dirname(__FILE__), 'test', 'gpghome'
7
7
  ENV['GNUPGHOME'] = gpghome
8
+ ENV['GPG_AGENT_INFO'] = '' # disable gpg agent
8
9
  unless File.directory? gpghome
9
10
  FileUtils.mkdir_p gpghome
10
11
  GPGME::Ctx.new do |gpg|
data/lib/hkp.rb CHANGED
@@ -1,26 +1,46 @@
1
1
  require 'open-uri'
2
+ require 'gpgme'
3
+
4
+ # simple HKP client for public key retrieval
2
5
  class Hkp
3
6
  def initialize(keyserver = 'http://pool.sks-keyservers.net:11371')
4
7
  @keyserver = keyserver
5
8
  end
6
9
 
10
+ # hkp.search 'user@host.com'
11
+ # will return an array of arrays, one for each matching key found, containing
12
+ # the key id as the first elment and any further info returned by the key
13
+ # server in the following elements.
14
+ # see http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00#section-5.2 for
15
+ # what that *might* be. unfortunately key servers seem to differ in how much
16
+ # and what info they return besides the key id
7
17
  def search(name)
8
18
  [].tap do |results|
9
19
  open("#{@keyserver}/pks/lookup?options=mr&search=#{URI.escape name}") do |f|
10
20
  f.each_line do |l|
11
- if l =~ /pub:(\w{8}):/
12
- results << $1
21
+ components = l.strip.split(':')
22
+ if components.shift == 'pub'
23
+ results << components
13
24
  end
14
25
  end
15
26
  end
16
27
  end
17
28
  end
18
29
 
30
+ # returns the key data as returned from the server as a string
19
31
  def fetch(id)
20
32
  open("#{@keyserver}/pks/lookup?options=mr&op=get&search=0x#{URI.escape id}") do |f|
21
33
  return clean_key f.read
22
34
  end
35
+ end
23
36
 
37
+ # fetches key data by id and imports the found key(s) into GPG, returning the full hex fingerprints of the
38
+ # imported key(s) as an array. Given there are no collisions with the id given / the server has returned
39
+ # exactly one key this will be a one element array.
40
+ def fetch_and_import(id)
41
+ if key = fetch(id)
42
+ GPGME::Key.import(key).imports.map(&:fpr)
43
+ end
24
44
  end
25
45
 
26
46
  private
@@ -1,5 +1,5 @@
1
1
  module Mail
2
2
  module Gpg
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail-gpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: