class SimpleScripting::Configuration::Value

The purpose of encryption in this library is just to avoid displaying passwords in plaintext; it's not considered safe against attacks.

Constants

ENCRYPTION_CIPHER

Public Class Methods

new(string, encryption_key = nil) click to toggle source
Calls superclass method
# File lib/simple_scripting/configuration/value.rb, line 15
def initialize(string, encryption_key = nil)
  super(string)

  if encryption_key
    @encryption_key = encryption_key + '*' * (24 - encryption_key.bytesize)
  end
end

Public Instance Methods

decrypted() click to toggle source
# File lib/simple_scripting/configuration/value.rb, line 31
def decrypted
  raise "Encryption key not provided!" if @encryption_key.nil?

  ciphertext = Base64.decode64(self)

  cipher = OpenSSL::Cipher::Cipher.new(ENCRYPTION_CIPHER)
  cipher.decrypt

  cipher.key = @encryption_key

  cipher.iv = ciphertext[0...cipher.iv_len]
  plaintext = cipher.update(ciphertext[cipher.iv_len..-1]) + cipher.final

  plaintext
end
encrypted() click to toggle source
# File lib/simple_scripting/configuration/value.rb, line 47
def encrypted
  cipher = OpenSSL::Cipher::Cipher.new(ENCRYPTION_CIPHER)
  cipher.encrypt

  iv = cipher.random_iv

  cipher.key = @encryption_key
  cipher.iv  = iv

  ciphertext = iv + cipher.update(self) + cipher.final

  Base64.encode64(ciphertext).rstrip
end
full_path() click to toggle source
# File lib/simple_scripting/configuration/value.rb, line 23
def full_path
  start_with?('/') ? self : File.expand_path(self, '~')
end
full_paths() click to toggle source
# File lib/simple_scripting/configuration/value.rb, line 27
def full_paths
  split(':').map { |value| self.class.new(value).full_path }
end