forked from acmephp/ssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParsedKey.php
125 lines (107 loc) · 2.39 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?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;
/**
* @param Key $source
* @param string $key
* @param int $bits
* @param int $type
* @param array $details
*/
public function __construct(Key $source, $key, $bits, $type, array $details = [])
{
Assert::stringNotEmpty($key, __CLASS__.'::$key expected a non empty string. Got: %s');
Assert::integer($bits, __CLASS__.'::$bits expected an integer. 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;
}
/**
* @return Key
*/
public function getSource()
{
return $this->source;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @return int
*/
public function getBits()
{
return $this->bits;
}
/**
* @return int
*/
public function getType()
{
return $this->type;
}
/**
* @return array
*/
public function getDetails()
{
return $this->details;
}
/**
* @param string $name
*
* @return bool
*/
public function hasDetail($name)
{
return isset($this->details[$name]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getDetail($name)
{
Assert::oneOf($name, array_keys($this->details), 'ParsedKey::getDetail() expected one of: %2$s. Got: %s');
return $this->details[$name];
}
}