Class: PGP::Encryptor
- Inherits:
-
Object
- Object
- PGP::Encryptor
- Defined in:
- lib/pgp/encryptor.rb
Instance Attribute Summary collapse
-
#recipients ⇒ Object
Returns the value of attribute recipients.
Instance Method Summary collapse
- #add_keys(key_string) ⇒ Object
- #add_keys_from_file(filename) ⇒ Object
- #encrypt(cleartext, filename = nil, mtime = nil) ⇒ Object
- #encrypt_file(file_path) ⇒ Object
-
#initialize(key_string = nil, gpg_engine = nil) ⇒ Encryptor
constructor
A new instance of Encryptor.
Constructor Details
Instance Attribute Details
#recipients ⇒ Object
Returns the value of attribute recipients.
3 4 5 |
# File 'lib/pgp/encryptor.rb', line 3 def recipients @recipients end |
Instance Method Details
#add_keys(key_string) ⇒ Object
11 12 13 |
# File 'lib/pgp/encryptor.rb', line 11 def add_keys(key_string) self.recipients += @gpg_engine.import_key(key_string) end |
#add_keys_from_file(filename) ⇒ Object
15 16 17 |
# File 'lib/pgp/encryptor.rb', line 15 def add_keys_from_file(filename) add_keys(File.read(filename)) end |
#encrypt(cleartext, filename = nil, mtime = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/pgp/encryptor.rb', line 19 def encrypt(cleartext, filename=nil, mtime=nil) result = @gpg_engine.encrypt(cleartext, recipients) unless filename.nil? File.write(filename, result[1]) end result[1] end |
#encrypt_file(file_path) ⇒ Object
29 30 31 |
# File 'lib/pgp/encryptor.rb', line 29 def encrypt_file(file_path) encrypt(File.read(file_path)) end |