Skip to content
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.10.11 2026-11-25

Mutation testing is now up to 98%

## v1.10.10 2026-11-25
## v1.10.9 2026-11-25

Expand Down
4 changes: 2 additions & 2 deletions infection.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
}
},
"tmpDir": "build/cache/infection",
"minMsi": 95,
"minCoveredMsi": 95,
"minMsi": 97,
"minCoveredMsi": 97,
"mutators": {
"@default": true,
},
Expand Down
7 changes: 6 additions & 1 deletion src/Rfc9421/Dto/ComponentItemDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ private static function validFieldName(Item $item): string
private static function ensureStringValue(
Bytes|Token|DisplayString|DateTimeImmutable|string|int|float|bool $v,
): string {
return is_string($v) ? $v : throw new UnexpectedValue(
if (is_string($v)) {
return $v;
}
// @codeCoverageIgnoreStart
throw new UnexpectedValue(
sprintf('Expected string, got "%s"', gettype($v)),
);
// @codeCoverageIgnoreEnd
}

public function getItem(): Item
Expand Down
5 changes: 1 addition & 4 deletions src/Rfc9421/Enums/DigestAlgorithmsEnum.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright (c) 2026.
* e-mail: rt@filefabrik.com
Expand Down Expand Up @@ -31,10 +32,6 @@ enum DigestAlgorithmsEnum: string
*/
public static function isOwnTypeOrThrow(self|string|null $key): self
{
if ($key instanceof self) {
return $key;
}

if (($res = self::isOwnType($key)) instanceof self) {
return $res;
}
Expand Down
1 change: 1 addition & 0 deletions src/Rfc9421/Signer/Metadata.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright (c) 2026.
* e-mail: rt@filefabrik.com
Expand Down
4 changes: 2 additions & 2 deletions src/Rfc9421/Signer/SigCompilerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function makeSig1fromComponents(SigningComponents $components, str
/**
* simple helper
*/
public static function wrapBraces(string $string): string
private static function wrapBraces(string $string): string
{
return sprintf('(%s)', $string);
}
Expand All @@ -61,7 +61,7 @@ public static function wrapBraces(string $string): string
* todo that is wrong, must use the component-parser
*
*/
public static function compileFromArrayComponent(SigningComponents $components): string
private static function compileFromArrayComponent(SigningComponents $components): string
{
$parts = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Rfc9421/Signer/SignBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function calculateSignature(): string
/**
* Create the hash
*/
public function hash(): string
private function hash(): string
{
return hash(
algo : $this->algorithm
Expand Down
14 changes: 11 additions & 3 deletions src/Rfc9421/Signer/Signatures/ReadLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

namespace Filefabrik\Rfc9421\Signer\Signatures;

use Filefabrik\Rfc9421\Exceptions\UnexpectedValue;

/**
* after verify, so nothing can be written into the ReadLines
*/
final class ReadLines extends AbstractLines
{
/**
* @param array<string|int,string|\Filefabrik\Rfc9421\Signer\Signatures\Line>|array{}|\Filefabrik\Rfc9421\Signer\Signatures\WriteLines $lines
*
* @throws \Filefabrik\Rfc9421\Exceptions\UnexpectedValue
*/
public function __construct(array|WriteLines $lines)
{
Expand All @@ -26,6 +30,8 @@ public function __construct(array|WriteLines $lines)

/**
* @param array<string|int,string|\Filefabrik\Rfc9421\Signer\Signatures\Line>|array{}|\Filefabrik\Rfc9421\Signer\Signatures\WriteLines $lines
*
* @throws \Filefabrik\Rfc9421\Exceptions\UnexpectedValue
*/
private function setup(array|WriteLines $lines): void
{
Expand All @@ -36,10 +42,12 @@ private function setup(array|WriteLines $lines): void
foreach ($lines as $key => $line) {
if ($line instanceof Line && is_int($key)) {
$this->protectedAdd($line);
} else {
/* @var string $key */
/* @var string $line */
} elseif ((is_string($line) || is_int($line)) && is_string($key)) {
$this->protectedAddEntry($key, $line);
} else {
throw new UnexpectedValue(
sprintf('Unexpected value of type %s or key of type %s', gettype($line), gettype($key)),
);
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/Rfc9421/Signer/TraitSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,11 @@ private function updateHeadersBeforePrepare(): void
/**
* Generate the base signature
*
*
*
* @throws \Filefabrik\Rfc9421\Exceptions\EmptyException
* @throws \Filefabrik\Rfc9421\Exceptions\SignatureException
* @throws \Filefabrik\Rfc9421\Exceptions\UnexpectedValue
*/
public function crypt(string $signingParametersString): string
private function crypt(string $signingParametersString): string
{
$signature = SignatureRegistry::signing(
signingEnumInterface: SigningEnum::isOwnTypeOrThrow($this->signingConfiguration->getMetadata()->alg),
Expand All @@ -193,7 +191,7 @@ public function crypt(string $signingParametersString): string
* @return string $signatureKeyName:$signature:
*
*/
public function makeSignatureString(string $signature): string
private function makeSignatureString(string $signature): string
{
return sprintf($this->signingConfiguration->getSignatureKeyName().':%s:', $signature);
}
Expand All @@ -203,7 +201,11 @@ public function makeSignatureString(string $signature): string
*/
public function getSigningParametersStringOrThrow(): string
{
return $this->signingParametersString ?? throw ProcessingException::signingParametersString();
if (is_string($this->signingParametersString)) {
return $this->signingParametersString;
}

return throw ProcessingException::signingParametersString();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Rfc9421/StructuredFields/Processing/Bs.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function handle(
if (0 < count($values)) {
$valuesSegments = [];
foreach ($values as $value) {
$valuesSegments [] = ':'.base64_encode(trim($value)).':';
$valuesSegments [] = ':'.base64_encode($value).':';
}

// all in a line
Expand Down
9 changes: 6 additions & 3 deletions src/Rfc9421/Support/AbstractMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function hasTag(): bool
* @throws \Filefabrik\Rfc9421\Exceptions\SignatureException
* @throws \Filefabrik\Rfc9421\Exceptions\UnexpectedValue
*/
public function set(string $key, int|string|null $value): static
public function set(string $key, int|string|null|SigningEnumInterface $value): static
{
$methodName = 'set'.ucfirst($key);

Expand Down Expand Up @@ -122,6 +122,7 @@ public function setNonce(?string $nonce): static
*/
private function setStringOrNull(mixed $value): ?string
{
// todo signature exception or metadata exception
return null === $value || is_string($value) ? $value :
throw new UnexpectedValue('$value must be string|null');
}
Expand All @@ -148,8 +149,10 @@ public function setAlg(string|SigningEnumInterface $alg): static
*/
private function setStringOrSigningEnum(mixed $value): string|SigningEnumInterface
{
return is_string($value) || $value instanceof SigningEnumInterface ? $value :
throw SignatureException::wrongFormat();
if (is_string($value) || $value instanceof SigningEnumInterface) {
return $value;
}
throw SignatureException::wrongFormat();
}

public function setTag(?string $tag): static
Expand Down
22 changes: 2 additions & 20 deletions src/Rfc9421/Verify/AbstractVerifyPrepare.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace Filefabrik\Rfc9421\Verify;

use Filefabrik\Rfc9421\Exceptions\UnexpectedValue;
use Filefabrik\Rfc9421\Exceptions\VerifyHeaderSignatureException;
use Filefabrik\Rfc9421\Extractors\ContentDigest;
use Filefabrik\Rfc9421\Extractors\HeaderSignature;
Expand Down Expand Up @@ -79,7 +78,7 @@ public function prepareVerification(): bool
*/
Metadata::bindMetadata(
instance: $this->signingConfiguration->getMetadata(),
metadata: $this->getExtractedMetadataArray(),
metadata: $this->getSignaturInputInstance()->extractedMetadata->toArray(),
);

/*
Expand All @@ -103,31 +102,14 @@ public function getHeaderSignatureExtractor(): HeaderSignature
return $this->headerSignatureExtractor;
}

/**
*
* @throws \Filefabrik\Rfc9421\Exceptions\AlreadySetException
* @throws \Filefabrik\Rfc9421\Exceptions\UnexpectedValue
* @throws \Filefabrik\Rfc9421\Exceptions\SignatureException
* @throws \Filefabrik\Rfc9421\Exceptions\SignatureExtractionException
* @throws \Filefabrik\Rfc9421\Exceptions\UnexpectedValue
* @throws \Filefabrik\Rfc9421\Exceptions\VerifyHeaderSignatureException
* @return array{}|array{created?: int, expires?: int, nonce?: string, keyid?: string, alg?: string, tag?: string}
*/
protected function getExtractedMetadataArray(): array
{
return $this->getSignaturInputInstance()->extractedMetadata?->toArray() ?? throw new UnexpectedValue(
'No Metadata Found',
);
}

/**
* @throws \Filefabrik\Rfc9421\Exceptions\AlreadySetException
* @throws \Filefabrik\Rfc9421\Exceptions\SignatureException
* @throws \Filefabrik\Rfc9421\Exceptions\SignatureExtractionException
* @throws \Filefabrik\Rfc9421\Exceptions\UnexpectedValue
* @throws \Filefabrik\Rfc9421\Exceptions\VerifyHeaderSignatureException
*/
protected function getSignaturInputInstance(): HeaderSignatureInput
private function getSignaturInputInstance(): HeaderSignatureInput
{
$headerSignatureInstance = new HeaderSignatureInput(
headerSignatureInputValue: $this->headerHelper
Expand Down
24 changes: 12 additions & 12 deletions src/Rfc9421/Verify/AbstractVerifying.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function verifying(): bool
$preparedSigningConfiguration = $this->getVerifySigningConfiguration();
$preparedSigningConfiguration->setSigningComponents(
components: $this->preparedVerify
->getSignatureInputInstance()
->getExtractedComponents(),
->getSignatureInputInstance()
->getExtractedComponents(),
);

$contentDigestResult = $this->verifyContentDigestIfNeed($preparedSigningConfiguration);
Expand Down Expand Up @@ -100,22 +100,19 @@ private function verifyContentDigestIfNeed(SigningConfiguration $signingConfigur
// Validates the Content digest if needed from signature-line sig1=("content-digest")
if ($signingConfiguration->hasContentDigestHashAlgo()) {
if (!$this->validateContentDigest()) {
$this->hasSignedBody = false;

// todo logging the error that validate content digest is wrong
return false;
return $this->hasSignedBody = false;
}

// was signed and is valid
$this->hasSignedBody = true;
}

if(null===$this->hasSignedBody){
if (null === $this->hasSignedBody) {
// content-digest was not part of the signing process
$this->hasSignedBody = false;
}


// return true so tell we have no validation error
return true;
}
Expand All @@ -128,8 +125,8 @@ private function verifyContentDigestIfNeed(SigningConfiguration $signingConfigur
private function validateContentDigest(): bool
{
$contentDigestLine = $this->preparedVerify
->getHeaderHelper()
->getContentDigestLine()
->getHeaderHelper()
->getContentDigestLine()
;

$verifyInstance = new VerifyContentDigest(
Expand All @@ -149,8 +146,8 @@ abstract protected function getSigner(): RequestSigner|ResponseSigner;
private function getBinarySignatureValue(): string
{
return $this->preparedVerify
->getHeaderSignatureExtractor()
->getBinarySignatureValue()
->getHeaderSignatureExtractor()
->getBinarySignatureValue()
;
}

Expand All @@ -159,7 +156,10 @@ private function getBinarySignatureValue(): string
*/
public function getSignedHeaderLines(): ReadLines
{
return $this->signedHeaderLines ?? throw ProcessingException::SignedHeaderLines();
if ($this->signedHeaderLines instanceof ReadLines) {
return $this->signedHeaderLines;
}
throw ProcessingException::SignedHeaderLines();
}

abstract public function getMessage(): MessageInterface;
Expand Down
8 changes: 6 additions & 2 deletions src/Rfc9421/Verify/HeaderSignatureInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
* if the signatureNameKey not set/null, then detect it during the extract
*
*/
private(set) readonly string $signatureNameKey
private(set) readonly string $signatureNameKey,
) {
}

Expand Down Expand Up @@ -103,7 +103,11 @@ private function extractSignatureString(): string
*/
public function getExtractedComponents(): SigningComponents
{
return $this->extractedComponents ?? throw SignatureExtractionException::notProceeded();
if ($this->extractedComponents instanceof SigningComponents) {
return $this->extractedComponents;
}

throw SignatureExtractionException::notProceeded();
}

}
4 changes: 2 additions & 2 deletions src/Rfc9421/Verify/VerifyContentDigest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function __construct(
}

/**
* @return bool true if valid
* @throws \Filefabrik\Rfc9421\Exceptions\ContentDigestException
* @return bool true if valid
*/
public function verify(): bool
{
Expand All @@ -40,7 +40,7 @@ public function verify(): bool
/**
* @throws \Filefabrik\Rfc9421\Exceptions\ContentDigestException
*/
public function getContentDigestVerifier(): ContentDigest
private function getContentDigestVerifier(): ContentDigest
{
if (null === $this->contentDigestVerifier) {
$this->contentDigestVerifier = $this->prepare();
Expand Down
8 changes: 8 additions & 0 deletions tests/Rfc9421/Enums/InitialContentsEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function testIsOwnTypeOrNullOrThrowException(): void
InitialContentsEnum::isOwnTypeOrNullOrThrow('nothing');
}

/**
* @throws \Filefabrik\Rfc9421\Exceptions\EnumTypeException
*/
public function testIsOwnTypeOrNullOrThrowNull(): void
{
self::assertNull(InitialContentsEnum::isOwnTypeOrNullOrThrow(null));
}

/**
* @throws \Filefabrik\Rfc9421\Exceptions\EnumTypeException
*/
Expand Down
Loading