ruby-gpgme icon indicating copy to clipboard operation
ruby-gpgme copied to clipboard

add sign + encrypt example to README

Open sawall opened this issue 10 years ago • 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 => "[email protected]",
                   :sign => true,
                   :signers => "[email protected]",
                   :password => "sig_key_password")

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

sawall avatar Jan 22 '15 00:01 sawall

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

ueno avatar Jan 22 '15 05:01 ueno

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.

sawall avatar Jan 23 '15 00:01 sawall

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.

ueno avatar Jan 23 '15 03:01 ueno