-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New ext providing md5 and sha256 hashing algos for strings and numbers.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Smuuf\Primi\Psl; | ||
|
||
use \Smuuf\Primi\Extension; | ||
use \Smuuf\Primi\Helpers\Common; | ||
use \Smuuf\Primi\Structures\StringValue; | ||
use \Smuuf\Primi\Structures\NumberValue; | ||
use \Smuuf\Primi\Structures\Value; | ||
|
||
class HashExtension extends Extension { | ||
|
||
public static function hash_md5(Value $val): StringValue { | ||
Common::allowTypes($val, StringValue::class, NumberValue::class); | ||
$hash = md5((string) $val->value); | ||
return new StringValue($hash); | ||
} | ||
|
||
public static function hash_sha256(Value $val): StringValue { | ||
Common::allowTypes($val, StringValue::class, NumberValue::class); | ||
$hash = hash('sha256', $val->value); | ||
return new StringValue($hash); | ||
} | ||
|
||
} |