rnpgp / ruby-rnp

Ruby bindings for librnp
https://www.rnpgp.org
MIT License
7 stars 3 forks source link

Support for more user-friendly enumerators #17

Open ribose-jeffreylau opened 6 years ago

ribose-jeffreylau commented 6 years ago

Currently, given this:

rnp = Rnp.new

... the following enumerators are provided:

rnp.each_fingerprint
rnp.each_grip
rnp.each_keyid
rnp.each_userid

Would it be possible to have the following way of working with the rnp object?

rnp.each_key do |key|
  key # ... do something ...
end

or even:

rnp.keys # => returns the collection of all key objects

so one could do these:

rnp.keys
  .filter(&:primary?)
  .filter(&:protected?)
  .filter(&:secret_key_present?)
  .reject(&:expired?)

Thanks!

dewyatt commented 6 years ago

It's certainly possible to implement this by just wrapping the other enumerators.

The reason this was not done initially is that, per the RFC, how a key is located (via userid, keyid, fpr, etc) determines what preferences apply. So it might be surprising behaviour.

skalee commented 6 years ago

Actually, Rnp#each_key should return an Enumerator instance. That's enough to chain filters, sorts, etc.