1 | <?php |
||
19 | class Hash extends Rule |
||
20 | { |
||
21 | const ALGO_MD5 = 'md5'; |
||
22 | const ALGO_SHA1 = 'sha1'; |
||
23 | const ALGO_SHA256 = 'sha256'; |
||
24 | const ALGO_SHA512 = 'sha512'; |
||
25 | const ALGO_CRC32 = 'crc32'; |
||
26 | |||
27 | /** |
||
28 | * A constant that will be used when the value is not a valid cryptographic hash. |
||
29 | */ |
||
30 | const INVALID_FORMAT = 'Hash::INVALID_FORMAT'; |
||
31 | |||
32 | /** |
||
33 | * The message templates which can be returned by this validator. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $messageTemplates = [ |
||
38 | self::INVALID_FORMAT => '{{ name }} must be a valid hash' |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $hashAlgorithm; |
||
45 | |||
46 | /** |
||
47 | * @var bool |
||
48 | */ |
||
49 | protected $allowUppercase; |
||
50 | |||
51 | /** |
||
52 | * Construct the Hash validator. |
||
53 | * |
||
54 | * @param string $hashAlgorithm |
||
55 | * @param bool $allowUppercase |
||
56 | */ |
||
57 | 12 | public function __construct($hashAlgorithm, $allowUppercase = false) |
|
66 | |||
67 | /** |
||
68 | * Validates if the value is a valid cryptographic hash. |
||
69 | * |
||
70 | * @param mixed $value |
||
71 | * @return bool |
||
72 | * @throws Exception |
||
73 | */ |
||
74 | 12 | public function validate($value) |
|
94 | |||
95 | /** |
||
96 | * @param string $value |
||
97 | * @param int $length |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | 12 | private function validateHexString($value, $length) |
|
107 | } |
||
108 |