Skip to content

Commit

Permalink
New ext providing md5 and sha256 hashing algos for strings and numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
smuuf committed Nov 6, 2018
1 parent a2c1cea commit f1556ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Interpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ private static function buildCachedPath(string $source, string $path): string {
\Smuuf\Primi\Psl\RegexExtension::class,
\Smuuf\Primi\Psl\BoolExtension::class,
\Smuuf\Primi\Psl\CastingExtension::class,
\Smuuf\Primi\Psl\HashExtension::class
]);

27 changes: 27 additions & 0 deletions src/extensions/psl/HashExtension.php
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);
}

}

0 comments on commit f1556ed

Please sign in to comment.