PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.3.1
Defender Security – Malware Scanner, Login Security & Firewall v5.3.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 / Key / OkpKey.php

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

68 lines 1.7 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\Key;
15
16 use function array_key_exists;
17 use Assert\Assertion;
18
19 class OkpKey extends Key
20 {
21 public const CURVE_X25519 = 4;
22 public const CURVE_X448 = 5;
23 public const CURVE_ED25519 = 6;
24 public const CURVE_ED448 = 7;
25
26 public const DATA_CURVE = -1;
27 public const DATA_X = -2;
28 public const DATA_D = -4;
29
30 private const SUPPORTED_CURVES = [
31 self::CURVE_X25519,
32 self::CURVE_X448,
33 self::CURVE_ED25519,
34 self::CURVE_ED448,
35 ];
36
37 public function __construct(array $data)
38 {
39 parent::__construct($data);
40 Assertion::eq($data[self::TYPE], self::TYPE_OKP, 'Invalid OKP key. The key type does not correspond to an OKP key');
41 Assertion::keyExists($data, self::DATA_CURVE, 'Invalid EC2 key. The curve is missing');
42 Assertion::keyExists($data, self::DATA_X, 'Invalid OKP key. The x coordinate is missing');
43 Assertion::inArray((int) $data[self::DATA_CURVE], self::SUPPORTED_CURVES, 'The curve is not supported');
44 }
45
46 public function x(): string
47 {
48 return $this->get(self::DATA_X);
49 }
50
51 public function isPrivate(): bool
52 {
53 return array_key_exists(self::DATA_D, $this->getData());
54 }
55
56 public function d(): string
57 {
58 Assertion::true($this->isPrivate(), 'The key is not private');
59
60 return $this->get(self::DATA_D);
61 }
62
63 public function curve(): int
64 {
65 return (int) $this->get(self::DATA_CURVE);
66 }
67 }
68