lib/encryptor.rb in encryptor-1.1.0 vs lib/encryptor.rb in encryptor-1.1.1

- old
+ new

@@ -1,7 +1,9 @@ require 'openssl' +require 'encryptor/string' +# A simple wrapper for the standard OpenSSL library module Encryptor # The default options to use when calling the <tt>encrypt</tt> and <tt>decrypt</tt> methods # # Defaults to { :algorithm => 'aes-256-cbc' } # @@ -14,30 +16,34 @@ # # Optionally accepts <tt>:iv</tt> and <tt>:algorithm</tt> options # # Example # - # encrypted_value = Huberry::Encryptor.encrypt(:value => 'some string to encrypt', :key => 'some secret key') - def self.encrypt(options) - crypt :encrypt, options + # encrypted_value = Encryptor.encrypt(:value => 'some string to encrypt', :key => 'some secret key') + # # or + # encrypted_value = Encryptor.encrypt('some string to encrypt', :key => 'some secret key') + def self.encrypt(*args) + crypt :encrypt, *args end # Decrypts a <tt>:value</tt> with a specified <tt>:key</tt> # # Optionally accepts <tt>:iv</tt> and <tt>:algorithm</tt> options # # Example # - # decrypted_value = Huberry::Encryptor.decrypt(:value => 'some encrypted string', :key => 'some secret key') - def self.decrypt(options) - crypt :decrypt, options + # decrypted_value = Encryptor.decrypt(:value => 'some encrypted string', :key => 'some secret key') + # # or + # decrypted_value = Encryptor.decrypt('some encrypted string', :key => 'some secret key') + def self.decrypt(*args) + crypt :decrypt, *args end protected - def self.crypt(cipher_method, options = {}) - options = default_options.merge(options) + def self.crypt(cipher_method, *args) #:nodoc: + options = default_options.merge(:value => args.first).merge(args.last.is_a?(Hash) ? args.last : {}) cipher = OpenSSL::Cipher::Cipher.new(options[:algorithm]) cipher.send(cipher_method) if options[:iv] cipher.key = options[:key] cipher.iv = options[:iv] @@ -45,6 +51,8 @@ cipher.pkcs5_keyivgen(options[:key]) end result = cipher.update(options[:value]) result << cipher.final end -end +end + +String.send :include, Encryptor::String \ No newline at end of file