1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-05 21:48:52 +01:00

X509: add replace parameter to setExtensionValue

This commit is contained in:
terrafrost 2021-04-18 09:57:39 -05:00
parent 0d9d1eedb1
commit 701881d3de

View File

@ -670,16 +670,27 @@ class X509
*/
private function mapOutExtensions(&$root, $path)
{
foreach ($this->extensionValues as $id => $value) {
$root['tbsCertificate']['extensions'][] = [
'extnId' => $id,
'extnValue' => $value[1],
'critical' => $value[0],
];
}
$extensions = &$this->subArray($root, $path);
foreach ($this->extensionValues as $id => $data) {
extract($data);
$newext = [
'extnId' => $id,
'extnValue' => $value,
'critical' => $critical
];
if (!$replace) {
$extensions[] = $newext;
continue;
}
foreach ($extensions as $key => $value) {
if ($value['extnId'] == $id) {
$extensions[$key] = $newext;
break;
}
}
}
if (is_array($extensions)) {
$size = count($extensions);
for ($i = 0; $i < $size; $i++) {
@ -4081,9 +4092,10 @@ class X509
* @param string $id
* @param mixed $value
* @param bool $critical
* @param bool $replace
*/
public function setExtensionValue($id, $value, $critical = false)
public function setExtensionValue($id, $value, $critical = false, $replace = false)
{
$this->extensionValues[$id] = [$critical, $value];
$this->extensionValues[$id] = compact('critical', 'replace', 'value');
}
}