Skip to content

Commit

Permalink
Bug/types as string (#58)
Browse files Browse the repository at this point in the history
Key type can be of type string
  • Loading branch information
Spomky authored Jul 26, 2023
1 parent 00d4cef commit 269f22d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ parameters:
count: 1
path: src/BigInteger.php

-
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Key/Ec2Key.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 2
Expand Down Expand Up @@ -85,11 +80,6 @@ parameters:
count: 1
path: src/Key/Key.php

-
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Key/OkpKey.php

-
message: "#^Method Cose\\\\Key\\\\OkpKey\\:\\:curve\\(\\) should return int\\|string but returns mixed\\.$#"
count: 1
Expand All @@ -105,11 +95,6 @@ parameters:
count: 1
path: src/Key/OkpKey.php

-
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Key/RsaKey.php

-
message: "#^Method Cose\\\\Key\\\\RsaKey\\:\\:QInv\\(\\) should return string but returns mixed\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/Mac/Hmac.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract protected function getSignatureLength(): int;

private function checKey(Key $key): void
{
if ($key->type() !== Key::TYPE_OCT) {
if ($key->type() !== Key::TYPE_OCT && $key->type() !== Key::TYPE_NAME_OCT) {
throw new InvalidArgumentException('Invalid key. Must be of type symmetric');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Key/Ec2Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Ec2Key extends Key
public function __construct(array $data)
{
parent::__construct($data);
if (! isset($data[self::TYPE]) || (int) $data[self::TYPE] !== self::TYPE_EC2) {
if ($data[self::TYPE] !== self::TYPE_EC2 && $data[self::TYPE] !== self::TYPE_NAME_EC2) {
throw new InvalidArgumentException('Invalid EC2 key. The key type does not correspond to an EC2 key');
}
if (! isset($data[self::DATA_CURVE], $data[self::DATA_X], $data[self::DATA_Y])) {
Expand Down
8 changes: 8 additions & 0 deletions src/Key/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class Key

public const TYPE_OCT = 4;

public const TYPE_NAME_OKP = 'OKP';

public const TYPE_NAME_EC2 = 'EC';

public const TYPE_NAME_RSA = 'RSA';

public const TYPE_NAME_OCT = 'oct';

public const KID = 2;

public const ALG = 3;
Expand Down
2 changes: 1 addition & 1 deletion src/Key/OkpKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class OkpKey extends Key
public function __construct(array $data)
{
parent::__construct($data);
if (! isset($data[self::TYPE]) || (int) $data[self::TYPE] !== self::TYPE_OKP) {
if ($data[self::TYPE] !== self::TYPE_OKP && $data[self::TYPE] !== self::TYPE_NAME_OKP) {
throw new InvalidArgumentException('Invalid OKP key. The key type does not correspond to an OKP key');
}
if (! isset($data[self::DATA_CURVE], $data[self::DATA_X])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Key/RsaKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RsaKey extends Key
public function __construct(array $data)
{
parent::__construct($data);
if (! isset($data[self::TYPE]) || (int) $data[self::TYPE] !== self::TYPE_RSA) {
if ($data[self::TYPE] !== self::TYPE_RSA && $data[self::TYPE] !== self::TYPE_NAME_RSA) {
throw new InvalidArgumentException('Invalid RSA key. The key type does not correspond to a RSA key');
}
if (! isset($data[self::DATA_N], $data[self::DATA_E])) {
Expand Down

0 comments on commit 269f22d

Please sign in to comment.