-
Notifications
You must be signed in to change notification settings - Fork 8
/
ParsedKey.php
92 lines (74 loc) · 1.91 KB
/
ParsedKey.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* This file is part of the Acme PHP project.
*
* (c) Titouan Galopin <galopintitouan@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AcmePhp\Ssl;
use Webmozart\Assert\Assert;
/**
* Represent the content of a parsed key.
*
* @see openssl_pkey_get_details
*
* @author Titouan Galopin <galopintitouan@gmail.com>
*/
class ParsedKey
{
/** @var Key */
private $source;
/** @var string */
private $key;
/** @var int */
private $bits;
/** @var int */
private $type;
/** @var array */
private $details;
public function __construct(Key $source, string $key, int $bits, int $type, array $details = [])
{
Assert::stringNotEmpty($key, __CLASS__.'::$key expected a non empty string. Got: %s');
Assert::oneOf(
$type,
[OPENSSL_KEYTYPE_RSA, OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH, OPENSSL_KEYTYPE_EC],
__CLASS__.'::$type expected one of: %2$s. Got: %s'
);
$this->source = $source;
$this->key = $key;
$this->bits = $bits;
$this->type = $type;
$this->details = $details;
}
public function getSource(): Key
{
return $this->source;
}
public function getKey(): string
{
return $this->key;
}
public function getBits(): int
{
return $this->bits;
}
public function getType(): int
{
return $this->type;
}
public function getDetails(): array
{
return $this->details;
}
public function hasDetail(string $name): bool
{
return isset($this->details[$name]);
}
public function getDetail(string $name)
{
Assert::oneOf($name, array_keys($this->details), 'ParsedKey::getDetail() expected one of: %2$s. Got: %s');
return $this->details[$name];
}
}