1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* The hash algorithm abstraction specification. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace CryptoManana\Core\Abstractions\MessageDigestion; |
8
|
|
|
|
9
|
|
|
use \CryptoManana\Core\Interfaces\MessageDigestion\SaltingCapabilitiesInterface as DataSalting; |
10
|
|
|
use \CryptoManana\Core\Interfaces\MessageDigestion\DigestionFormatsInterface as DigestFormatting; |
11
|
|
|
use \CryptoManana\Core\Traits\MessageDigestion\SaltingCapabilitiesTrait as SaltingCapabilities; |
12
|
|
|
use \CryptoManana\Core\Traits\MessageDigestion\DigestionFormatsTrait as DigestOutputFormats; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AbstractHashAlgorithm - The hash algorithm abstraction representation. |
16
|
|
|
* |
17
|
|
|
* @package CryptoManana\Core\Abstractions\MessageDigestion |
18
|
|
|
* |
19
|
|
|
* @mixin SaltingCapabilities |
20
|
|
|
* @mixin DigestOutputFormats |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractHashAlgorithm implements DataSalting, DigestFormatting |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Data salting capabilities. |
26
|
|
|
* |
27
|
|
|
* {@internal Reusable implementation of `SaltingCapabilitiesInterface`. }} |
28
|
|
|
*/ |
29
|
|
|
use SaltingCapabilities; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Digest outputting formats. |
33
|
|
|
* |
34
|
|
|
* {@internal Reusable implementation of `DigestionFormatsInterface`. }} |
35
|
|
|
*/ |
36
|
|
|
use DigestOutputFormats; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The salt string property storage. |
40
|
|
|
* |
41
|
|
|
* @var string The salting string value. |
42
|
|
|
*/ |
43
|
|
|
protected $salt = ''; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The salting mode property storage. |
47
|
|
|
* |
48
|
|
|
* @var int The salting mode integer code value. |
49
|
|
|
*/ |
50
|
|
|
protected $saltingMode = self::SALTING_MODE_APPEND; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The digest output format property storage. |
54
|
|
|
* |
55
|
|
|
* @var int The output format integer code value. |
56
|
|
|
*/ |
57
|
|
|
protected $digestFormat = self::DIGEST_OUTPUT_HEX_UPPER; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Hash algorithm constructor. |
61
|
|
|
*/ |
62
|
|
|
abstract public function __construct(); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Calculates a hash value for the given data. |
66
|
|
|
* |
67
|
|
|
* @param string $data The input string. |
68
|
|
|
* |
69
|
|
|
* @return string The digest. |
70
|
|
|
* @throws \Exception Validation errors. |
71
|
|
|
*/ |
72
|
|
|
abstract public function hashData($data); |
73
|
|
|
} |
74
|
|
|
|