From ce9c17fa2e73411896ab45f1047a8712e32560f2 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 31 Aug 2011 16:52:12 -0700 Subject: [PATCH] use ActiveSupport's Base64 encoding methods instead of calling Array#pack directly; strip new lines. --- lib/encryptor.rb | 2 +- lib/salmon/salmon.rb | 20 ++------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/encryptor.rb b/lib/encryptor.rb index 0ade6d1b1..165ab91f2 100644 --- a/lib/encryptor.rb +++ b/lib/encryptor.rb @@ -16,7 +16,7 @@ module Encryptor cipher = OpenSSL::Cipher.new('AES-256-CBC') key = cipher.random_key iv = cipher.random_iv - {'key' => Base64.encode64s(key), 'iv' => Base64.encode64(iv)} + {'key' => Base64.encode64s(key), 'iv' => Base64.encode64s(iv)} end def aes_encrypt(txt, key) diff --git a/lib/salmon/salmon.rb b/lib/salmon/salmon.rb index aa0dd4b1d..3d09404d2 100644 --- a/lib/salmon/salmon.rb +++ b/lib/salmon/salmon.rb @@ -5,28 +5,12 @@ # Add URL safe Base64 support module Base64 module_function - # Returns the Base64-encoded version of +bin+. - # This method complies with RFC 4648. - # No line feeds are added. - def strict_encode64(bin) - [bin].pack("m0") - end - - # Returns the Base64-decoded version of +str+. - # This method complies with RFC 4648. - # ArgumentError is raised if +str+ is incorrectly padded or contains - # non-alphabet characters. Note that CR or LF are also rejected. - def strict_decode64(str) - Rails.logger.info("trying to decode string: " + str) - str.unpack("m0").first - end - # Returns the Base64-encoded version of +bin+. # This method complies with ``Base 64 Encoding with URL and Filename Safe # Alphabet'' in RFC 4648. # The alphabet uses '-' instead of '+' and '_' instead of '/'. def urlsafe_encode64(bin) - strict_encode64(bin).tr("+/", "-_") + self.encode64s(bin).tr("+/", "-_") end # Returns the Base64-decoded version of +str+. @@ -34,7 +18,7 @@ module Base64 # Alphabet'' in RFC 4648. # The alphabet uses '-' instead of '+' and '_' instead of '/'. def urlsafe_decode64(str) - strict_decode64(str.tr("-_", "+/")) + self.decode64(str.tr("-_", "+/")) end end