From b5c0e4042eab30110b59ddbfa9d877af32ce546a Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Thu, 15 Nov 2012 11:50:05 +0000 Subject: [PATCH] Fixing use of splitIv Fixed unit tests for splitIv --- apps/files_encryption/lib/crypt.php | 4 +-- apps/files_encryption/tests/crypt.php | 45 ++++++++++++--------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 48e114846b..8026ac4361 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -263,9 +263,7 @@ class Crypt { , 'iv' => $iv ); - $combined = $content . '00iv00' . $iv; - - return $combined; + return $split; } diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index f29a72c24b..4315e347cb 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -67,17 +67,17 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { */ function testConcatIv( $iv ) { - Encryption\Crypt::concatIv( $this->dataLong, $iv ); + $catFile = Encryption\Crypt::concatIv( $this->dataLong, $iv ); // Fetch encryption metadata from end of file $meta = substr( $catFile, -22 ); - $identifier = substr( $meta, 6 ); - - $this->assertEquals( '00iv00', $identifier ); + $identifier = substr( $meta, 0, 6); // Fetch IV from end of file - $foundIv = substr( $meta, -16 ); + $foundIv = substr( $meta, 6 ); + + $this->assertEquals( '00iv00', $identifier ); $this->assertEquals( $iv, $foundIv ); @@ -85,32 +85,27 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { $data = substr( $catFile, 0, -22 ); $this->assertEquals( $this->dataLong, $data ); + + return array( + 'iv' => $iv + , 'catfile' => $catFile + ); } /** - * @depends testGenerateIv + * @depends testConcatIv */ - function testSplitIv( $iv ) { + function testSplitIv( $testConcatIv ) { - Encryption\Crypt::concatIv( $this->dataLong, $iv ); + // Split catfile into components + $splitCatfile = Encryption\Crypt::splitIv( $testConcatIv['catfile'] ); - // Fetch encryption metadata from end of file - $meta = substr( $catFile, -22 ); + // Check that original IV and split IV match + $this->assertEquals( $testConcatIv['iv'], $splitCatfile['iv'] ); - $identifier = substr( $meta, 6 ); - - $this->assertEquals( '00iv00', $identifier ); - - // Fetch IV from end of file - $foundIv = substr( $meta, -16 ); - - $this->assertEquals( $iv, $foundIv ); - - // Remove IV and IV identifier text to expose encrypted content - $data = substr( $catFile, 0, -22 ); - - $this->assertEquals( $this->dataLong, $data ); + // Check that original data and split data match + $this->assertEquals( $this->dataLong, $splitCatfile['encrypted'] ); } @@ -201,7 +196,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { $this->assertNotEquals( $this->dataShort, $retreivedCryptedFile ); - $key = Keymanager::getFileKey( $filename ); + $key = Encryption\Keymanager::getFileKey( $filename ); $manualDecrypt = Encryption\Crypt::symmetricBlockDecryptFileContent( $retreivedCryptedFile, $key ); @@ -245,7 +240,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { //print_r($e); // Manually fetch keyfile - $keyfile = Keymanager::getFileKey( $filename ); + $keyfile = Encryption\Keymanager::getFileKey( $filename ); // Set var for reassembling decrypted content $decrypt = '';