Skip to content

Commit

Permalink
Stricter typing
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Apr 19, 2024
1 parent 633cdc8 commit b34744d
Show file tree
Hide file tree
Showing 43 changed files with 59 additions and 157 deletions.
1 change: 1 addition & 0 deletions lib/namespaced.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

require_once dirname(dirname(__FILE__)) . '/autoload.php';

Expand Down
2 changes: 1 addition & 1 deletion lib/php72compat_const.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

declare(strict_types=1);
const SODIUM_LIBRARY_MAJOR_VERSION = 9;
const SODIUM_LIBRARY_MINOR_VERSION = 1;
const SODIUM_LIBRARY_VERSION = '1.0.8';
Expand Down
1 change: 1 addition & 0 deletions lib/php84compat_const.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
const SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES = 16;
const SODIUM_CRYPTO_AEAD_AEGIS128L_NSECBYTES = 0;
const SODIUM_CRYPTO_AEAD_AEGIS128L_NPUBBYTES = 32;
Expand Down
1 change: 1 addition & 0 deletions src/Compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,7 @@ public static function pad(
$k = $unpadded_len;
for ($j = 0; $j <= $xpadded_len; ++$j) {
$i = (int) $i;
/** @psalm-suppress RedundantCast */
$k = (int) $k;
if ($j >= $unpadded_len) {
$padded[$j] = "\0";
Expand Down
1 change: 1 addition & 0 deletions src/Core/AEGIS/State128L.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_AEGIS_State128L', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/AEGIS/State256.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_AEGIS_State256', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/AEGIS128L.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (!defined('SODIUM_COMPAT_AEGIS_C0')) {
define('SODIUM_COMPAT_AEGIS_C0', "\x00\x01\x01\x02\x03\x05\x08\x0d\x15\x22\x37\x59\x90\xe9\x79\x62");
Expand Down
1 change: 1 addition & 0 deletions src/Core/AEGIS256.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (!defined('SODIUM_COMPAT_AEGIS_C0')) {
define('SODIUM_COMPAT_AEGIS_C0', "\x00\x01\x01\x02\x03\x05\x08\x0d\x15\x22\x37\x59\x90\xe9\x79\x62");
Expand Down
2 changes: 2 additions & 0 deletions src/Core/AES.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_AES', false)) {
return;
Expand Down Expand Up @@ -271,6 +272,7 @@ public static function keySchedule(
for ($i = $nk, $j = 0, $k = 0; $i < $nkf; ++$i) {
if ($j === 0) {
$tmp = (($tmp & 0xff) << 24) | ($tmp >> 8);
/** @psalm-suppress InvalidArrayOffset */
$tmp = (self::subWord($tmp) ^ self::Rcon[$k]) & self::U32_MAX;
} elseif ($nk > 6 && $j === 4) {
$tmp = self::subWord($tmp);
Expand Down
3 changes: 3 additions & 0 deletions src/Core/AES/Block.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_AES_Block', false)) {
return;
}

/**
* @internal This should only be used by sodium_compat
*
* @psalm-suppress MissingTemplateParam
*/
class ParagonIE_Sodium_Core_AES_Block extends SplFixedArray
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/AES/Expanded.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_AES_Expanded', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/AES/KeySchedule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_AES_KeySchedule', false)) {
return;
Expand Down
5 changes: 3 additions & 2 deletions src/Core/BLAKE2b.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_BLAKE2b', false)) {
return;
Expand Down Expand Up @@ -450,7 +451,7 @@ public static function update(SplFixedArray $ctx, SplFixedArray $p, int $plen):
if ($plen > $fill) {
# memcpy( S->buf + left, in, fill ); /* Fill buffer */
for ($i = $fill; $i--;) {
$ctx[3][$i + $left] = $p[$i + $offset];
$ctx[3][$i + $left] = $p[(int) ($i + $offset)];
}

# S->buflen += fill;
Expand All @@ -477,7 +478,7 @@ public static function update(SplFixedArray $ctx, SplFixedArray $p, int $plen):
$plen -= $fill;
} else {
for ($i = $plen; $i--;) {
$ctx[3][$i + $left] = $p[$i + $offset];
$ctx[3][$i + $left] = $p[(int) ($i + $offset)];
}
$ctx[4] += $plen;
$offset += $plen;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Base64/Original.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Class ParagonIE_Sodium_Core_Base64
Expand Down
1 change: 1 addition & 0 deletions src/Core/Base64/UrlSafe.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Class ParagonIE_Sodium_Core_Base64UrlSafe
Expand Down
1 change: 1 addition & 0 deletions src/Core/ChaCha20.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_ChaCha20', false)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/Core/ChaCha20/Ctx.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_ChaCha20_Ctx', false)) {
return;
}

/**
* Class ParagonIE_Sodium_Core_ChaCha20_Ctx
*
* @template-implements ArrayAccess<int>
* @psalm-suppress MissingTemplateParam
*/
class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util implements ArrayAccess
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/ChaCha20/IetfCtx.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_ChaCha20_IetfCtx', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Curve25519.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519', false)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Curve25519/Fe.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519_Fe', false)) {
return;
Expand All @@ -8,6 +9,8 @@
* Class ParagonIE_Sodium_Core_Curve25519_Fe
*
* This represents a Field Element
*
* @psalm-suppress MissingTemplateParam
*/
class ParagonIE_Sodium_Core_Curve25519_Fe implements ArrayAccess
{
Expand Down Expand Up @@ -98,6 +101,7 @@ public function offsetUnset($offset)
*
* @param int $offset
* @return int
* @psalm-suppress ImplementedReturnTypeMismatch
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Curve25519/Ge/Cached.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519_Ge_Cached', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Curve25519/Ge/P1p1.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519_Ge_P1p1', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Curve25519/Ge/P2.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519_Ge_P2', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Curve25519/Ge/P3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519_Ge_P3', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Curve25519/Ge/Precomp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519_Ge_Precomp', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Curve25519/H.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Curve25519_H', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Ed25519.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Ed25519', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/HChaCha20.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_HChaCha20', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/HSalsa20.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_HSalsa20', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Poly1305.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Poly1305', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Poly1305/State.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Poly1305_State', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Ristretto255.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Class ParagonIE_Sodium_Core_Ristretto255
Expand Down
1 change: 1 addition & 0 deletions src/Core/Salsa20.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_Salsa20', false)) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Core/SecretStream/State.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Class ParagonIE_Sodium_Core_SecretStream_State
Expand Down
3 changes: 3 additions & 0 deletions src/Core/SipHash.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

if (class_exists('ParagonIE_Sodium_Core_SipHash', false)) {
return;
Expand Down Expand Up @@ -159,6 +160,8 @@ public static function rotl_64(int $int0, int $int1, int $c): array
* @return string
* @throws SodiumException
* @throws TypeError
*
* @psalm-suppress PossiblyUndefinedArrayOffset
*/
public static function sipHash24(
#[SensitiveParameter]
Expand Down
Loading

0 comments on commit b34744d

Please sign in to comment.