Skip to content

Commit

Permalink
Version credentials (#54)
Browse files Browse the repository at this point in the history
Renames `Credential` to `CredentialV1`, for the upcoming addition of
`CredentialV2` which tracks additional data.

Extracted from #53.
  • Loading branch information
Firehed authored Nov 19, 2023
1 parent 8e7f191 commit 66d9dfc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Codecs/Credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Firehed\WebAuthn\BinaryString;
use Firehed\WebAuthn\COSEKey;
use Firehed\WebAuthn\CredentialInterface;
use Firehed\WebAuthn\Credential as CredentialObj;
use Firehed\WebAuthn\CredentialV1;

/**
* This codec is responsible for serializing a CredentialInterface object to
Expand Down Expand Up @@ -113,7 +113,7 @@ public function decode(string $encoded): CredentialInterface

$signCount = $bytes->readUint32();

return new CredentialObj(
return new CredentialV1(
new BinaryString($id),
new COSEKey(new BinaryString($cbor)),
$signCount,
Expand Down
2 changes: 1 addition & 1 deletion src/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function verify(
// associate credential with new user
// done in client code
$data = $authData->getAttestedCredentialData();
$credential = new Credential(
$credential = new CredentialV1(
id: $this->id,
signCount: $authData->getSignCount(),
coseKey: $data->coseKey,
Expand Down
13 changes: 8 additions & 5 deletions src/Credential.php → src/CredentialV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Firehed\WebAuthn;

/**
* Data format for WebAuthn Level 2 formats which lacked data for backup
* eligibility and did not track transports.
*
* @internal
*/
class Credential implements CredentialInterface
class CredentialV1 implements CredentialInterface
{
// Risk factors:
// Create:
Expand Down Expand Up @@ -49,10 +52,10 @@ public function getPublicKey(): PublicKey\PublicKeyInterface

public function withUpdatedSignCount(int $newSignCount): CredentialInterface
{
return new Credential(
$this->id,
$this->coseKey,
$newSignCount,
return new CredentialV1(
id: $this->id,
coseKey: $this->coseKey,
signCount: $newSignCount,
);
}
}
4 changes: 2 additions & 2 deletions tests/Codecs/CredentialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
BinaryString,
COSEKey,
CredentialInterface,
Credential as CredentialObj,
CredentialV1,
};

/**
Expand All @@ -24,7 +24,7 @@ public function testRoundtrip(): void
$cbor = hex2bin($cborHex);
assert($cbor !== false);
$coseKey = new COSEKey(new BinaryString($cbor));
$credential = new CredentialObj(
$credential = new CredentialV1(
new BinaryString(random_bytes(10)),
$coseKey,
15,
Expand Down
8 changes: 4 additions & 4 deletions tests/CredentialTest.php → tests/CredentialV1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
namespace Firehed\WebAuthn;

/**
* @covers Firehed\WebAuthn\Credential
* @covers Firehed\WebAuthn\CredentialV1
*/
class CredentialTest extends \PHPUnit\Framework\TestCase
class CredentialV1Test extends \PHPUnit\Framework\TestCase
{
public function testAccessors(): void
{
$pk = self::createMock(PublicKey\PublicKeyInterface::class);
$coseKey = self::createMock(COSEKey::class);
$coseKey->method('getPublicKey')
->willReturn($pk);
$credential = new Credential(
$credential = new CredentialV1(
id: BinaryString::fromHex('FFFF'),
coseKey: $coseKey,
signCount: 10,
Expand All @@ -36,7 +36,7 @@ public function testUpdatingSignCount(): void
$coseKey = self::createMock(COSEKey::class);
$coseKey->method('getPublicKey')
->willReturn($pk);
$credential = new Credential(
$credential = new CredentialV1(
id: BinaryString::fromHex('0000'),
coseKey: $coseKey,
signCount: 20,
Expand Down

0 comments on commit 66d9dfc

Please sign in to comment.