Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
1441 ariadna 3
declare(strict_types=1);
1 efrain 4
 
5
namespace OTPHP;
6
 
7
interface OTPInterface
8
{
1441 ariadna 9
    public const DEFAULT_DIGITS = 6;
10
 
11
    public const DEFAULT_DIGEST = 'sha1';
12
 
1 efrain 13
    /**
1441 ariadna 14
     * Create a OTP object from an existing secret.
1 efrain 15
     *
1441 ariadna 16
     * @param non-empty-string $secret
1 efrain 17
     */
1441 ariadna 18
    public static function createFromSecret(string $secret): self;
1 efrain 19
 
20
    /**
1441 ariadna 21
     * Create a new OTP object. A random 64 bytes secret will be generated.
22
     */
23
    public static function generate(): self;
24
 
25
    /**
26
     * @param non-empty-string $secret
27
     */
28
    public function setSecret(string $secret): void;
29
 
30
    public function setDigits(int $digits): void;
31
 
32
    /**
33
     * @param non-empty-string $digest
34
     */
35
    public function setDigest(string $digest): void;
36
 
37
    /**
38
     * Generate the OTP at the specified input.
1 efrain 39
     *
1441 ariadna 40
     * @param 0|positive-int $input
1 efrain 41
     *
1441 ariadna 42
     * @return non-empty-string Return the OTP at the specified timestamp
1 efrain 43
     */
1441 ariadna 44
    public function at(int $input): string;
1 efrain 45
 
46
    /**
1441 ariadna 47
     * Verify that the OTP is valid with the specified input. If no input is provided, the input is set to a default
48
     * value or false is returned.
49
     *
50
     * @param non-empty-string $otp
51
     * @param null|0|positive-int $input
52
     * @param null|0|positive-int $window
1 efrain 53
     */
1441 ariadna 54
    public function verify(string $otp, null|int $input = null, null|int $window = null): bool;
55
 
56
    /**
57
     * @return non-empty-string The secret of the OTP
58
     */
1 efrain 59
    public function getSecret(): string;
60
 
61
    /**
1441 ariadna 62
     * @param non-empty-string $label The label of the OTP
1 efrain 63
     */
1441 ariadna 64
    public function setLabel(string $label): void;
1 efrain 65
 
66
    /**
1441 ariadna 67
     * @return non-empty-string|null The label of the OTP
1 efrain 68
     */
1441 ariadna 69
    public function getLabel(): null|string;
1 efrain 70
 
71
    /**
1441 ariadna 72
     * @return non-empty-string|null The issuer
1 efrain 73
     */
1441 ariadna 74
    public function getIssuer(): ?string;
1 efrain 75
 
76
    /**
1441 ariadna 77
     * @param non-empty-string $issuer
1 efrain 78
     */
1441 ariadna 79
    public function setIssuer(string $issuer): void;
1 efrain 80
 
81
    /**
82
     * @return bool If true, the issuer will be added as a parameter in the provisioning URI
83
     */
84
    public function isIssuerIncludedAsParameter(): bool;
85
 
1441 ariadna 86
    public function setIssuerIncludedAsParameter(bool $issuer_included_as_parameter): void;
1 efrain 87
 
88
    /**
1441 ariadna 89
     * @return positive-int Number of digits in the OTP
1 efrain 90
     */
91
    public function getDigits(): int;
92
 
93
    /**
1441 ariadna 94
     * @return non-empty-string Digest algorithm used to calculate the OTP. Possible values are 'md5', 'sha1', 'sha256' and 'sha512'
1 efrain 95
     */
96
    public function getDigest(): string;
97
 
98
    /**
1441 ariadna 99
     * @param non-empty-string $parameter
1 efrain 100
     */
1441 ariadna 101
    public function getParameter(string $parameter): mixed;
1 efrain 102
 
103
    /**
1441 ariadna 104
     * @param non-empty-string $parameter
1 efrain 105
     */
106
    public function hasParameter(string $parameter): bool;
107
 
108
    /**
1441 ariadna 109
     * @return array<non-empty-string, mixed>
1 efrain 110
     */
111
    public function getParameters(): array;
112
 
113
    /**
1441 ariadna 114
     * @param non-empty-string $parameter
1 efrain 115
     */
1441 ariadna 116
    public function setParameter(string $parameter, mixed $value): void;
1 efrain 117
 
118
    /**
1441 ariadna 119
     * Get the provisioning URI.
120
     *
121
     * @return non-empty-string
1 efrain 122
     */
123
    public function getProvisioningUri(): string;
124
 
125
    /**
1441 ariadna 126
     * Get the provisioning URI.
1 efrain 127
     *
1441 ariadna 128
     * @param non-empty-string $uri         The Uri of the QRCode generator with all parameters. This Uri MUST contain a placeholder that will be replaced by the method.
129
     * @param non-empty-string $placeholder the placeholder to be replaced in the QR Code generator URI
1 efrain 130
     */
1441 ariadna 131
    public function getQrCodeUri(string $uri, string $placeholder): string;
1 efrain 132
}