Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge up 1.2.2 to 1.3.x #61

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
dependencies:
- "lowest"
- "highest"
Expand Down
18 changes: 8 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,16 @@
"require-dev": {
"ext-gmp": "*",
"ext-openssl": "*",
"ekino/phpstan-banned-code": "^1.0",
"infection/infection": "^0.28",
"ekino/phpstan-banned-code": "^1.0|^2.0|^3.0",
"infection/infection": "^0.28|^0.29",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.3",
"rector/rector": "^1.0",
"phpstan/extension-installer": "^1.3|^2.0",
"phpstan/phpstan": "^1.8|^2.0",
"phpstan/phpstan-deprecation-rules": "^1.0|^2.0",
"phpstan/phpstan-phpunit": "^1.1|^2.0",
"phpstan/phpstan-strict-rules": "^1.3|^2.0",
"rector/rector": "^1.0|^2.0",
"roave/security-advisories": "dev-latest",
"symfony/phpunit-bridge": "^6.4|^7.0",
"symfony/string": "^6.4|^7.0",
"symfony/var-dumper": "^6.4|^7.0",
"symplify/easy-coding-standard": "^12.0",
Expand Down
651 changes: 474 additions & 177 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ parameters:
level: max
paths:
- src
checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: true
checkUninitializedProperties: true
treatPhpDocTypesAsCertain: false
includes:
Expand Down
8 changes: 2 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@
</include>
</source>
<php>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<ini name="xdebug.show_exception_trace" value="0"/>
<ini name="display_errors" value="1"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<server name="SYMFONY_PHPUNIT_VERSION" value="10"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>
</phpunit>
15 changes: 5 additions & 10 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\DataProviderArrayItemsNewLinedRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Symfony\Symfony42\Rector\New_\StringToArrayArgumentProcessRector;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $config): void {
$config->import(SetList::DEAD_CODE);
$config->import(LevelSetList::UP_TO_PHP_81);
$config->import(SetList::PHP_81);
$config->import(SymfonySetList::SYMFONY_50_TYPES);
$config->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
$config->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$config->import(SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION);
$config->import(SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES);
$config->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
$config->import(PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES);
$config->paths([__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']);
$config->skip([
DataProviderArrayItemsNewLinedRector::class,
PreferPHPUnitThisCallRector::class,
StringToArrayArgumentProcessRector::class => [__DIR__ . '/tests'],
]);
$config->skip([DataProviderArrayItemsNewLinedRector::class, PreferPHPUnitThisCallRector::class]);
$config::configure()->withComposerBased(twig: true, phpunit: true);
$config::configure()->withPhpSets();
$config::configure()->withAttributesSets();
$config->phpVersion(PhpVersion::PHP_81);
$config->parallel();
$config->importNames();
Expand Down
2 changes: 1 addition & 1 deletion src/ASN1/Component/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
* Variable is updated to the offset next to the
* parsed identifier. If null, start from offset 0.
*/
public static function fromDER(string $data, int &$offset = null): self
public static function fromDER(string $data, ?int &$offset = null): self
{
$idx = $offset ?? 0;
$datalen = mb_strlen($data, '8bit');
Expand All @@ -97,9 +97,9 @@
$byte = ord($data[$idx++]);
// bits 8 and 7 (class)
// 0 = universal, 1 = application, 2 = context-specific, 3 = private
$class = (0b11000000 & $byte) >> 6;

Check warning on line 100 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "IncrementInteger": @@ @@ $byte = ord($data[$idx++]); // bits 8 and 7 (class) // 0 = universal, 1 = application, 2 = context-specific, 3 = private - $class = (0b11000000 & $byte) >> 6; + $class = (193 & $byte) >> 6; // bit 6 (0 = primitive / 1 = constructed) $pc = (0b100000 & $byte) >> 5; // bits 5 to 1 (tag number)
// bit 6 (0 = primitive / 1 = constructed)
$pc = (0b00100000 & $byte) >> 5;

Check warning on line 102 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "IncrementInteger": @@ @@ // 0 = universal, 1 = application, 2 = context-specific, 3 = private $class = (0b11000000 & $byte) >> 6; // bit 6 (0 = primitive / 1 = constructed) - $pc = (0b100000 & $byte) >> 5; + $pc = (33 & $byte) >> 5; // bits 5 to 1 (tag number) $tag = 0b11111 & $byte; // long-form identifier
// bits 5 to 1 (tag number)
$tag = (0b00011111 & $byte);
// long-form identifier
Expand All @@ -117,17 +117,17 @@
$bytes = [];
$byte = $this->_class << 6 | $this->_pc << 5;
$tag = $this->_tag->getValue();
if ($tag->isLessThan(0x1f)) {

Check warning on line 120 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "DecrementInteger": @@ @@ $bytes = []; $byte = $this->_class << 6 | $this->_pc << 5; $tag = $this->_tag->getValue(); - if ($tag->isLessThan(0x1f)) { + if ($tag->isLessThan(30)) { $bytes[] = $byte | $tag->toInt(); } else { $bytes[] = $byte | 0x1f;

Check warning on line 120 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "IncrementInteger": @@ @@ $bytes = []; $byte = $this->_class << 6 | $this->_pc << 5; $tag = $this->_tag->getValue(); - if ($tag->isLessThan(0x1f)) { + if ($tag->isLessThan(32)) { $bytes[] = $byte | $tag->toInt(); } else { $bytes[] = $byte | 0x1f;
$bytes[] = $byte | $tag->toInt();
} // long-form identifier
else {
$bytes[] = $byte | 0x1f;
$octets = [];
for (; $tag->isGreaterThan(0); $tag = $tag->shiftedRight(7)) {
$octets[] = 0x80 | $tag->and(0x7f)->toInt();

Check warning on line 127 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "IncrementInteger": @@ @@ $bytes[] = $byte | 0x1f; $octets = []; for (; $tag->isGreaterThan(0); $tag = $tag->shiftedRight(7)) { - $octets[] = 0x80 | $tag->and(0x7f)->toInt(); + $octets[] = 129 | $tag->and(0x7f)->toInt(); } // last octet has bit 8 set to zero $octets[0] &= 0x7f;
}
// last octet has bit 8 set to zero
$octets[0] &= 0x7f;

Check warning on line 130 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "Assignment": @@ @@ $octets[] = 0x80 | $tag->and(0x7f)->toInt(); } // last octet has bit 8 set to zero - $octets[0] &= 0x7f; + $octets[0] = 0x7f; foreach (array_reverse($octets) as $octet) { $bytes[] = $octet; }
foreach (array_reverse($octets) as $octet) {
$bytes[] = $octet;
}
Expand Down Expand Up @@ -221,8 +221,8 @@
*/
public function withClass(int $class): self
{
$obj = clone $this;

Check warning on line 224 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "CloneRemoval": @@ @@ */ public function withClass(int $class): self { - $obj = clone $this; + $obj = $this; $obj->_class = 0b11 & $class; return $obj; }
$obj->_class = 0b11 & $class;

Check warning on line 225 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "DecrementInteger": @@ @@ public function withClass(int $class): self { $obj = clone $this; - $obj->_class = 0b11 & $class; + $obj->_class = 2 & $class; return $obj; } /**

Check warning on line 225 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "IncrementInteger": @@ @@ public function withClass(int $class): self { $obj = clone $this; - $obj->_class = 0b11 & $class; + $obj->_class = 4 & $class; return $obj; } /**
return $obj;
}

Expand All @@ -233,7 +233,7 @@
*/
public function withTag(int $tag): self
{
$obj = clone $this;

Check warning on line 236 in src/ASN1/Component/Identifier.php

View workflow job for this annotation

GitHub Actions / 5️⃣ Mutation Testing

Escaped Mutant for Mutator "CloneRemoval": @@ @@ */ public function withTag(int $tag): self { - $obj = clone $this; + $obj = $this; $obj->_tag = BigInt::create($tag); return $obj; }
$obj->_tag = BigInt::create($tag);
return $obj;
}
Expand Down
5 changes: 3 additions & 2 deletions src/ASN1/Component/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function count;
use function mb_strlen;
use function ord;
use function sprintf;

/**
* Class to represent BER/DER length octets.
Expand Down Expand Up @@ -49,7 +50,7 @@ public static function create(BigInteger|int $length, bool $_indefinite = false)
* Variable is updated to the offset next to the
* parsed length component. If null, start from offset 0.
*/
public static function fromDER(string $data, int &$offset = null): self
public static function fromDER(string $data, ?int &$offset = null): self
{
$idx = $offset ?? 0;
$datalen = mb_strlen($data, '8bit');
Expand Down Expand Up @@ -89,7 +90,7 @@ public static function fromDER(string $data, int &$offset = null): self
* @param null|int $expected Expected length, null to bypass checking
* @see self::fromDER
*/
public static function expectFromDER(string $data, int &$offset, int $expected = null): self
public static function expectFromDER(string $data, int &$offset, ?int $expected = null): self
{
$idx = $offset;
$length = self::fromDER($data, $idx);
Expand Down
3 changes: 2 additions & 1 deletion src/ASN1/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use UnexpectedValueException;
use function array_key_exists;
use function mb_strlen;
use function sprintf;

/**
* Base class for all ASN.1 type elements.
Expand Down Expand Up @@ -240,7 +241,7 @@ abstract public function isConstructed(): bool;
* Variable is updated to the offset next to the
* parsed element. If null, start from offset 0.
*/
public static function fromDER(string $data, int &$offset = null): static
public static function fromDER(string $data, ?int &$offset = null): static
{
$idx = $offset ?? 0;
// decode identifier
Expand Down
1 change: 1 addition & 0 deletions src/ASN1/Type/BaseString.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use SpomkyLabs\Pki\ASN1\Element;
use Stringable;
use function sprintf;

/**
* Base class for all string types.
Expand Down
18 changes: 9 additions & 9 deletions src/ASN1/Type/Primitive/GeneralizedTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ final class GeneralizedTime extends BaseTime
* @var string
*/
final public const REGEX = '#^' .
'(\d\d\d\d)' . // YYYY
'(\d\d)' . // MM
'(\d\d)' . // DD
'(\d\d)' . // hh
'(\d\d)' . // mm
'(\d\d)' . // ss
'(?:\.(\d+))?' . // frac
'Z' . // TZ
'$#';
'(\d\d\d\d)' . // YYYY
'(\d\d)' . // MM
'(\d\d)' . // DD
'(\d\d)' . // hh
'(\d\d)' . // mm
'(\d\d)' . // ss
'(?:\.(\d+))?' . // frac
'Z' . // TZ
'$#';

/**
* Cached formatted date.
Expand Down
1 change: 1 addition & 0 deletions src/ASN1/Type/Primitive/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function is_int;
use function is_scalar;
use function is_string;
use function sprintf;
use function strval;

abstract class Number extends Element
Expand Down
1 change: 1 addition & 0 deletions src/ASN1/Type/Primitive/ObjectIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use function is_int;
use function mb_strlen;
use function ord;
use function sprintf;

/**
* Implements *OBJECT IDENTIFIER* type.
Expand Down
39 changes: 20 additions & 19 deletions src/ASN1/Type/Primitive/Real.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use function in_array;
use function mb_strlen;
use function ord;
use function sprintf;
use const INF;

/**
Expand All @@ -38,31 +39,31 @@ final class Real extends Element implements Stringable
* @var string
*/
final public const NR1_REGEX = '/^\s*' .
'(?<s>[+\-])?' . // sign
'(?<i>\d+)' . // integer
'$/';
'(?<s>[+\-])?' . // sign
'(?<i>\d+)' . // integer
'$/';

/**
* Regex pattern to parse NR2 form number.
*
* @var string
*/
final public const NR2_REGEX = '/^\s*' .
'(?<s>[+\-])?' . // sign
'(?<d>(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // decimal number
'$/';
'(?<s>[+\-])?' . // sign
'(?<d>(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // decimal number
'$/';

/**
* Regex pattern to parse NR3 form number.
*
* @var string
*/
final public const NR3_REGEX = '/^\s*' .
'(?<ms>[+\-])?' . // mantissa sign
'(?<m>(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // mantissa
'[Ee](?<es>[+\-])?' . // exponent sign
'(?<e>\d+)' . // exponent
'$/';
'(?<ms>[+\-])?' . // mantissa sign
'(?<m>(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // mantissa
'[Ee](?<es>[+\-])?' . // exponent sign
'(?<e>\d+)' . // exponent
'$/';

/**
* Regex pattern to parse PHP exponent number format.
Expand All @@ -72,14 +73,14 @@ final class Real extends Element implements Stringable
* @var string
*/
final public const PHP_EXPONENT_DNUM = '/^' .
'(?<ms>[+\-])?' . // sign
'(?<m>' .
'\d+' . // LNUM
'|' .
'(?:\d*\.\d+|\d+\.\d*)' . // DNUM
')[eE]' .
'(?<es>[+\-])?(?<e>\d+)' . // exponent
'$/';
'(?<ms>[+\-])?' . // sign
'(?<m>' .
'\d+' . // LNUM
'|' .
'(?:\d*\.\d+|\d+\.\d*)' . // DNUM
')[eE]' .
'(?<es>[+\-])?(?<e>\d+)' . // exponent
'$/';

/**
* Exponent when value is positive or negative infinite.
Expand Down
1 change: 1 addition & 0 deletions src/ASN1/Type/Primitive/RelativeOID.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use function chr;
use function is_int;
use function ord;
use function sprintf;

/**
* Implements *RELATIVE-OID* type.
Expand Down
16 changes: 8 additions & 8 deletions src/ASN1/Type/Primitive/UTCTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ final class UTCTime extends BaseTime
* @var string
*/
final public const REGEX = '#^' .
'(\d\d)' . // YY
'(\d\d)' . // MM
'(\d\d)' . // DD
'(\d\d)' . // hh
'(\d\d)' . // mm
'(\d\d)' . // ss
'Z' . // TZ
'$#';
'(\d\d)' . // YY
'(\d\d)' . // MM
'(\d\d)' . // DD
'(\d\d)' . // hh
'(\d\d)' . // mm
'(\d\d)' . // ss
'Z' . // TZ
'$#';

private function __construct(DateTimeImmutable $dt)
{
Expand Down
1 change: 1 addition & 0 deletions src/ASN1/Type/Tagged/ImplicitlyTaggedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SpomkyLabs\Pki\ASN1\Feature\ElementBase;
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
use UnexpectedValueException;
use function sprintf;

/**
* Implements implicit tagging mode.
Expand Down
1 change: 1 addition & 0 deletions src/ASN1/Type/UnspecifiedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use SpomkyLabs\Pki\ASN1\Type\Tagged\ApplicationType;
use SpomkyLabs\Pki\ASN1\Type\Tagged\PrivateType;
use UnexpectedValueException;
use function sprintf;

/**
* Decorator class to wrap an element without already knowing the specific underlying type.
Expand Down
1 change: 1 addition & 0 deletions src/CryptoBridge/Crypto/OpenSSLCrypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use UnexpectedValueException;
use function array_key_exists;
use function mb_strlen;
use function sprintf;
use const OPENSSL_ALGO_MD4;
use const OPENSSL_ALGO_MD5;
use const OPENSSL_ALGO_SHA1;
Expand Down
18 changes: 9 additions & 9 deletions src/CryptoEncoding/PEM.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ final class PEM implements Stringable
* @var string
*/
final public const PEM_REGEX = '/' .
/* line start */
'(?:^|[\r\n])' .
/* header */
'-----BEGIN (.+?)-----[\r\n]+' .
/* payload */
'(.+?)' .
/* trailer */
'[\r\n]+-----END \\1-----' .
'/ms';
/* line start */
'(?:^|[\r\n])' .
/* header */
'-----BEGIN (.+?)-----[\r\n]+' .
/* payload */
'(.+?)' .
/* trailer */
'[\r\n]+-----END \\1-----' .
'/ms';

/**
* @param string $type Content type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
use UnexpectedValueException;

/*
From RFC 5480 - 2.1.1. Unrestricted Algorithm Identifier and Parameters:

The parameter for id-ecPublicKey is as follows and MUST always be
present:

ECParameters ::= CHOICE {
namedCurve OBJECT IDENTIFIER
-- implicitCurve NULL
-- specifiedCurve SpecifiedECDomain
}
* From RFC 5480 - 2.1.1. Unrestricted Algorithm Identifier and Parameters:
* The parameter for id-ecPublicKey is as follows and MUST always be
* present:
* ECParameters ::= CHOICE {
* namedCurve OBJECT IDENTIFIER
* -- implicitCurve NULL
* -- specifiedCurve SpecifiedECDomain
* }
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier;

/*
From RFC 8410:

For all of the OIDs, the parameters MUST be absent.

It is possible to find systems that require the parameters to be
present. This can be due to either a defect in the original 1997
syntax or a programming error where developers never got input where
this was not true. The optimal solution is to fix these systems;
where this is not possible, the problem needs to be restricted to
that subsystem and not propagated to the Internet.
* From RFC 8410:
* For all of the OIDs, the parameters MUST be absent.
* It is possible to find systems that require the parameters to be
* present. This can be due to either a defect in the original 1997
* syntax or a programming error where developers never got input where
* this was not true. The optimal solution is to fix these systems;
* where this is not possible, the problem needs to be restricted to
* that subsystem and not propagated to the Internet.
*/

/**
Expand Down
Loading
Loading