From e46db70fbb574cfef7f52686f1ac3dd8ce676d95 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Wed, 17 Nov 2010 17:37:34 +0100 Subject: [PATCH] Cleanup. --- framework/Secret/lib/Horde/Secret.php | 22 ++++++++++------------ .../Secret/test/Horde/Secret/Unit/SecretTest.php | 8 +++++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/framework/Secret/lib/Horde/Secret.php b/framework/Secret/lib/Horde/Secret.php index f6da86486..862e9ece4 100644 --- a/framework/Secret/lib/Horde/Secret.php +++ b/framework/Secret/lib/Horde/Secret.php @@ -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 ''; + } } /** diff --git a/framework/Secret/test/Horde/Secret/Unit/SecretTest.php b/framework/Secret/test/Horde/Secret/Unit/SecretTest.php index d295d0bb3..8b529fb5e 100644 --- a/framework/Secret/test/Horde/Secret/Unit/SecretTest.php +++ b/framework/Secret/test/Horde/Secret/Unit/SecretTest.php @@ -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 -- 2.11.0