提交 d1213fa4 编写于 作者: J Jeremy Kemper

Rescue OpenSSL::Cipher::CipherError or OpenSSL::CipherError depending on which is present

上级 4073a6d0
......@@ -10,7 +10,8 @@ module ActiveSupport
# want users to be able to determine the value of the payload.
class MessageEncryptor
class InvalidMessage < StandardError; end
OpenSSLCipherError = OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError
def initialize(secret, cipher = 'aes-256-cbc')
@secret = secret
@cipher = cipher
......@@ -43,7 +44,7 @@ def decrypt(encrypted_message)
decrypted_data << cipher.final
Marshal.load(decrypted_data)
rescue OpenSSL::CipherError, TypeError
rescue OpenSSLCipherError, TypeError
raise InvalidMessage
end
......@@ -66,4 +67,4 @@ def verifier
MessageVerifier.new(@secret)
end
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册