| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Password; |
| 15: | |
| 16: | final readonly class Password |
| 17: | { |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public static function fromAlgorithm(string $algo, array $options = []): HashInterface |
| 36: | { |
| 37: | $algorithm = Algorithm::tryFrom($algo); |
| 38: | |
| 39: | return match ($algorithm) { |
| 40: | Algorithm::Argon2i => new Hash\Argon2iHash($algorithm, $options), |
| 41: | Algorithm::Argon2id => new Hash\Argon2idHash($algorithm, $options), |
| 42: | Algorithm::Bcrypt => new Hash\BcryptHash($algorithm, $options), |
| 43: | Algorithm::Pbkdf2HmacSha1, |
| 44: | Algorithm::Pbkdf2HmacSha256, |
| 45: | Algorithm::Pbkdf2HmacSha512 => new Hash\Pbkdf2Hash($algorithm, $options), |
| 46: | Algorithm::Sodium => new Hash\SodiumHash($algorithm, $options), |
| 47: | default => throw new HashException(\sprintf('Unsupported "%s" algorithm.', $algo)), |
| 48: | }; |
| 49: | } |
| 50: | } |
| 51: | |