From 02a246480aa12de3c6cd085c77e37a188fc29810 Mon Sep 17 00:00:00 2001 From: Elias Olivtradet Date: Sat, 19 Sep 2026 17:22:43 +0200 Subject: [PATCH] fix: build the signature document without reading it back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit XadesSignature::build() reached for SignatureValue through element(), which reads $this->document — a property the constructor only assigns once build() returns, so every signature threw on construction. The element is now created and given its Id directly. Container::save() called @unlink on a temporary file that does not exist on a first save; it checks for the file instead, so no warning is raised. --- .gitignore | 1 + src/Container/Container.php | 9 ++++++--- src/Signature/XadesSignature.php | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 67dd1b0..8f50208 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock .phpunit.result.cache .DS_Store +.phpunit.cache/ diff --git a/src/Container/Container.php b/src/Container/Container.php index f3bda96..9501811 100644 --- a/src/Container/Container.php +++ b/src/Container/Container.php @@ -194,7 +194,10 @@ public function save(?string $path = null): string { $path = $path ?? $this->path ?? throw new RuntimeException('No path to save the container to.'); $temporary = $path.'.tmp'; - @unlink($temporary); + + if (is_file($temporary)) { + unlink($temporary); + } $zip = new ZipArchive; @@ -229,7 +232,7 @@ public function contents(): string $path = tempnam(sys_get_temp_dir(), 'asice-'); $this->save($path); $bytes = (string) file_get_contents($path); - @unlink($path); + unlink($path); return $bytes; } @@ -322,4 +325,4 @@ private function fetchIssuer(Certificate $certificate): ?Certificate return null; } } -} +} \ No newline at end of file diff --git a/src/Signature/XadesSignature.php b/src/Signature/XadesSignature.php index f19380b..d713f6f 100644 --- a/src/Signature/XadesSignature.php +++ b/src/Signature/XadesSignature.php @@ -278,8 +278,9 @@ private function build(): DOMDocument $signedInfo->appendChild($reference); } - $signature->appendChild($document->createElementNS(self::DSIG, 'ds:SignatureValue', '')); - $this->element('SignatureValue')->setAttribute('Id', $this->signatureId.'-SIG'); + $signatureValue = $document->createElementNS(self::DSIG, 'ds:SignatureValue', ''); + $signatureValue->setAttribute('Id', $this->signatureId.'-SIG'); + $signature->appendChild($signatureValue); $keyInfo = $document->createElementNS(self::DSIG, 'ds:KeyInfo'); $keyInfo->setAttribute('Id', $this->signatureId.'-KEYINFO'); @@ -361,4 +362,4 @@ private function build(): DOMDocument return $document; } -} +} \ No newline at end of file