Skip to content

Commit fe14173

Browse files
committed
detaching parent for base object and it's children
1 parent fa9e3d9 commit fe14173

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/CMS/SignerInfo.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,29 @@ private function getSigningCert()
9999
}
100100

101101
/**
102-
* FIXME: shouldn't return ASN1Object
103102
* Signed Attributes
104-
* @return ExplicitlyTaggedObject
103+
* @return ExplicitlyTaggedObject|ASN1\ASN1ObjectInterface
105104
* @throws Exception
106105
*/
107106
public function getSignedAttributes()
108107
{
109108
$exTaggedObjects = $this->object->findChildrenByType(ExplicitlyTaggedObject::class);
109+
/** @var ExplicitlyTaggedObject[] $attributes */
110110
$attributes = array_filter($exTaggedObjects, function ($value) {
111111
return $value->getIdentifier()->getTagNumber() === 0;
112112
});
113113

114-
return array_pop($attributes);
114+
// if we return attributes as is - we give reference to parent so any object can be changed directly.
115+
// so lets detach from parent first
116+
$object = array_pop($attributes)->detach();
117+
118+
// now replace all children creating them from binary.
119+
foreach ($object->getChildren() as $child) {
120+
$binary = $child->getBinary();
121+
$object->replaceChild($child, Sequence::fromBinary($binary));
122+
}
123+
124+
return $object;
115125
}
116126

117127
/**

0 commit comments

Comments
 (0)