-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate benburkert's interesting fixes + some test fixes #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ source "http://rubygems.org" | |
|
||
# Specify your gem's dependencies in gpgme.gemspec | ||
gemspec | ||
|
||
gem 'rake' | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ class << self | |
# | ||
# @example | ||
# GPGME::Key.find(:public, "[email protected]", :sign) | ||
# # => return the public keys that match mrsimo@exampl.com and are | ||
# # => return the public keys that match mrsimo@example.com and are | ||
# # capable of signing | ||
def find(secret, keys_or_names = nil, purposes = []) | ||
secret = (secret == :secret) | ||
|
@@ -63,6 +63,26 @@ def find(secret, keys_or_names = nil, purposes = []) | |
keys | ||
end | ||
|
||
# Works similar as {.find}, however it restricts the way the keys are looked up. | ||
# GPG has the issue that finding a key for [email protected], also returns a key | ||
# for [email protected]. | ||
# This can be restricted by adding <> around the address: <[email protected]>. | ||
# Hence {.find_exact} simply wraps <> around each email you passed to the method and delegates | ||
# the rest to {.find} | ||
# | ||
# @example | ||
# GPGME::Key.find_exact(:public, "[email protected]") | ||
# # => return the public key of [email protected], but not for | ||
# # [email protected] | ||
def find_exact(secret, keys_or_names = nil, purposes = []) | ||
keys_or_names = [""] if keys_or_names.nil? || (keys_or_names.is_a?(Array) && keys_or_names.empty?) | ||
find( | ||
secret, | ||
[keys_or_names].flatten.collect{|k| if k =~ /.*@.*/ && !(k =~ /<.*@.*>/) then "<#{k}>" else k end }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I´m pretty concerned with this line. I need a lot of brain power to get to understand it, the 1 letter variable with two regexp´s and a ternary make it pretty hard. Also, I´m not sure if this kind of method has to be part of the API. after all it´s 'normal' gpg behavior, so I have the feeling it's the user who should be passing emails in <> to the normal find instead. I'd probably add a comment on the find method explaining it, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is the following: Given you have 2 keys: one for [email protected] and one for [email protected]. If you do a I implemented that I agree that I tend to write compact rather than readable code. If you prefer, I could propose a more "readable" but less compact version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some in details about that can be found here: http://old.nabble.com/key-lookup-strategies-td30325738.html |
||
purposes | ||
) | ||
end | ||
|
||
def get(fingerprint) | ||
Ctx.new do |ctx| | ||
ctx.get_key(fingerprint) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,28 @@ | |
assert keys.empty? | ||
end | ||
end | ||
|
||
describe :find_exact do | ||
it "wraps an email address with angle brackets" do | ||
GPGME::Key.expects(:find).with(:public,['<[email protected]>'],[]) | ||
GPGME::Key.find_exact(:public,'[email protected]') | ||
end | ||
|
||
it "wraps multiple email addresses with angle brackets" do | ||
GPGME::Key.expects(:find).with(:public,['<[email protected]>','<[email protected]>'],[]) | ||
GPGME::Key.find_exact(:public,['[email protected]','[email protected]']) | ||
end | ||
|
||
it "does not touch other strings than email addresses" do | ||
GPGME::Key.expects(:find).with(:public,['Bar Example'],[]) | ||
GPGME::Key.find_exact(:public,'Bar Example') | ||
end | ||
|
||
it "does the same in mixed mode" do | ||
GPGME::Key.expects(:find).with(:public,['<[email protected]>','Foo Example'],[]) | ||
GPGME::Key.find_exact(:public,['[email protected]','Foo Example']) | ||
end | ||
end | ||
|
||
describe :export do | ||
# Testing the lazy way with expectations. I think tests in | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this is needed? Never had any problems without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bundler complained, that rake is missing. This fixed the issue. To be honest I didn't investigate further than adding the dependency. I'm not sure if it hurts some day, some time. If you prefer, you can skip that commit.