Cleanup.
authorGunnar Wrobel <p@rdus.de>
Wed, 17 Nov 2010 16:37:34 +0000 (17:37 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 30 Nov 2010 12:48:26 +0000 (13:48 +0100)
framework/Secret/lib/Horde/Secret.php
framework/Secret/test/Horde/Secret/Unit/SecretTest.php

index f6da864..862e9ec 100644 (file)
@@ -74,11 +74,11 @@ class Horde_Secret
             throw new Horde_Secret_Exception('Plain text must be a string', 0);
         }
 
-        $val = strlen($key) && strlen($message)
-            ? $this->_getCipherOb($key)->encrypt($message)
-            : '';
-
-        return $val;
+        if (strlen($key) && strlen($message)) {
+            return $this->_getCipherOb($key)->encrypt($message);
+        } else {
+            return '';
+        }
     }
 
     /**
@@ -96,13 +96,11 @@ class Horde_Secret
             throw new Horde_Secret_Exception('Chiper text must be a string', 1);
         }
 
-        $val = strlen($key) && strlen($ciphertext)
-            ? $this->_getCipherOb($key)->decrypt($ciphertext)
-            : '';
-
-        /* Bug #9121: Data may be null padded - need to remove this
-         * padding. */
-        return rtrim($val, "\0");
+        if (strlen($key) && strlen($ciphertext)) {
+            return rtrim($this->_getCipherOb($key)->decrypt($ciphertext), "\0");
+        } else {
+            return '';
+        }
     }
 
     /**
index d295d0b..8b529fb 100644 (file)
@@ -114,9 +114,15 @@ class Horde_Secret_Unit_SecretTest extends PHPUnit_Framework_TestCase
         $secret->read('012345678901234567890123456789012345678901234567890123456789', "\x01");
     }
 
-    public function testShortKey()
+    public function testShortKeyRead()
     {
         $secret = new Horde_Secret();
         $this->assertEquals('', $secret->read('', "\x01"));
     }
+
+    public function testShortKeyWrite()
+    {
+        $secret = new Horde_Secret();
+        $this->assertEquals('', $secret->write('', "\x01"));
+    }
 }
\ No newline at end of file