PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.1
Defender Security – Malware Scanner, Login Security & Firewall v5.6.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / web-auth / cose-lib / src / Hash.php

Hash.php in Defender Security – Malware Scanner, Login Security & Firewall 5.6.1, at vendor/web-auth/cose-lib/src/Hash.php

104 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * The MIT License (MIT)
7 *
8 * Copyright (c) 2014-2021 Spomky-Labs
9 *
10 * This software may be modified and distributed under the terms
11 * of the MIT license. See the LICENSE file for details.
12 */
13
14 namespace Cose;
15
16 /**
17 * @internal
18 */
19 class Hash
20 {
21 /**
22 * Hash Parameter.
23 *
24 * @var string
25 */
26 private $hash;
27
28 /**
29 * DER encoding T.
30 *
31 * @var string
32 */
33 private $t;
34
35 /**
36 * Hash Length.
37 *
38 * @var int
39 */
40 private $length;
41
42 private function __construct(string $hash, int $length, string $t)
43 {
44 $this->hash = $hash;
45 $this->length = $length;
46 $this->t = $t;
47 }
48
49 /**
50 * @return Hash
51 */
52 public static function sha1(): self
53 {
54 return new self('sha1', 20, "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14");
55 }
56
57 /**
58 * @return Hash
59 */
60 public static function sha256(): self
61 {
62 return new self('sha256', 32, "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20");
63 }
64
65 /**
66 * @return Hash
67 */
68 public static function sha384(): self
69 {
70 return new self('sha384', 48, "\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30");
71 }
72
73 /**
74 * @return Hash
75 */
76 public static function sha512(): self
77 {
78 return new self('sha512', 64, "\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40");
79 }
80
81 public function getLength(): int
82 {
83 return $this->length;
84 }
85
86 /**
87 * Compute the HMAC.
88 */
89 public function hash(string $text): string
90 {
91 return hash($this->hash, $text, true);
92 }
93
94 public function name(): string
95 {
96 return $this->hash;
97 }
98
99 public function t(): string
100 {
101 return $this->t;
102 }
103 }
104