1 | <?php |
||
21 | class Encoder implements TotpEncoderInterface |
||
22 | { |
||
23 | use SecretValidationTrait; |
||
24 | |||
25 | /** |
||
26 | * Encoder constructor. |
||
27 | * |
||
28 | * @param SecretKeyValidator|null $secretKeyValidator |
||
29 | */ |
||
30 | public function __construct(SecretKeyValidator $secretKeyValidator = null) |
||
34 | |||
35 | /** |
||
36 | * @inheritdoc |
||
37 | * @throws InvalidSecretKeyException |
||
38 | */ |
||
39 | public function generateBase32RandomKey(int $length = 16, string $prefix = ''): string |
||
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | public function toBase32(string $value): string |
||
58 | |||
59 | /** |
||
60 | * @inheritdoc |
||
61 | * @throws InvalidSecretKeyException |
||
62 | */ |
||
63 | public function fromBase32(string $value): string |
||
71 | |||
72 | /** |
||
73 | * Get a random number. |
||
74 | * |
||
75 | * @param $from |
||
76 | * @param $to |
||
77 | * |
||
78 | * @throws Exception |
||
79 | * @return int |
||
80 | */ |
||
81 | protected function getRandomNumber(int $from = 0, int $to = 31): int |
||
85 | |||
86 | /** |
||
87 | * Pad string with random base 32 chars. |
||
88 | * |
||
89 | * @param $string |
||
90 | * @param $length |
||
91 | * |
||
92 | * @throws Exception |
||
93 | * @return string |
||
94 | */ |
||
95 | private function strPadBase32(string $string, int $length): string |
||
103 | } |
||
104 |