Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/simplecrypt.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,15 @@ function Encrypt($key, $sString)
*/
function Decrypt($key, $string)
{
return $this->oEngine->Decrypt($key,$string);
try{
return $this->oEngine->Decrypt($key,$string);
} catch(\Exception $e){
if (strlen($string)==0){
IssueLog::Warning("Cannot decrypt empty/null value", null, ['msg' => $e->getMessage(), 'stack' => $e->getTraceAsString()]);
return $string;
}
throw $e;
}
}

/**
Expand Down Expand Up @@ -422,4 +430,4 @@ public function Decrypt($key, $encrypted_data)
return trim($plaintext);
}

}
}
Comment on lines -425 to +433
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove EOL's at end of the file!

36 changes: 36 additions & 0 deletions tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*!
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/

namespace Combodo\iTop\Test\UnitTest\Core;

use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use SodiumException;

/**
* Tests of the ormPassword class
*/
class SympleCryptTest extends ItopDataTestCase
{
public function testDecryptWithNullValue()
{
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$this->assertEquals(null, $oSimpleCrypt->Decrypt("dd", null));
}

public function testDecryptWithEmptyValue()
{
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$this->assertEquals('', $oSimpleCrypt->Decrypt("dd", ""));
}

public function testDecrypNonDecryptableValue()
{
$this->expectException(SodiumException::class);
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$this->assertEquals('', $oSimpleCrypt->Decrypt("dd", "gabuzomeu"));
}

}