Skip to content

Commit

Permalink
Merge pull request #61 from Spomky-Labs/temp-1a1ed5
Browse files Browse the repository at this point in the history
Merge up 1.2.2 to 1.3.x
  • Loading branch information
Spomky authored Jan 3, 2025
2 parents 2547e68 + 5ac374c commit 0888b72
Show file tree
Hide file tree
Showing 91 changed files with 992 additions and 423 deletions.
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 @@ public static function create(int $class, int $pc, BigInteger|int $tag): self
* 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 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

0 comments on commit 0888b72

Please sign in to comment.