Class: Obfusc::Encryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/obfusc/encryptor.rb

Overview

Recursive find files from origin or pattern

Constant Summary collapse

SEP_FROM =
'/'.freeze
SEP_TO =
'___|___'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Encryptor

Returns a new instance of Encryptor.



9
10
11
12
13
# File 'lib/obfusc/encryptor.rb', line 9

def initialize(config)
  @config = config
  @prefix = "#{config.prefix}__"
  @suffix = ".#{config.extension}"
end

Instance Method Details

#decrypt(path) ⇒ Object



23
24
25
# File 'lib/obfusc/encryptor.rb', line 23

def decrypt(path)
  expand_path_for_decrypt(path).join(SEP_FROM)
end

#encrypt(path) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/obfusc/encryptor.rb', line 15

def encrypt(path)
  crypted_filename = expand_path_for_encrypt(path).map do |step|
    step.chars.map { |char| charlist[char] || char }.join
  end.join(SEP_TO)

  [@prefix, crypted_filename, @suffix].join
end

#obfuscated?(file) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/obfusc/encryptor.rb', line 27

def obfuscated?(file)
  !!(file =~ obfuscated_expression)
end