aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/spomky-labs/otphp/src/OTPInterface.php
blob: 3b27f54564106cb02e3115e43c8ea6d976b7f539 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php

declare(strict_types=1);

namespace OTPHP;

interface OTPInterface
{
    public const DEFAULT_DIGITS = 6;

    public const DEFAULT_DIGEST = 'sha1';

    /**
     * Create a OTP object from an existing secret.
     *
     * @param non-empty-string $secret
     */
    public static function createFromSecret(string $secret): self;

    /**
     * Create a new OTP object. A random 64 bytes secret will be generated.
     */
    public static function generate(): self;

    /**
     * @param non-empty-string $secret
     */
    public function setSecret(string $secret): void;

    public function setDigits(int $digits): void;

    /**
     * @param non-empty-string $digest
     */
    public function setDigest(string $digest): void;

    /**
     * @return string Return the OTP at the specified timestamp
     */
    public function at(int $input): string;

    /**
     * Verify that the OTP is valid with the specified input. If no input is provided, the input is set to a default
     * value or false is returned.
     */
    public function verify(string $otp, null|int $input = null, null|int $window = null): bool;

    /**
     * @return string The secret of the OTP
     */
    public function getSecret(): string;

    /**
     * @param string $label The label of the OTP
     */
    public function setLabel(string $label): void;

    /**
     * @return string|null The label of the OTP
     */
    public function getLabel(): null|string;

    /**
     * @return string|null The issuer
     */
    public function getIssuer(): ?string;

    public function setIssuer(string $issuer): void;

    /**
     * @return bool If true, the issuer will be added as a parameter in the provisioning URI
     */
    public function isIssuerIncludedAsParameter(): bool;

    public function setIssuerIncludedAsParameter(bool $issuer_included_as_parameter): void;

    /**
     * @return int Number of digits in the OTP
     */
    public function getDigits(): int;

    /**
     * @return string Digest algorithm used to calculate the OTP. Possible values are 'md5', 'sha1', 'sha256' and 'sha512'
     */
    public function getDigest(): string;

    public function getParameter(string $parameter): mixed;

    public function hasParameter(string $parameter): bool;

    /**
     * @return array<string, mixed>
     */
    public function getParameters(): array;

    public function setParameter(string $parameter, mixed $value): void;

    /**
     * Get the provisioning URI.
     */
    public function getProvisioningUri(): string;

    /**
     * Get the provisioning URI.
     *
     * @param string $uri         The Uri of the QRCode generator with all parameters. This Uri MUST contain a placeholder that will be replaced by the method.
     * @param string $placeholder the placeholder to be replaced in the QR Code generator URI
     */
    public function getQrCodeUri(string $uri, string $placeholder): string;
}