Class: Cript::Cripter
- Inherits:
-
Object
- Object
- Cript::Cripter
- Defined in:
- lib/cript/cripter.rb
Overview
Cript::Cripter is an abstract class for encryption implementations using RSA keys.
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #decrypt(message) ⇒ Object
- #echo(message) ⇒ Object
- #encrypt(message) ⇒ Object
-
#initialize(options = {}) ⇒ Cripter
constructor
Build a new cripter.
- #inspect ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Cripter
Build a new cripter
Options: public_key_content private_key_content public_key_path private_key_path passphrase
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cript/cripter.rb', line 21 def initialize( = {}) @opt = unless [:public_key_content, :private_key_content, :public_key_path, :private_key_path].any? { |o| @opt[o] } if File.file?("#{ENV['HOME']}/.ssh/id_rsa") @opt[:private_key_path] = "#{ENV['HOME']}/.ssh/id_rsa" end if File.file?("#{ENV['HOME']}/.ssh/id_rsa.pub") @opt[:public_key_path] = "#{ENV['HOME']}/.ssh/id_rsa.pub" end end if [:private_key_content, :private_key_path].any? { |o| @opt[o] } @private_key = OpenSSL::PKey::RSA.new(*[key_content(:private), @opt.delete(:passphrase)]) end if [:public_key_content, :public_key_path].any? { |o| @opt[o] } @public_key = OpenSSL::PKey::RSA.new(key_content) end end |
Instance Method Details
#decrypt(message) ⇒ Object
49 50 51 |
# File 'lib/cript/cripter.rb', line 49 def decrypt() raise Cript::Cripter::Error, "Implement me" end |
#echo(message) ⇒ Object
53 54 55 |
# File 'lib/cript/cripter.rb', line 53 def echo() decrypt(encrypt()) end |
#encrypt(message) ⇒ Object
45 46 47 |
# File 'lib/cript/cripter.rb', line 45 def encrypt() raise Cript::Cripter::Error, "Implement me" end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/cript/cripter.rb', line 41 def inspect "#<#{self.class.name}>" end |