Skip to content
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
17 changes: 6 additions & 11 deletions .ci-tools/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ parameters:
count: 1
path: ../src/Algorithm/Signature/ECDSA/ECDSA.php

-
rawMessage: "Strict comparison using === between '30' and '81' will always evaluate to false."
identifier: identical.alwaysFalse
count: 1
path: ../src/Algorithm/Signature/ECDSA/ECSignature.php

-
rawMessage: 'Method Cose\Algorithm\Signature\ECDSA\ECSignature::fromAsn1() should return string but returns string|false.'
identifier: return.type
Expand Down Expand Up @@ -252,12 +258,6 @@ parameters:
count: 1
path: ../src/BigInteger.php

-
rawMessage: 'Parameter #1 $number of static method Brick\Math\BigInteger::fromBase() expects string, mixed given.'
identifier: argument.type
count: 1
path: ../src/BigInteger.php

-
rawMessage: 'Parameter #1 $string of function ltrim expects string, string|false given.'
identifier: argument.type
Expand Down Expand Up @@ -534,11 +534,6 @@ parameters:
count: 1
path: ../src/Key/RsaKey.php

-
rawMessage: 'Parameter #1 $number of static method Brick\Math\BigInteger::fromBase() expects string, mixed given.'
identifier: argument.type
count: 1
path: ../src/Key/RsaKey.php

-
rawMessage: Cannot cast mixed to int.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=8.1",
"ext-json": "*",
"ext-openssl": "*",
"brick/math": "^0.9|^0.10|^0.11|^0.12|^0.13|^0.14",
"brick/math": "^0.9|^0.10|^0.11|^0.12|^0.13|^0.14|^0.15|^0.16|^0.17",
"spomky-labs/pki-framework": "^1.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Cose\Algorithm;

use InvalidArgumentException;
use function array_key_exists;
use InvalidArgumentException;

final class Manager
{
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Cose\Algorithm;

use InvalidArgumentException;
use function array_key_exists;
use InvalidArgumentException;
use function sprintf;

final class ManagerFactory
Expand Down
5 changes: 2 additions & 3 deletions src/Algorithm/Signature/ECDSA/ECSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Cose\Algorithm\Signature\ECDSA;

use InvalidArgumentException;
use function bin2hex;
use function dechex;
use function hex2bin;
use function hexdec;
use InvalidArgumentException;
use function str_pad;
use const STR_PAD_LEFT;
use function strlen;
use function substr;
use const STR_PAD_LEFT;

/**
* @internal
Expand Down Expand Up @@ -67,7 +67,6 @@ public static function fromAsn1(string $signature, int $length): string
throw new InvalidArgumentException('Invalid data. Should start with a sequence.');
}

// @phpstan-ignore-next-line
if (self::readAsn1Content($message, $position, self::BYTE_SIZE) === self::ASN1_LENGTH_2BYTES) {
$position += self::BYTE_SIZE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/Signature/EdDSA/EdDSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Cose\Key\Key;
use Cose\Key\OkpKey;
use InvalidArgumentException;
use Throwable;
use function sodium_crypto_sign_detached;
use function sodium_crypto_sign_verify_detached;
use Throwable;

/**
* @see \Cose\Tests\Algorithm\Signature\EdDSA\EdDSATest
Expand Down
10 changes: 5 additions & 5 deletions src/Algorithm/Signature/RSA/PSSRSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

namespace Cose\Algorithm\Signature\RSA;

use function ceil;
use function chr;
use Cose\Algorithm\Signature\Signature;
use Cose\BigInteger;
use Cose\Hash;
use Cose\Key\Key;
use Cose\Key\RsaKey;
use InvalidArgumentException;
use RuntimeException;
use function ceil;
use function chr;
use function hash_equals;
use InvalidArgumentException;
use function ord;
use function pack;
use function random_bytes;
use RuntimeException;
use function str_pad;
use const STR_PAD_LEFT;
use function str_repeat;
use function strlen;
use const STR_PAD_LEFT;

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/Signature/RSA/RSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Cose\Key\Key;
use Cose\Key\RsaKey;
use InvalidArgumentException;
use Throwable;
use function openssl_sign;
use function openssl_verify;
use Throwable;

/**
* @see \Cose\Tests\Algorithm\Signature\RSA\RSATest
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithms.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Cose;

use InvalidArgumentException;
use function array_key_exists;
use InvalidArgumentException;
use const OPENSSL_ALGO_SHA1;
use const OPENSSL_ALGO_SHA256;
use const OPENSSL_ALGO_SHA384;
Expand Down
1 change: 1 addition & 0 deletions src/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private function __construct(
public static function createFromBinaryString(string $value): self
{
$res = unpack('H*', $value);
/** @var non-empty-string $data */
$data = current($res);

return new self(BrickBigInteger::fromBase($data, 16));
Expand Down
6 changes: 3 additions & 3 deletions src/Key/Ec2Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace Cose\Key;

use function array_key_exists;
use function in_array;
use InvalidArgumentException;
use function is_int;
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString;
use SpomkyLabs\Pki\ASN1\Type\Primitive\Integer;
use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier;
use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString;
use SpomkyLabs\Pki\ASN1\Type\Tagged\ExplicitlyTaggedType;
use function array_key_exists;
use function in_array;
use function is_int;
use function sprintf;
use function strlen;

Expand Down
2 changes: 1 addition & 1 deletion src/Key/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Cose\Key;

use InvalidArgumentException;
use function array_key_exists;
use InvalidArgumentException;
use function sprintf;

class Key
Expand Down
2 changes: 1 addition & 1 deletion src/Key/OkpKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Cose\Key;

use InvalidArgumentException;
use function array_key_exists;
use function in_array;
use InvalidArgumentException;

/**
* @final
Expand Down
5 changes: 3 additions & 2 deletions src/Key/RsaKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Cose\Key;

use function array_key_exists;
use Brick\Math\BigInteger;
use function in_array;
use InvalidArgumentException;
use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PublicKeyInfo;
use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSAPrivateKey;
use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSAPublicKey;
use function array_key_exists;
use function in_array;

/**
* @final
Expand Down Expand Up @@ -255,6 +255,7 @@ private function checkKeyIsPrivate(): void
private function binaryToBigInteger(string $data): string
{
$res = unpack('H*', $data);
/** @var non-empty-string $res */
$res = current($res);

return BigInteger::fromBase($res, 16)->toBase(10);
Expand Down
2 changes: 1 addition & 1 deletion tests/Algorithm/Mac/HS256Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Cose\Tests\Algorithm\Mac;

use function base64_decode;
use Cose\Algorithm\Mac\HS256;
use Cose\Key\OkpKey;
use Cose\Key\SymmetricKey;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use function base64_decode;

final class HS256Test extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Algorithm/Mac/HmacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cose\Tests\Algorithm\Mac;

use function base64_decode;
use Cose\Algorithm\Mac\Hmac;
use Cose\Algorithm\Mac\HS256;
use Cose\Algorithm\Mac\HS256Truncated64;
Expand All @@ -15,7 +16,6 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use function base64_decode;

final class HmacTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Signature/CoseSign1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Cose\Tests\Signature;

use function base64_decode;
use CBOR\Decoder;
use CBOR\OtherObject\OtherObjectManager;
use CBOR\StringStream;
use CBOR\Tag\TagManager;
use Cose\Signature\CoseSign1Tag;
use Cose\Signature\Signature1;
use function openssl_verify;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use function base64_decode;
use function openssl_verify;

final class CoseSign1Test extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Signature/ECSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Cose\Tests\Signature;

use InvalidArgumentException;
use function hex2bin;
use InvalidArgumentException;
use function mb_strlen;
use function mb_strpos;
use function mb_substr;
Expand Down
Loading