class Nexaas::Cipher::CrypterBase
CrypterBase: abstract class to support crypter classes
Attributes
salt[R]
Public Class Methods
new(*args)
click to toggle source
# File lib/nexaas/cipher/crypter_base.rb, line 9 def initialize(*args) @salt = Salt.new(*args) end
Public Instance Methods
decrypt(code, **options)
click to toggle source
# File lib/nexaas/cipher/crypter_base.rb, line 17 def decrypt(code, **options) guarded_crypt(code, :do_decrypt, **options) end
encrypt(code, **options)
click to toggle source
# File lib/nexaas/cipher/crypter_base.rb, line 13 def encrypt(code, **options) guarded_crypt(code, :do_encrypt, **options) end
salt?()
click to toggle source
# File lib/nexaas/cipher/crypter_base.rb, line 21 def salt? salt.salt? end
Protected Instance Methods
b64_encrypt(code, method, **options)
click to toggle source
# File lib/nexaas/cipher/crypter_base.rb, line 44 def b64_encrypt(code, method, **options) Base64. encode64(do_crypt(Base64.decode64(code), method, **options)). rstrip end
do_crypt(code, method, **options)
click to toggle source
# File lib/nexaas/cipher/crypter_base.rb, line 50 def do_crypt(code, method, **options) case method when :do_encrypt do_encrypt(code, **options) when :do_decrypt do_decrypt(code, **options) else raise ArgumentError(method) end end
guarded_crypt(code, method, **options)
click to toggle source
# File lib/nexaas/cipher/crypter_base.rb, line 27 def guarded_crypt(code, method, **options) return if code.nil? || code.empty? return code unless salt.salt? start_encrypting(code, method, **options) end
start_encrypting(code, method, base64: false, **options)
click to toggle source
base64 :reek:ControlParameter base64 :reek:BooleanParameter
:reek: LongParameterList
# File lib/nexaas/cipher/crypter_base.rb, line 36 def start_encrypting(code, method, base64: false, **options) if base64 b64_encrypt(code, method, **options) else do_crypt(code, method, **options) end end