Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Tidy up registration class (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed committed Oct 25, 2021
1 parent 82529e2 commit 5c3ad2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Registration implements RegistrationInterface
private $counter = -1;

/** @var PublicKeyInterface */
private $pubKey;
private $publicKey;

public function getAttestationCertificate(): AttestationCertificateInterface
{
Expand Down Expand Up @@ -45,12 +45,34 @@ public function setCounter(int $counter): self

public function getPublicKey(): PublicKeyInterface
{
return $this->pubKey;
return $this->publicKey;
}

public function setPublicKey(PublicKeyInterface $pubKey): self
public function setPublicKey(PublicKeyInterface $publicKey): self
{
$this->pubKey = $pubKey;
$this->publicKey = $publicKey;
return $this;
}

/**
* @return array{
* cert: AttestationCertificateInterface,
* counter: int,
* publicKey: PublicKeyInterface,
* keyHandle: string,
* }
*/
public function __debugInfo(): array
{
$hex = function (string $binary): string {
return '0x' . bin2hex($binary);
};

return [
'cert' => $this->cert,
'counter' => $this->counter,
'publicKey' => $this->publicKey,
'keyHandle' => $hex($this->keyHandle),
];
}
}
17 changes: 17 additions & 0 deletions tests/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,21 @@ public function testAttestationCertificate(): void
$reg->setAttestationCertificate($pk);
$this->assertSame($pk, $reg->getAttestationCertificate());
}

/**
* @covers ::__debugInfo
*/
public function testDebugInfoEncodesBinary(): void
{
$reg = new Registration();
$reg->setAttestationCertificate($this->createMock(AttestationCertificateInterface::class));
$reg->setPublicKey($this->createMock(PublicKeyInterface::class));
$kh = random_bytes(20);
$reg->setKeyHandle($kh);
$reg->setCounter(50);

$debugInfo = $reg->__debugInfo();
$this->assertNotSame($kh, $debugInfo['keyHandle']);
$this->assertRegExp('/^0x[0-9a-f]{40}$/', $debugInfo['keyHandle']);
}
}

0 comments on commit 5c3ad2a

Please sign in to comment.