diff --git a/classes/chillerlan-OAuth-Core-PKCETrait.html b/classes/chillerlan-OAuth-Core-PKCETrait.html index dbf973d..75c5bb1 100644 --- a/classes/chillerlan-OAuth-Core-PKCETrait.html +++ b/classes/chillerlan-OAuth-Core-PKCETrait.html @@ -131,7 +131,7 @@

@@ -238,7 +238,7 @@

@@ -317,7 +317,7 @@

@@ -364,24 +364,6 @@

OAuth2Provider::setCodeChallenge() - -
- noinspection -
-
- -

PhpFullyQualifiedNameUsageInspection

-
- -
-
- SuppressWarnings -
-
- -

(PHPMD.MissingImport)

-
-
@@ -407,7 +389,7 @@

@@ -486,7 +468,7 @@

diff --git a/classes/chillerlan-OAuth-Core-Utilities.html b/classes/chillerlan-OAuth-Core-Utilities.html index b9a90d6..b7db6c9 100644 --- a/classes/chillerlan-OAuth-Core-Utilities.html +++ b/classes/chillerlan-OAuth-Core-Utilities.html @@ -146,9 +146,9 @@

Common utilities for use with the OAuth providers

@@ -173,31 +173,6 @@

-

- Constants - - -

-
-
- ENCRYPT_FORMAT_BASE64 - -  = 0b1 -
- -
- ENCRYPT_FORMAT_BINARY - -  = 0b0 -
- -
- ENCRYPT_FORMAT_HEX - -  = 0b10 -
- -
@@ -207,27 +182,6 @@

-
- createEncryptionKey() - -  : string -
-
Creates a new cryptographically secure random encryption key (in hexadecimal format)
- -
- decrypt() - -  : string -
-
decrypts the given $encrypted data with $key from $format input [binary, base64, hex]
- -
- encrypt() - -  : string -
-
encrypts the given $data with $key, $format output [binary, base64, hex]
-
getProviders() @@ -240,109 +194,6 @@

-
-

- Constants - - -

-
-

- ENCRYPT_FORMAT_BASE64 - - -

- - - - - - - public - final mixed - ENCRYPT_FORMAT_BASE64 - = 0b1 - - - - - - - - - -
-
-

- ENCRYPT_FORMAT_BINARY - - -

- - - - - - - public - final mixed - ENCRYPT_FORMAT_BINARY - = 0b0 - - - - - - - - - -
-
-

- ENCRYPT_FORMAT_HEX - - -

- - - - - - - public - final mixed - ENCRYPT_FORMAT_HEX - = 0b10 - - - - - - - - - -
-
@@ -357,236 +208,6 @@

-method -public -static " -> -

- createEncryptionKey() - - -

- - -

Creates a new cryptographically secure random encryption key (in hexadecimal format)

- - - public - static createEncryptionKey() : string - -
-
- - - - - - - -
-
Return values
- string -
- - -
-

- decrypt() - - -

- - -

decrypts the given $encrypted data with $key from $format input [binary, base64, hex]

- - - public - static decrypt(string $encrypted, string $keyHex[, int $format = self::ENCRYPT_FORMAT_HEX ]) : string - -
-
- - -
Parameters
-
-
- $encrypted - : string -
-
- -
-
- $keyHex - : string -
-
- -
-
- $format - : int - = self::ENCRYPT_FORMAT_HEX
-
- -
-
- - -
- Tags - - -
-
-
- see -
-
- sodium_crypto_secretbox_open() - - -
-
- see -
-
- sodium_base642bin() - - -
-
- see -
-
- sodium_hex2bin() - - -
-
- - - -
-
Return values
- string -
- -
-
-

- encrypt() - - -

- - -

encrypts the given $data with $key, $format output [binary, base64, hex]

- - - public - static encrypt(string $data, string $keyHex[, int $format = self::ENCRYPT_FORMAT_HEX ]) : string - -
-
- - -
Parameters
-
-
- $data - : string -
-
- -
-
- $keyHex - : string -
-
- -
-
- $format - : int - = self::ENCRYPT_FORMAT_HEX
-
- -
-
- - -
- Tags - - -
-
-
- see -
-
- sodium_crypto_secretbox() - - -
-
- see -
-
- sodium_bin2base64() - - -
-
- see -
-
- sodium_bin2hex() - - -
-
- - - -
-
Return values
- string -
- -
-

getProviders() @@ -596,9 +217,9 @@

Fetches a list of provider classes in the given directory

@@ -744,26 +365,14 @@

Return values
  • Table Of Contents
  • -
  • Constants
  • -
  • - -
  • Methods
  • diff --git a/classes/chillerlan-OAuth-OAuthOptions.html b/classes/chillerlan-OAuth-OAuthOptions.html index 37be437..bdd2511 100644 --- a/classes/chillerlan-OAuth-OAuthOptions.html +++ b/classes/chillerlan-OAuth-OAuthOptions.html @@ -321,7 +321,7 @@

    @@ -358,7 +358,7 @@

    @@ -418,7 +418,7 @@

    @@ -455,7 +455,7 @@

    @@ -506,7 +506,7 @@

    @@ -543,7 +543,7 @@

    @@ -605,7 +605,7 @@

    @@ -667,7 +667,7 @@

    @@ -719,7 +719,7 @@

    @@ -779,7 +779,7 @@

    @@ -831,7 +831,7 @@

    @@ -888,7 +888,7 @@

    @@ -933,7 +933,7 @@

    @@ -978,7 +978,7 @@

    diff --git a/classes/chillerlan-OAuth-OAuthOptionsTrait.html b/classes/chillerlan-OAuth-OAuthOptionsTrait.html index 823baf6..64f2dab 100644 --- a/classes/chillerlan-OAuth-OAuthOptionsTrait.html +++ b/classes/chillerlan-OAuth-OAuthOptionsTrait.html @@ -130,7 +130,7 @@

    @@ -763,7 +763,7 @@

    @@ -800,7 +800,7 @@

    @@ -860,7 +860,7 @@

    @@ -897,7 +897,7 @@

    @@ -948,7 +948,7 @@

    @@ -985,7 +985,7 @@

    @@ -1047,7 +1047,7 @@

    @@ -1109,7 +1109,7 @@

    @@ -1161,7 +1161,7 @@

    @@ -1221,7 +1221,7 @@

    @@ -1273,7 +1273,7 @@

    @@ -1330,7 +1330,7 @@

    @@ -1375,7 +1375,7 @@

    @@ -1420,7 +1420,7 @@

    diff --git a/classes/chillerlan-OAuth-Providers-Codeberg.html b/classes/chillerlan-OAuth-Providers-Codeberg.html index 62cbcf9..ab8f144 100644 --- a/classes/chillerlan-OAuth-Providers-Codeberg.html +++ b/classes/chillerlan-OAuth-Providers-Codeberg.html @@ -2719,7 +2719,7 @@

    @@ -2798,7 +2798,7 @@

    @@ -2845,24 +2845,6 @@

    OAuth2Provider::setCodeChallenge() - -
    - noinspection -
    -
    - -

    PhpFullyQualifiedNameUsageInspection

    -
    - -
    -
    - SuppressWarnings -
    -
    - -

    (PHPMD.MissingImport)

    -
    -
    @@ -3757,7 +3739,7 @@

    @@ -3836,7 +3818,7 @@

    diff --git a/classes/chillerlan-OAuth-Providers-Gitea.html b/classes/chillerlan-OAuth-Providers-Gitea.html index e9157dc..9934015 100644 --- a/classes/chillerlan-OAuth-Providers-Gitea.html +++ b/classes/chillerlan-OAuth-Providers-Gitea.html @@ -2594,7 +2594,7 @@

    @@ -2673,7 +2673,7 @@

    @@ -2720,24 +2720,6 @@

    OAuth2Provider::setCodeChallenge() - -
    - noinspection -
    -
    - -

    PhpFullyQualifiedNameUsageInspection

    -
    - -
    -
    - SuppressWarnings -
    -
    - -

    (PHPMD.MissingImport)

    -
    -
    @@ -3632,7 +3614,7 @@

    @@ -3711,7 +3693,7 @@

    diff --git a/classes/chillerlan-OAuth-Providers-Google.html b/classes/chillerlan-OAuth-Providers-Google.html index ddeecf5..3e02b7e 100644 --- a/classes/chillerlan-OAuth-Providers-Google.html +++ b/classes/chillerlan-OAuth-Providers-Google.html @@ -1863,7 +1863,7 @@

    @@ -1942,7 +1942,7 @@

    @@ -1989,24 +1989,6 @@

    OAuth2Provider::setCodeChallenge() - -
    - noinspection -
    -
    - -

    PhpFullyQualifiedNameUsageInspection

    -
    - -
    -
    - SuppressWarnings -
    -
    - -

    (PHPMD.MissingImport)

    -
    -
    @@ -2980,7 +2962,7 @@

    @@ -3059,7 +3041,7 @@

    diff --git a/classes/chillerlan-OAuth-Providers-Spotify.html b/classes/chillerlan-OAuth-Providers-Spotify.html index 15bd47f..62df1bf 100644 --- a/classes/chillerlan-OAuth-Providers-Spotify.html +++ b/classes/chillerlan-OAuth-Providers-Spotify.html @@ -2613,7 +2613,7 @@

    @@ -2692,7 +2692,7 @@

    @@ -2739,24 +2739,6 @@

    OAuth2Provider::setCodeChallenge() - -
    - noinspection -
    -
    - -

    PhpFullyQualifiedNameUsageInspection

    -
    - -
    -
    - SuppressWarnings -
    -
    - -

    (PHPMD.MissingImport)

    -
    -
    @@ -3723,7 +3705,7 @@

    @@ -3802,7 +3784,7 @@

    diff --git a/classes/chillerlan-OAuth-Providers-YouTube.html b/classes/chillerlan-OAuth-Providers-YouTube.html index 39948c8..57be0eb 100644 --- a/classes/chillerlan-OAuth-Providers-YouTube.html +++ b/classes/chillerlan-OAuth-Providers-YouTube.html @@ -1909,7 +1909,7 @@

    @@ -1988,7 +1988,7 @@

    @@ -2035,24 +2035,6 @@

    OAuth2Provider::setCodeChallenge() - -
    - noinspection -
    -
    - -

    PhpFullyQualifiedNameUsageInspection

    -
    - -
    -
    - SuppressWarnings -
    -
    - -

    (PHPMD.MissingImport)

    -
    -
    @@ -3026,7 +3008,7 @@

    @@ -3105,7 +3087,7 @@

    diff --git a/classes/chillerlan-OAuth-Storage-FileStorage.html b/classes/chillerlan-OAuth-Storage-FileStorage.html index 018465e..7ad8b79 100644 --- a/classes/chillerlan-OAuth-Storage-FileStorage.html +++ b/classes/chillerlan-OAuth-Storage-FileStorage.html @@ -149,7 +149,7 @@

    @@ -210,7 +210,7 @@

    ENCRYPT_FORMAT -  = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_BINARY +  = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_BINARY
    Output format for encrypted data
    @@ -449,7 +449,7 @@

    loadFile() -  : string|null +  : string
    fetched the content from a file
    @@ -481,7 +481,7 @@

    @@ -492,7 +492,7 @@

    protected final int ENCRYPT_FORMAT - = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_BINARY + = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_BINARY @@ -513,7 +513,7 @@

    @@ -544,7 +544,7 @@

    @@ -575,7 +575,7 @@

    @@ -622,7 +622,7 @@

    @@ -659,7 +659,7 @@

    @@ -696,7 +696,7 @@

    @@ -738,7 +738,7 @@

    @@ -797,7 +797,7 @@

    @@ -846,7 +846,7 @@

    @@ -885,7 +885,7 @@

    @@ -924,7 +924,7 @@

    @@ -963,7 +963,7 @@

    @@ -1012,7 +1012,7 @@

    @@ -1061,7 +1061,7 @@

    @@ -1110,7 +1110,7 @@

    @@ -1161,7 +1161,7 @@

    @@ -1212,7 +1212,7 @@

    @@ -1263,7 +1263,7 @@

    @@ -1312,7 +1312,7 @@

    @@ -1361,7 +1361,7 @@

    @@ -1410,7 +1410,7 @@

    @@ -1473,7 +1473,7 @@

    @@ -1529,7 +1529,7 @@

    @@ -1585,7 +1585,7 @@

    @@ -1641,7 +1641,7 @@

    @@ -1687,7 +1687,7 @@

    @@ -1736,7 +1736,7 @@

    @@ -1781,7 +1781,7 @@

    @@ -1833,7 +1833,7 @@

    @@ -1882,7 +1882,7 @@

    @@ -1938,7 +1938,7 @@

    @@ -2002,7 +2002,7 @@

    @@ -2010,7 +2010,7 @@

    protected - loadFile(string $key, string $provider) : string|null + loadFile(string $key, string $provider) : string
    @@ -2040,7 +2040,7 @@

    Parameters
    Return values
    - string|null + string
    @@ -2058,7 +2058,7 @@

    diff --git a/classes/chillerlan-OAuth-Storage-MemoryStorage.html b/classes/chillerlan-OAuth-Storage-MemoryStorage.html index 6569662..7324d40 100644 --- a/classes/chillerlan-OAuth-Storage-MemoryStorage.html +++ b/classes/chillerlan-OAuth-Storage-MemoryStorage.html @@ -186,7 +186,7 @@

    ENCRYPT_FORMAT -  = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_HEX +  = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_HEX
    Output format for encrypted data
    @@ -422,7 +422,7 @@

    @@ -433,7 +433,7 @@

    protected int ENCRYPT_FORMAT - = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_HEX + = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_HEX @@ -454,7 +454,7 @@

    @@ -485,7 +485,7 @@

    @@ -516,7 +516,7 @@

    @@ -563,7 +563,7 @@

    @@ -600,7 +600,7 @@

    @@ -681,7 +681,7 @@

    @@ -997,7 +997,7 @@

    @@ -1346,7 +1346,7 @@

    @@ -1577,7 +1577,7 @@

    @@ -1623,7 +1623,7 @@

    @@ -1672,7 +1672,7 @@

    @@ -1721,7 +1721,7 @@

    diff --git a/classes/chillerlan-OAuth-Storage-OAuthStorageAbstract.html b/classes/chillerlan-OAuth-Storage-OAuthStorageAbstract.html index 8032d0e..a642ea7 100644 --- a/classes/chillerlan-OAuth-Storage-OAuthStorageAbstract.html +++ b/classes/chillerlan-OAuth-Storage-OAuthStorageAbstract.html @@ -151,7 +151,7 @@

    @@ -193,7 +193,7 @@

    ENCRYPT_FORMAT -  = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_HEX +  = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_HEX
    Output format for encrypted data
    @@ -317,7 +317,7 @@

    @@ -328,7 +328,7 @@

    protected int ENCRYPT_FORMAT - = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_HEX + = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_HEX @@ -349,7 +349,7 @@

    @@ -380,7 +380,7 @@

    @@ -411,7 +411,7 @@

    @@ -458,7 +458,7 @@

    @@ -495,7 +495,7 @@

    @@ -537,7 +537,7 @@

    @@ -589,7 +589,7 @@

    @@ -638,7 +638,7 @@

    @@ -701,7 +701,7 @@

    @@ -747,7 +747,7 @@

    @@ -796,7 +796,7 @@

    @@ -845,7 +845,7 @@

    diff --git a/classes/chillerlan-OAuth-Storage-SessionStorage.html b/classes/chillerlan-OAuth-Storage-SessionStorage.html index bfe8d39..f8dd3f3 100644 --- a/classes/chillerlan-OAuth-Storage-SessionStorage.html +++ b/classes/chillerlan-OAuth-Storage-SessionStorage.html @@ -186,7 +186,7 @@

    ENCRYPT_FORMAT -  = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_HEX +  = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_HEX
    Output format for encrypted data
    @@ -429,7 +429,7 @@

    @@ -440,7 +440,7 @@

    protected int ENCRYPT_FORMAT - = \chillerlan\OAuth\Core\Utilities::ENCRYPT_FORMAT_HEX + = \chillerlan\Utilities\Crypto::ENCRYPT_FORMAT_HEX @@ -461,7 +461,7 @@

    @@ -492,7 +492,7 @@

    @@ -523,7 +523,7 @@

    @@ -570,7 +570,7 @@

    @@ -607,7 +607,7 @@

    @@ -1051,7 +1051,7 @@

    @@ -1400,7 +1400,7 @@

    @@ -1631,7 +1631,7 @@

    @@ -1677,7 +1677,7 @@

    @@ -1726,7 +1726,7 @@

    @@ -1775,7 +1775,7 @@

    diff --git a/classes/chillerlan-OAuthTest-Core-OAuthOptionsTest.html b/classes/chillerlan-OAuthTest-Core-OAuthOptionsTest.html index cab2cb2..3fae570 100644 --- a/classes/chillerlan-OAuthTest-Core-OAuthOptionsTest.html +++ b/classes/chillerlan-OAuthTest-Core-OAuthOptionsTest.html @@ -149,7 +149,7 @@

    @@ -242,7 +242,7 @@

    @@ -276,7 +276,7 @@

    @@ -310,7 +310,7 @@

    OAuthOptionsTest.php : - 44 + 45 @@ -344,7 +344,7 @@

    @@ -378,7 +378,7 @@

    OAuthOptionsTest.php : - 31 + 32 diff --git a/classes/chillerlan-OAuthTest-Core-UtilitiesTest.html b/classes/chillerlan-OAuthTest-Core-UtilitiesTest.html index 6c28dd5..005e9cc 100644 --- a/classes/chillerlan-OAuthTest-Core-UtilitiesTest.html +++ b/classes/chillerlan-OAuthTest-Core-UtilitiesTest.html @@ -149,7 +149,7 @@

    @@ -184,18 +184,6 @@

    -
    - encryptionFormatProvider() - -  : array<string, array<int, int>> -
    - -
    - testEncryptDecrypt() - -  : void -
    -
    testGetProviders() @@ -229,102 +217,6 @@

    -

    - encryptionFormatProvider() - - -

    - - - - - public - static encryptionFormatProvider() : array<string, array<int, int>> - -
    -
    - - - - - - - -
    -
    Return values
    - array<string, array<int, int>> -
    - -
    -
    -

    - testEncryptDecrypt() - - -

    - - - - - public - testEncryptDecrypt(int $format) : void - -
    -
    - - -
    Parameters
    -
    -
    - $format - : int -
    -
    - -
    -
    - - - - -
    -
    - Attributes - -
    -
    -
    - #[DataProvider] -
    -
    - 'encryptionFormatProvider' -
    -
    -
    - - -
    -
    @@ -372,7 +264,7 @@

    UtilitiesTest.php : - 40 + 39 @@ -406,7 +298,7 @@

    UtilitiesTest.php : - 32 + 31 @@ -539,8 +431,6 @@

    Methods
  • @@ -2963,7 +2945,7 @@

    @@ -3042,7 +3024,7 @@

    diff --git a/files/src/Core/OAuth1Provider.php.txt b/files/src/Core/OAuth1Provider.php.txt index 01f5e99..ac8daf0 100644 --- a/files/src/Core/OAuth1Provider.php.txt +++ b/files/src/Core/OAuth1Provider.php.txt @@ -15,9 +15,9 @@ namespace chillerlan\OAuth\Core; use chillerlan\HTTP\Utils\{MessageUtil, QueryUtil}; use chillerlan\OAuth\Providers\ProviderException; +use chillerlan\Utilities\Str; use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface}; -use function array_merge, hash_hmac, implode, in_array, sodium_bin2base64, sprintf, strtoupper, time; -use const SODIUM_BASE64_VARIANT_ORIGINAL; +use function array_merge, hash_hmac, implode, in_array, sprintf, strtoupper, time; /** * Implements an abstract OAuth1 (1.0a) provider with all methods required by the OAuth1Interface. @@ -186,7 +186,7 @@ abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ $hash = hash_hmac('sha1', implode('&', $data), implode('&', $key), true); - return sodium_bin2base64($hash, SODIUM_BASE64_VARIANT_ORIGINAL); + return Str::base64encode($hash); } /** diff --git a/files/src/Core/OAuthProvider.php.txt b/files/src/Core/OAuthProvider.php.txt index 689c2b0..60999ad 100644 --- a/files/src/Core/OAuthProvider.php.txt +++ b/files/src/Core/OAuthProvider.php.txt @@ -18,17 +18,17 @@ use chillerlan\OAuth\OAuthOptions; use chillerlan\OAuth\Providers\ProviderException; use chillerlan\OAuth\Storage\{MemoryStorage, OAuthStorageInterface}; use chillerlan\Settings\SettingsContainerInterface; +use chillerlan\Utilities\Str; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\{ RequestFactoryInterface, RequestInterface, ResponseInterface, StreamFactoryInterface, StreamInterface, UriFactoryInterface }; use Psr\Log\{LoggerInterface, NullLogger}; -use ReflectionClass, UnhandledMatchError; -use function array_merge, array_shift, explode, implode, in_array, is_array, is_string, - json_encode, ltrim, random_bytes, rtrim, sodium_bin2hex, sodium_bin2base64, - sprintf, str_contains, str_starts_with, strip_tags, strtolower; -use const PHP_QUERY_RFC1738, SODIUM_BASE64_VARIANT_ORIGINAL; +use ReflectionClass; +use function array_merge, array_shift, explode, implode, in_array, is_array, is_string, ltrim, + random_bytes, rtrim, sodium_bin2hex, sprintf, str_contains, str_starts_with, strip_tags, strtolower; +use const PHP_QUERY_RFC1738; /** * Implements an abstract OAuth provider with all methods required by the OAuthInterface. @@ -271,7 +271,7 @@ abstract class OAuthProvider implements OAuthInterface{ * Adds an "Authorization: Basic " header to the given request */ protected function addBasicAuthHeader(RequestInterface $request):RequestInterface{ - $auth = sodium_bin2base64(sprintf('%s:%s', $this->options->key, $this->options->secret), SODIUM_BASE64_VARIANT_ORIGINAL); + $auth = Str::base64encode(sprintf('%s:%s', $this->options->key, $this->options->secret)); return $request->withHeader('Authorization', sprintf('Basic %s', $auth)); } @@ -363,7 +363,7 @@ abstract class OAuthProvider implements OAuthInterface{ $body = match($contentType){ 'application/x-www-form-urlencoded' => QueryUtil::build($body, PHP_QUERY_RFC1738), - 'application/json', 'application/vnd.api+json' => json_encode($body), + 'application/json', 'application/vnd.api+json' => Str::jsonEncode($body, 0), default => throw new ProviderException( sprintf('invalid content-type "%s" for the given array body', $contentType), ), diff --git a/files/src/Core/Utilities.php.txt b/files/src/Core/Utilities.php.txt index f32f942..1f291c3 100644 --- a/files/src/Core/Utilities.php.txt +++ b/files/src/Core/Utilities.php.txt @@ -13,49 +13,29 @@ declare(strict_types=1); namespace chillerlan\OAuth\Core; +use chillerlan\Utilities\File; use DirectoryIterator; use InvalidArgumentException; use ReflectionClass; -use RuntimeException; use function hash; -use function random_bytes; -use function realpath; -use function sodium_base642bin; -use function sodium_bin2base64; -use function sodium_bin2hex; -use function sodium_crypto_secretbox; -use function sodium_crypto_secretbox_keygen; -use function sodium_crypto_secretbox_open; -use function sodium_hex2bin; -use function sodium_memzero; use function substr; use function trim; -use const SODIUM_BASE64_VARIANT_ORIGINAL; -use const SODIUM_CRYPTO_SECRETBOX_NONCEBYTES; /** * Common utilities for use with the OAuth providers */ class Utilities{ - final public const ENCRYPT_FORMAT_BINARY = 0b00; - final public const ENCRYPT_FORMAT_BASE64 = 0b01; - final public const ENCRYPT_FORMAT_HEX = 0b10; - /** * Fetches a list of provider classes in the given directory * * @return array> */ public static function getProviders(string|null $providerDir = null, string|null $namespace = null):array{ - $providerDir = realpath(($providerDir ?? __DIR__.'/../Providers')); + $providerDir = File::realpath(($providerDir ?? __DIR__.'/../Providers')); $namespace = trim(($namespace ?? 'chillerlan\\OAuth\\Providers'), '\\'); $providers = []; - if($providerDir === false){ - throw new InvalidArgumentException('invalid $providerDir'); - } - foreach(new DirectoryIterator($providerDir) as $e){ if($e->getExtension() !== 'php'){ @@ -79,70 +59,4 @@ class Utilities{ return $providers; } - /** - * Creates a new cryptographically secure random encryption key (in hexadecimal format) - */ - public static function createEncryptionKey():string{ - return sodium_bin2hex(sodium_crypto_secretbox_keygen()); - } - - /** - * encrypts the given $data with $key, $format output [binary, base64, hex] - * - * @see \sodium_crypto_secretbox() - * @see \sodium_bin2base64() - * @see \sodium_bin2hex() - */ - public static function encrypt(string $data, string $keyHex, int $format = self::ENCRYPT_FORMAT_HEX):string{ - $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); - $box = sodium_crypto_secretbox($data, $nonce, sodium_hex2bin($keyHex)); - - $out = match($format){ - self::ENCRYPT_FORMAT_BINARY => $nonce.$box, - self::ENCRYPT_FORMAT_BASE64 => sodium_bin2base64($nonce.$box, SODIUM_BASE64_VARIANT_ORIGINAL), - self::ENCRYPT_FORMAT_HEX => sodium_bin2hex($nonce.$box), - default => throw new InvalidArgumentException('invalid format'), // @codeCoverageIgnore - }; - - sodium_memzero($data); - sodium_memzero($keyHex); - sodium_memzero($nonce); - sodium_memzero($box); - - return $out; - } - - /** - * decrypts the given $encrypted data with $key from $format input [binary, base64, hex] - * - * @see \sodium_crypto_secretbox_open() - * @see \sodium_base642bin() - * @see \sodium_hex2bin() - */ - public static function decrypt(string $encrypted, string $keyHex, int $format = self::ENCRYPT_FORMAT_HEX):string{ - - $bin = match($format){ - self::ENCRYPT_FORMAT_BINARY => $encrypted, - self::ENCRYPT_FORMAT_BASE64 => sodium_base642bin($encrypted, SODIUM_BASE64_VARIANT_ORIGINAL), - self::ENCRYPT_FORMAT_HEX => sodium_hex2bin($encrypted), - default => throw new InvalidArgumentException('invalid format'), // @codeCoverageIgnore - }; - - $nonce = substr($bin, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); - $box = substr($bin, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); - $data = sodium_crypto_secretbox_open($box, $nonce, sodium_hex2bin($keyHex)); - - sodium_memzero($encrypted); - sodium_memzero($keyHex); - sodium_memzero($bin); - sodium_memzero($nonce); - sodium_memzero($box); - - if($data === false){ - throw new RuntimeException('decryption failed'); // @codeCoverageIgnore - } - - return $data; - } - } diff --git a/js/searchIndex.js b/js/searchIndex.js index a07a31d..5f3139b 100644 --- a/js/searchIndex.js +++ b/js/searchIndex.js @@ -870,36 +870,6 @@ Search.appendIndex( "name": "getProviders", "summary": "Fetches\u0020a\u0020list\u0020of\u0020provider\u0020classes\u0020in\u0020the\u0020given\u0020directory", "url": "classes/chillerlan-OAuth-Core-Utilities.html#method_getProviders" - }, { - "fqsen": "\\chillerlan\\OAuth\\Core\\Utilities\u003A\u003AcreateEncryptionKey\u0028\u0029", - "name": "createEncryptionKey", - "summary": "Creates\u0020a\u0020new\u0020cryptographically\u0020secure\u0020random\u0020encryption\u0020key\u0020\u0028in\u0020hexadecimal\u0020format\u0029", - "url": "classes/chillerlan-OAuth-Core-Utilities.html#method_createEncryptionKey" - }, { - "fqsen": "\\chillerlan\\OAuth\\Core\\Utilities\u003A\u003Aencrypt\u0028\u0029", - "name": "encrypt", - "summary": "encrypts\u0020the\u0020given\u0020\u0024data\u0020with\u0020\u0024key,\u0020\u0024format\u0020output\u0020\u005Bbinary,\u0020base64,\u0020hex\u005D", - "url": "classes/chillerlan-OAuth-Core-Utilities.html#method_encrypt" - }, { - "fqsen": "\\chillerlan\\OAuth\\Core\\Utilities\u003A\u003Adecrypt\u0028\u0029", - "name": "decrypt", - "summary": "decrypts\u0020the\u0020given\u0020\u0024encrypted\u0020data\u0020with\u0020\u0024key\u0020from\u0020\u0024format\u0020input\u0020\u005Bbinary,\u0020base64,\u0020hex\u005D", - "url": "classes/chillerlan-OAuth-Core-Utilities.html#method_decrypt" - }, { - "fqsen": "\\chillerlan\\OAuth\\Core\\Utilities\u003A\u003AENCRYPT_FORMAT_BINARY", - "name": "ENCRYPT_FORMAT_BINARY", - "summary": "", - "url": "classes/chillerlan-OAuth-Core-Utilities.html#constant_ENCRYPT_FORMAT_BINARY" - }, { - "fqsen": "\\chillerlan\\OAuth\\Core\\Utilities\u003A\u003AENCRYPT_FORMAT_BASE64", - "name": "ENCRYPT_FORMAT_BASE64", - "summary": "", - "url": "classes/chillerlan-OAuth-Core-Utilities.html#constant_ENCRYPT_FORMAT_BASE64" - }, { - "fqsen": "\\chillerlan\\OAuth\\Core\\Utilities\u003A\u003AENCRYPT_FORMAT_HEX", - "name": "ENCRYPT_FORMAT_HEX", - "summary": "", - "url": "classes/chillerlan-OAuth-Core-Utilities.html#constant_ENCRYPT_FORMAT_HEX" }, { "fqsen": "\\chillerlan\\OAuth\\OAuthException", "name": "OAuthException", @@ -6060,16 +6030,6 @@ Search.appendIndex( "name": "testGetProvidersInvalidPathException", "summary": "", "url": "classes/chillerlan-OAuthTest-Core-UtilitiesTest.html#method_testGetProvidersInvalidPathException" - }, { - "fqsen": "\\chillerlan\\OAuthTest\\Core\\UtilitiesTest\u003A\u003AencryptionFormatProvider\u0028\u0029", - "name": "encryptionFormatProvider", - "summary": "", - "url": "classes/chillerlan-OAuthTest-Core-UtilitiesTest.html#method_encryptionFormatProvider" - }, { - "fqsen": "\\chillerlan\\OAuthTest\\Core\\UtilitiesTest\u003A\u003AtestEncryptDecrypt\u0028\u0029", - "name": "testEncryptDecrypt", - "summary": "", - "url": "classes/chillerlan-OAuthTest-Core-UtilitiesTest.html#method_testEncryptDecrypt" }, { "fqsen": "\\chillerlan\\OAuthTest\\Providers\\DummyOAuth1Provider", "name": "DummyOAuth1Provider",