diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 65f586e..04d82cc 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -2,9 +2,9 @@ name: PHP Unit Tests on: push: - branches: [ main, develop ] + branches: [ master ] pull_request: - branches: [ main, develop ] + branches: [ master ] jobs: test: @@ -12,7 +12,7 @@ jobs: strategy: matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] dependency-version: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php-versions }} - ${{ matrix.dependency-version }} @@ -50,12 +50,15 @@ jobs: run: vendor/bin/phpunit - name: Run PHPUnit with coverage + if: matrix.php-versions == '8.4' && matrix.dependency-version == 'prefer-stable' run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml - - name: Upload coverage to Coveralls + - name: Upload coverage to Codecov if: matrix.php-versions == '8.4' && matrix.dependency-version == 'prefer-stable' - uses: coverallsapp/github-action@v2 + uses: codecov/codecov-action@v3 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: build/logs/clover.xml - format: clover \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} + file: ./build/logs/clover.xml + flags: unittests + name: codecov-umbrella + fail_ci_if_error: false \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 74de807..7b015a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,9 @@ php: - 7.4 - 8.0 - 8.1 + - 8.2 + - 8.3 + - 8.4 cache: directories: diff --git a/README.md b/README.md index c80b965..d252675 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ PHPASN1 ======= -[![Build Status](https://secure.travis-ci.org/Adapik/PHPASN1.png?branch=master)](http://travis-ci.org/Adapik/PHPASN1) -[![PHP 7 ready](http://php7ready.timesplinter.ch/Adapik/PHPASN1/badge.svg)](https://travis-ci.org/Adapik/PHPASN1) -[![Coverage Status](https://coveralls.io/repos/Adapik/PHPASN1/badge.svg?branch=master&service=github)](https://coveralls.io/github/Adapik/PHPASN1?branch=master) +![build status](https://github.com/github/docs/actions/workflows/tests.yml/badge.svg) +[![codecov](https://codecov.io/github/adapik/phpasn1/graph/badge.svg?token=KCBH7EV2J0)](https://codecov.io/github/adapik/phpasn1) [![Latest Stable Version](https://poser.pugx.org/Adapik/phpasn1/v/stable.png)](https://packagist.org/packages/Adapik/phpasn1) [![Total Downloads](https://poser.pugx.org/Adapik/phpasn1/downloads.png)](https://packagist.org/packages/Adapik/phpasn1) -[![Latest Unstable Version](https://poser.pugx.org/Adapik/phpasn1/v/unstable.png)](https://packagist.org/packages/Adapik/phpasn1) [![License](https://poser.pugx.org/Adapik/phpasn1/license.png)](https://packagist.org/packages/Adapik/phpasn1) A PHP Framework that allows you to encode and decode arbitrary [ASN.1][3] structures diff --git a/composer.json b/composer.json index 2c77c7e..4d213ae 100644 --- a/composer.json +++ b/composer.json @@ -25,12 +25,11 @@ "keywords": [ "x690", "x.690", "x.509", "x509", "asn1", "asn.1", "ber", "der", "binary", "encoding", "decoding" ], "require": { - "php": ">=7.2", + "php": ">=7.4", "ext-gmp": "*" }, "require-dev": { - "phpunit/phpunit": "^8.0", - "php-coveralls/php-coveralls": "^2.4" + "phpunit/phpunit": "^9.0" }, "suggest": { "php-curl": "For loading OID information from the web if they have not bee defined statically" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c30a483..b33165d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,13 @@ - - - - - tests - - - - - - src - - + + + + src + + + + + tests + + diff --git a/src/ASN1/AbstractTime.php b/src/ASN1/AbstractTime.php index 8638f8e..2432ee1 100644 --- a/src/ASN1/AbstractTime.php +++ b/src/ASN1/AbstractTime.php @@ -64,5 +64,5 @@ protected static function extractTimeZoneData(&$binaryData, &$offsetIndex, DateT return $dateTime; } - abstract public static function createFormDateTime(\DateTimeInterface $dateTime = null, array $options = []); + abstract public static function createFormDateTime(?\DateTimeInterface $dateTime = null, array $options = []); } diff --git a/src/ASN1/ElementBuilder.php b/src/ASN1/ElementBuilder.php index 5b9e914..552b1c3 100644 --- a/src/ASN1/ElementBuilder.php +++ b/src/ASN1/ElementBuilder.php @@ -180,7 +180,7 @@ protected static function createIdentifier($tagClass, $isConstructed, $tagNumber public static function createContentLength($content, $lengthForm) { - $length = strlen($content); + $length = strlen((string) $content); if ($lengthForm === ContentLength::INDEFINITE_FORM) { $lengthOctets = chr(128); } else { diff --git a/src/ASN1/Universal/GeneralizedTime.php b/src/ASN1/Universal/GeneralizedTime.php index 39e1365..f004ea3 100644 --- a/src/ASN1/Universal/GeneralizedTime.php +++ b/src/ASN1/Universal/GeneralizedTime.php @@ -152,7 +152,7 @@ public static function encodeValue(string $dateTime) return $dateTime; } - public static function createFormDateTime(\DateTimeInterface $dateTime = null, array $options = []) + public static function createFormDateTime(?\DateTimeInterface $dateTime = null, array $options = []) { $dateTime = $dateTime ?? new DateTime('now', new DateTimeZone('UTC')); diff --git a/src/ASN1/Universal/UTCTime.php b/src/ASN1/Universal/UTCTime.php index f9102d9..0701637 100644 --- a/src/ASN1/Universal/UTCTime.php +++ b/src/ASN1/Universal/UTCTime.php @@ -86,11 +86,10 @@ public function setValue(Content $content) $this->value = $dateTime; } - public static function createFormDateTime(\DateTimeInterface $dateTime = null, array $options = []) + public static function createFormDateTime(?\DateTimeInterface $dateTime = null, array $options = []) { $dateTime = $dateTime ?? new DateTime('now', new DateTimeZone('UTC')); - $isConstructed = false; $lengthForm = $options['lengthForm'] ?? ContentLength::SHORT_FORM; $string = $dateTime->format('ymdHis') . 'Z'; @@ -99,7 +98,7 @@ public static function createFormDateTime(\DateTimeInterface $dateTime = null, a ElementBuilder::createObject( Identifier::CLASS_UNIVERSAL, static::getType(), - $isConstructed, + false, $string, $lengthForm ); diff --git a/tests/ASN1/ASN1ObjectTest.php b/tests/ASN1/ASN1ObjectTest.php index b37a81c..fe807a3 100644 --- a/tests/ASN1/ASN1ObjectTest.php +++ b/tests/ASN1/ASN1ObjectTest.php @@ -201,79 +201,86 @@ public function testFromBinary() } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 10: Can not parse binary from data: Offset index larger than input size * @depends testFromBinary */ public function testFromBinaryThrowsException() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 10: Can not parse binary from data: Offset index larger than input size'); + $binaryData = 0x0; $offset = 10; ASN1Object::fromBinary($binaryData, $offset); } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 0: Can not parse binary from data: Offset index larger than input size * @depends testFromBinary */ public function testFromBinaryWithEmptyStringThrowsException() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 0: Can not parse binary from data: Offset index larger than input size'); + $data = ''; ASN1Object::fromBinary($data); } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 2: Can not parse binary from data: Offset index larger than input size * @depends testFromBinary */ public function testFromBinaryWithSpacyStringThrowsException() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 2: Can not parse binary from data: Offset index larger than input size'); + $data = ' '; ASN1Object::fromBinary($data); } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 1: Can not parse content length from data: Offset index larger than input size * @depends testFromBinary */ public function testFromBinaryWithNumberStringThrowsException() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 1: Can not parse content length from data: Offset index larger than input size'); + $data = '1'; ASN1Object::fromBinary($data); } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 25: Can not parse content length from data: Offset index larger than input size * @depends testFromBinary */ public function testFromBinaryWithGarbageStringThrowsException() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 25: Can not parse content length from data: Offset index larger than input size'); + $data = 'certainly no asn.1 object'; ASN1Object::fromBinary($data); } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 1: Can not parse identifier (long form) from data: Offset index larger than input size * @depends testFromBinary */ public function testFromBinaryUnknownObjectMissingLength() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 1: Can not parse identifier (long form) from data: Offset index larger than input size'); + $data = hex2bin('1f'); ASN1Object::fromBinary($data); } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 4: Can not parse content length (long form) from data: Offset index larger than input size * @depends testFromBinary */ public function testFromBinaryInalidLongFormContentLength() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 4: Can not parse content length (long form) from data: Offset index larger than input size'); + $binaryData = chr(Identifier::INTEGER); $binaryData .= chr(0x8f); //denotes a long-form content length with 15 length-octets $binaryData .= chr(0x1); //only give one content-length-octet diff --git a/tests/ASN1/Base128Test.php b/tests/ASN1/Base128Test.php index e4def35..5884050 100644 --- a/tests/ASN1/Base128Test.php +++ b/tests/ASN1/Base128Test.php @@ -79,12 +79,11 @@ public function getDataToDecode() ]; } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Malformed base-128 encoded value (0xFFFF). - */ public function testDecodeFailsIfLastOctetSignificantBitSet() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Malformed base-128 encoded value (0xFFFF).'); + Base128::decode("\xFF\xFF"); } } diff --git a/tests/ASN1/Universal/BitStringTest.php b/tests/ASN1/Universal/BitStringTest.php index 39394e2..7adce5c 100644 --- a/tests/ASN1/Universal/BitStringTest.php +++ b/tests/ASN1/Universal/BitStringTest.php @@ -138,12 +138,13 @@ public function testFromBinaryWithOffset() } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 3: Malformed bit string - * @depends testFromBinary + * @depends testFromBinary */ public function testFromBinaryWithInvalidLength01() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 3: Malformed bit string'); + $binaryData = chr(Identifier::BITSTRING); $binaryData .= chr(0x01); $binaryData .= chr(0x00); diff --git a/tests/ASN1/Universal/BooleanTest.php b/tests/ASN1/Universal/BooleanTest.php index eef1695..a228494 100644 --- a/tests/ASN1/Universal/BooleanTest.php +++ b/tests/ASN1/Universal/BooleanTest.php @@ -97,12 +97,13 @@ public function testFromBinaryWithOffset() } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 4: An ASN.1 Boolean should not have a length other than one. Extracted length was 2 * @depends testFromBinary */ public function testFromBinaryWithInvalidLength01() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 4: An ASN.1 Boolean should not have a length other than one. Extracted length was 2'); + $binaryData = chr(Identifier::BOOLEAN); $binaryData .= chr(0x02); $binaryData .= chr(0xFF); @@ -110,12 +111,13 @@ public function testFromBinaryWithInvalidLength01() } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 2: An ASN.1 Boolean should not have a length other than one. Extracted length was 0 * @depends testFromBinary */ public function testFromBinaryWithInvalidLength02() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 2: An ASN.1 Boolean should not have a length other than one. Extracted length was 0'); + $binaryData = chr(Identifier::BOOLEAN); $binaryData .= chr(0x00); $binaryData .= chr(0xFF); diff --git a/tests/ASN1/Universal/IntegerTest.php b/tests/ASN1/Universal/IntegerTest.php index b8c3be0..b23a668 100644 --- a/tests/ASN1/Universal/IntegerTest.php +++ b/tests/ASN1/Universal/IntegerTest.php @@ -29,11 +29,10 @@ public function testGetIdentifierCode() $this->assertEquals('Integer', $object->getIdentifier()->getCode()); } - /** - * @expectedException \Exception - */ public function testCreateInstanceCanFail() { + $this->expectException(\Exception::class); + Integer::create('a'); } diff --git a/tests/ASN1/Universal/NullObjectTest.php b/tests/ASN1/Universal/NullObjectTest.php index 9252d62..69cf6fa 100644 --- a/tests/ASN1/Universal/NullObjectTest.php +++ b/tests/ASN1/Universal/NullObjectTest.php @@ -74,12 +74,13 @@ public function testFromBinaryWithOffset() } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 3: An ASN.1 Null should not have a length other than zero. Extracted length was 1 * @depends testFromBinary */ public function testFromBinaryWithInvalidLength01() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 3: An ASN.1 Null should not have a length other than zero. Extracted length was 1'); + $binaryData = chr(Identifier::NULL); $binaryData .= chr(0x01); NullObject::fromBinary($binaryData); diff --git a/tests/ASN1/Universal/ObjectIdentifierTest.php b/tests/ASN1/Universal/ObjectIdentifierTest.php index 24388b3..5b43520 100644 --- a/tests/ASN1/Universal/ObjectIdentifierTest.php +++ b/tests/ASN1/Universal/ObjectIdentifierTest.php @@ -89,12 +89,13 @@ public function testFromBinaryWithOffset() } /** - * @expectedException \FG\ASN1\Exception\ParserException - * @expectedExceptionMessage ASN.1 Parser Exception at offset 2: Malformed ASN.1 Object Identifier - * @depends testFromBinary + * @depends testFromBinary */ public function testFromBinaryWithMalformedOID() { + $this->expectException(\FG\ASN1\Exception\ParserException::class); + $this->expectExceptionMessage('ASN.1 Parser Exception at offset 2: Malformed ASN.1 Object Identifier'); + $binaryData = chr(Identifier::OBJECT_IDENTIFIER); $binaryData .= chr(0x03); $binaryData .= chr(42); @@ -103,12 +104,11 @@ public function testFromBinaryWithMalformedOID() ObjectIdentifier::fromBinary($binaryData); } - /** - * @expectedException \Exception - * @expectedExceptionMessage [1.Foo.3] is no valid object identifier (sub identifier 2 is not numeric)! - */ public function testCreateWithInvalidObjectIdentifier() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('[1.Foo.3] is no valid object identifier (sub identifier 2 is not numeric)!'); + ObjectIdentifier::create('1.Foo.3'); } }