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