ueno/ruby-gpgme

add sign + encrypt example to README

Opened this issue · 3 comments

It might be nice to add an example in the README for encrypting and signing. The API docs are a bit vague on how this works and it's especially confusing since the parameters for GPGME::Crypto.sign() are different than the ones in GPGME::Crypto.encrypt(). Suggested sample code block:

encrypted = crypto.encrypt(
                   "text to be encrypted",
                   :recipients => "their@email.com",
                   :sign => true,
                   :signers => "my@email.com",
                   :password => "sig_key_password")

I'm happy to fork/pull if you prefer!

ueno commented

and/or perhaps we could improve the API, something like:

  • add :signers option to crypto.sign, in addition to :signer
  • guess :sign is true, if :signers is given
  • add crypto.encrypt_sign

1: I think I might change :signer to :signers for crypto.sign. That way the option is consistently named within GPGME::Crypto and it's clear that it can take multiples. (To be honest I'm not entirely familiar with the best practice pattern for naming ruby method parameters that might take different object types that could be singular or plural.)

2: that's a great idea. One thing I hadn't mentioned was that it wasn't clear to me what (if anything) happens if :signers isn't specified in my sample call. Does :sign => true without a :signers do anything? If not, I definitely agree with your suggestion. (At that point, you could ditch :sign entirely.)

3: crypto.encrypt_sign would definitely improve clarity! If that was added maybe ditch :sign options from crypto.encrypt? Although that would kill some backwards compatibility.

ueno commented

for 1, I'm a bit concern about backward compatibility. it wouldn't be good if the renaming broke existing programs. patches are welcome anyway.