lib/aes/aes.rb in aes-0.4.0 vs lib/aes/aes.rb in aes-0.5.0

- old
+ new

@@ -120,15 +120,17 @@ end # Merge init options with defaults def merge_options(opts) @options = { - :format => :base_64, - :cipher => "AES-256-CBC", - :iv => nil, + :format => :base_64, + :cipher => "AES-256-CBC", + :iv => nil, + :padding => true, # use cipher padding by default }.merge! opts _handle_iv + _handle_padding end def _handle_iv @iv = @options[:iv] return if @iv.nil? @@ -137,14 +139,20 @@ when :base_64 @iv = Base64.decode64(@options[:iv]) end end + def _handle_padding + # convert value to what OpenSSL module format expects + @options[:padding] = @options[:padding] ? 1 : 0 + end + # Create a new cipher using the cipher type specified def _setup(action) @cipher ||= OpenSSL::Cipher::Cipher.new(@options[:cipher]) # Toggles encryption mode @cipher.send(action) + @cipher.padding = @options[:padding] @cipher.key = @key.unpack('a2'*32).map{|x| x.hex}.pack('c'*32) end end -end \ No newline at end of file +end