Class: Cript::Cripter

Inherits:
Object
  • Object
show all
Defined in:
lib/cript/cripter.rb

Overview

Cript::Cripter is an abstract class for encryption implementations using RSA keys.

Direct Known Subclasses

Naive, Simple

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

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(options = {})
  @opt = options

  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(message)
  raise Cript::Cripter::Error, "Implement me"
end

#echo(message) ⇒ Object



53
54
55
# File 'lib/cript/cripter.rb', line 53

def echo(message)
  decrypt(encrypt(message))
end

#encrypt(message) ⇒ Object



45
46
47
# File 'lib/cript/cripter.rb', line 45

def encrypt(message)
  raise Cript::Cripter::Error, "Implement me"
end

#inspectObject



41
42
43
# File 'lib/cript/cripter.rb', line 41

def inspect
  "#<#{self.class.name}>"
end