Debian Codegraph @

lib/3rdParty/composer/web-auth/cose-lib/src/Hash.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Cose;
6
7 /**
8 * @internal
9 */
10 final class Hash
11 {
12 private function __construct(
13 private readonly string $hash,
14 private readonly int $length,
15 private readonly string $t
16 ) {
17 }
18
19 public static function sha1(): self
20 {
21 return new self('sha1', 20, "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14");
22 }
23
24 public static function sha256(): self
25 {
26 return new self('sha256', 32, "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20");
27 }
28
29 public static function sha384(): self
30 {
31 return new self('sha384', 48, "\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30");
32 }
33
34 public static function sha512(): self
35 {
36 return new self('sha512', 64, "\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40");
37 }
38
39 public function getLength(): int
40 {
41 return $this->length;
42 }
43
44 /**
45 * Compute the HMAC.
46 */
47 public function hash(string $text): string
48 {
49 return hash($this->hash, $text, true);
50 }
51
52 public function name(): string
53 {
54 return $this->hash;
55 }
56
57 public function t(): string
58 {
59 return $this->t;
60 }
61 }