Skip to content

Commit

Permalink
Rector fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Dec 14, 2022
1 parent c6a6535 commit 973111b
Show file tree
Hide file tree
Showing 337 changed files with 4,608 additions and 9,801 deletions.
422 changes: 213 additions & 209 deletions .github/workflows/integrate.yml

Large diffs are not rendered by default.

65 changes: 17 additions & 48 deletions tests/ASN1/Component/IdentifierDecodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Brick\Math\BigInteger;
use Brick\Math\Exception\IntegerOverflowException;
use function chr;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use SpomkyLabs\Pki\ASN1\Component\Identifier;
use SpomkyLabs\Pki\ASN1\Exception\DecodeException;
Expand All @@ -16,117 +17,91 @@
*/
final class IdentifierDecodeTest extends TestCase
{
/**
* @test
*/
#[Test]
public function type()
{
$identifier = Identifier::fromDER("\x0");
static::assertInstanceOf(Identifier::class, $identifier);
}

/**
* @test
*/
#[Test]
public function universal()
{
$identifier = Identifier::fromDER(chr(0b00000000));
static::assertTrue($identifier->isUniversal());
}

/**
* @test
*/
#[Test]
public function application()
{
$identifier = Identifier::fromDER(chr(0b01000000));
static::assertTrue($identifier->isApplication());
}

/**
* @test
*/
#[Test]
public function contextSpecific()
{
$identifier = Identifier::fromDER(chr(0b10000000));
static::assertTrue($identifier->isContextSpecific());
}

/**
* @test
*/
#[Test]
public function private()
{
$identifier = Identifier::fromDER(chr(0b11000000));
static::assertTrue($identifier->isPrivate());
}

/**
* @test
*/
#[Test]
public function pC()
{
$identifier = Identifier::fromDER(chr(0b00000000));
static::assertEquals(Identifier::PRIMITIVE, $identifier->pc());
}

/**
* @test
*/
#[Test]
public function primitive()
{
$identifier = Identifier::fromDER(chr(0b00000000));
static::assertTrue($identifier->isPrimitive());
}

/**
* @test
*/
#[Test]
public function constructed()
{
$identifier = Identifier::fromDER(chr(0b00100000));
static::assertTrue($identifier->isConstructed());
}

/**
* @test
*/
#[Test]
public function tag()
{
$identifier = Identifier::fromDER(chr(0b00001111));
static::assertEquals(0b1111, $identifier->tag());
}

/**
* @test
*/
#[Test]
public function intTag()
{
$identifier = Identifier::fromDER(chr(0b00001111));
static::assertEquals(0b1111, $identifier->intTag());
}

/**
* @test
*/
#[Test]
public function longTag()
{
$identifier = Identifier::fromDER(chr(0b00011111) . "\x7f");
static::assertEquals(0x7f, $identifier->tag());
}

/**
* @test
*/
#[Test]
public function longTag2()
{
$identifier = Identifier::fromDER(chr(0b00011111) . "\xff\x7f");
static::assertEquals((0x7f << 7) + 0x7f, $identifier->tag());
}

/**
* @test
*/
#[Test]
public function hugeTag()
{
$der = "\x1f" . str_repeat("\xff", 100) . "\x7f";
Expand All @@ -135,19 +110,15 @@ public function hugeTag()
static::assertEquals($num->toBase(10), $identifier->tag());
}

/**
* @test
*/
#[Test]
public function hugeIntTagOverflow()
{
$der = "\x1f" . str_repeat("\xff", 100) . "\x7f";
$this->expectException(IntegerOverflowException::class);
Identifier::fromDER($der)->intTag();
}

/**
* @test
*/
#[Test]
public function invalidOffset()
{
$offset = 1;
Expand All @@ -156,9 +127,7 @@ public function invalidOffset()
Identifier::fromDER("\x0", $offset);
}

/**
* @test
*/
#[Test]
public function unexpectedTagEnd()
{
$this->expectException(DecodeException::class);
Expand Down
29 changes: 8 additions & 21 deletions tests/ASN1/Component/IdentifierEncodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Brick\Math\BigInteger;
use function chr;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use SpomkyLabs\Pki\ASN1\Component\Identifier;
use SpomkyLabs\Pki\ASN1\Element;
Expand All @@ -15,27 +16,21 @@
*/
final class IdentifierEncodeTest extends TestCase
{
/**
* @test
*/
#[Test]
public function universal()
{
$identifier = Identifier::create(Identifier::CLASS_UNIVERSAL, Identifier::PRIMITIVE, Element::TYPE_BOOLEAN);
static::assertEquals(chr(0b00000001), $identifier->toDER());
}

/**
* @test
*/
#[Test]
public function application()
{
$identifier = Identifier::create(Identifier::CLASS_APPLICATION, Identifier::PRIMITIVE, Element::TYPE_BOOLEAN);
static::assertEquals(chr(0b01000001), $identifier->toDER());
}

/**
* @test
*/
#[Test]
public function contextSpecific()
{
$identifier = Identifier::create(
Expand All @@ -46,36 +41,28 @@ public function contextSpecific()
static::assertEquals(chr(0b10000001), $identifier->toDER());
}

/**
* @test
*/
#[Test]
public function private()
{
$identifier = Identifier::create(Identifier::CLASS_PRIVATE, Identifier::PRIMITIVE, Element::TYPE_BOOLEAN);
static::assertEquals(chr(0b11000001), $identifier->toDER());
}

/**
* @test
*/
#[Test]
public function constructed()
{
$identifier = Identifier::create(Identifier::CLASS_UNIVERSAL, Identifier::CONSTRUCTED, Element::TYPE_SEQUENCE);
static::assertEquals(chr(0b00110000), $identifier->toDER());
}

/**
* @test
*/
#[Test]
public function longTag()
{
$identifier = Identifier::create(Identifier::CLASS_APPLICATION, Identifier::CONSTRUCTED, (0x7f << 7) + 0x7f);
static::assertEquals(chr(0b01111111) . "\xff\x7f", $identifier->toDER());
}

/**
* @test
*/
#[Test]
public function hugeTag()
{
$num = BigInteger::fromBase(str_repeat('1111111', 100) . '1111111', 2);
Expand Down
9 changes: 3 additions & 6 deletions tests/ASN1/Component/IdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SpomkyLabs\Pki\Test\ASN1\Component;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use SpomkyLabs\Pki\ASN1\Component\Identifier;

Expand All @@ -12,18 +13,14 @@
*/
final class IdentifierTest extends TestCase
{
/**
* @test
*/
#[Test]
public function classToName()
{
$name = Identifier::classToName(Identifier::CLASS_UNIVERSAL);
static::assertEquals('UNIVERSAL', $name);
}

/**
* @test
*/
#[Test]
public function unknownClassToName()
{
$name = Identifier::classToName(0xff);
Expand Down
Loading

0 comments on commit 973111b

Please sign in to comment.