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(opts = {}) ⇒ Cripter
constructor
Build a new cripter.
- #inspect ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Cripter
Build a new cripter
opts: 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 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cript/cripter.rb', line 21 def initialize(opts = {}) @opts = opts # Attempt to use the private key at the default location # if exists and not otherwise specified unless [:private_key_content, :private_key_path].any? { |o| @opts[o] } if File.file?("#{ENV['HOME']}/.ssh/id_rsa") @opts[:private_key_path] = "#{ENV['HOME']}/.ssh/id_rsa" end end if @opts[:private_key_content] @private_key = OpenSSL::PKey::RSA.new(*[@opts[:private_key_content], @opts.delete(:passphrase)]) elsif @opts[:private_key_path] && File.file?(@opts[:private_key_path]) @private_key = OpenSSL::PKey::RSA.new(*[File.read(@opts[:private_key_path]), @opts.delete(:passphrase)]) end if @private_key @public_key = @private_key.public_key else if @opts[:public_key_content] @public_key = OpenSSL::PKey::RSA.new(@opts[:public_key_content]) elsif @opts[:public_key_path] && File.file?(@opts[:public_key_path]) @public_key = OpenSSL::PKey::RSA.new(File.read(@opts[:public_key_path])) elsif File.file?("#{ENV['HOME']}/.ssh/id_rsa.pub") @public_key = OpenSSL::PKey::RSA.new(File.read("#{ENV['HOME']}/.ssh/id_rsa.pub")) end end end |
Instance Method Details
#decrypt(message) ⇒ Object
59 60 61 |
# File 'lib/cript/cripter.rb', line 59 def decrypt() raise Cript::Cripter::Error, "Implement me" end |
#echo(message) ⇒ Object
63 64 65 |
# File 'lib/cript/cripter.rb', line 63 def echo() decrypt(encrypt()) end |
#encrypt(message) ⇒ Object
55 56 57 |
# File 'lib/cript/cripter.rb', line 55 def encrypt() raise Cript::Cripter::Error, "Implement me" end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/cript/cripter.rb', line 51 def inspect "#<#{self.class.name}>" end |