| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\SsdeepException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Calculates the match score between signature1 |
| 9 |
* and signature2 using |
| 10 |
* context-triggered piecewise hashing, and returns the match |
| 11 |
* score. |
| 12 |
* |
| 13 |
* @param string $signature1 The first fuzzy hash signature string. |
| 14 |
* @param string $signature2 The second fuzzy hash signature string. |
| 15 |
* @return int Returns an integer from 0 to 100 on success, FALSE otherwise. |
| 16 |
* @throws SsdeepException |
| 17 |
* |
| 18 |
*/ |
| 19 |
function ssdeep_fuzzy_compare(string $signature1, string $signature2): int |
| 20 |
{ |
| 21 |
error_clear_last(); |
| 22 |
$result = \ssdeep_fuzzy_compare($signature1, $signature2); |
| 23 |
if ($result === false) { |
| 24 |
throw SsdeepException::createFromPhpError(); |
| 25 |
} |
| 26 |
return $result; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
/** |
| 31 |
* ssdeep_fuzzy_hash_filename calculates the hash |
| 32 |
* of the file specified by file_name using |
| 33 |
* context-triggered piecewise |
| 34 |
* hashing, and returns that hash. |
| 35 |
* |
| 36 |
* @param string $file_name The filename of the file to hash. |
| 37 |
* @return string Returns a string on success, FALSE otherwise. |
| 38 |
* @throws SsdeepException |
| 39 |
* |
| 40 |
*/ |
| 41 |
function ssdeep_fuzzy_hash_filename(string $file_name): string |
| 42 |
{ |
| 43 |
error_clear_last(); |
| 44 |
$result = \ssdeep_fuzzy_hash_filename($file_name); |
| 45 |
if ($result === false) { |
| 46 |
throw SsdeepException::createFromPhpError(); |
| 47 |
} |
| 48 |
return $result; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
/** |
| 53 |
* ssdeep_fuzzy_hash calculates the hash of |
| 54 |
* to_hash using |
| 55 |
* context-triggered piecewise hashing, and returns that hash. |
| 56 |
* |
| 57 |
* @param string $to_hash The input string. |
| 58 |
* @return string Returns a string on success, FALSE otherwise. |
| 59 |
* @throws SsdeepException |
| 60 |
* |
| 61 |
*/ |
| 62 |
function ssdeep_fuzzy_hash(string $to_hash): string |
| 63 |
{ |
| 64 |
error_clear_last(); |
| 65 |
$result = \ssdeep_fuzzy_hash($to_hash); |
| 66 |
if ($result === false) { |
| 67 |
throw SsdeepException::createFromPhpError(); |
| 68 |
} |
| 69 |
return $result; |
| 70 |
} |
| 71 |
|