also return BadKey when OpenSSL raises a CipherError
authorLunar <lunar@anargeek.net>
Sat, 17 Mar 2012 11:29:37 +0000 (12:29 +0100)
committerLunar <lunar@anargeek.net>
Fri, 23 Mar 2012 17:11:29 +0000 (18:11 +0100)
lib/coquelicot/stored_file.rb

index dcd0a9e..81acd6d 100644 (file)
@@ -177,9 +177,13 @@ module Coquelicot
     def find_meta
       yaml = ''
       buf = @file.read(BUFFER_LEN)
-      content = @cipher.update(buf)
-      content << @cipher.final if @file.eof?
-      raise BadKey.new unless content.start_with? YAML_START
+      begin
+        content = @cipher.update(buf)
+        content << @cipher.final if @file.eof?
+        raise BadKey.new unless content.start_with? YAML_START
+      rescue OpenSSL::Cipher::CipherError
+        raise BadKey.new
+      end
       yaml << YAML_START
       block = content.split(YAML_START, 3)
       yaml << block[1]