Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-ql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer:2.0 as composer
FROM composer:2.8 AS composer

ARG TESTING=false
ENV TESTING=$TESTING
Expand All @@ -14,7 +14,7 @@ RUN composer update \
--no-scripts \
--prefer-dist

FROM php:8.0-cli-alpine as compile
FROM php:8.4-cli-alpine AS compile

RUN apk add --no-cache \
git \
Expand All @@ -27,7 +27,7 @@ RUN apk add --no-cache \
FROM compile AS scrypt
RUN pecl install scrypt

FROM compile as final
FROM compile AS final

LABEL maintainer="team@appwrite.io"

Expand All @@ -38,7 +38,8 @@ WORKDIR /usr/src/code
RUN docker-php-ext-install sodium

# Copy and enable scrypt extension
COPY --from=scrypt /usr/local/lib/php/extensions/no-debug-non-zts-20200930/scrypt.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
COPY --from=scrypt /usr/local/lib/php/extensions/no-debug-non-zts-20240924/scrypt.so /usr/local/lib/php/extensions/no-debug-non-zts-20240924/scrypt.so

RUN docker-php-ext-enable scrypt

# Configure PHP
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"scripts": {
"check": "./vendor/bin/phpstan analyse --level max src tests",
"lint": "./vendor/bin/pint --test",
"format": "./vendor/bin/pint"
"lint": "./vendor/bin/pint --config pint.json --test",
"format": "./vendor/bin/pint --config pint.json"
},
"require": {
"php": ">=8.0",
Expand Down
16 changes: 16 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"preset": "psr12",
"rules": {
"array_indentation": true,
"single_import_per_statement": true,
"simplified_null_return": true,
"ordered_imports": {
"sort_algorithm": "alpha",
"imports_order": [
"const",
"class",
"function"
]
}
}
}
25 changes: 7 additions & 18 deletions src/Auth/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ abstract class Hash
/**
* Set hashing options
*
* @param string $key The option key to set
* @param mixed $value The value to set for the option
* @return self
* @param string $key The option key to set
* @param mixed $value The value to set for the option
*/
public function setOption(string $key, mixed $value): self
public function setOption(string $key, mixed $value): static
{
$this->options[$key] = $value;

Expand All @@ -26,10 +25,9 @@ public function setOption(string $key, mixed $value): self
/**
* Set multiple hashing options at once
*
* @param array<string, mixed> $options Array of options to set
* @return self
* @param array<string, mixed> $options Array of options to set
*/
public function setOptions(array $options): self
public function setOptions(array $options): static
{
foreach ($options as $key => $value) {
$this->setOption($key, $value);
Expand All @@ -41,8 +39,8 @@ public function setOptions(array $options): self
/**
* Get a specific option value
*
* @param string $key The option key to retrieve
* @param mixed $default Default value if option doesn't exist
* @param string $key The option key to retrieve
* @param mixed $default Default value if option doesn't exist
* @return mixed The option value or default if not found
*/
public function getOption(string $key, mixed $default = null): mixed
Expand All @@ -62,25 +60,16 @@ public function getOptions(): array

/**
* Hash a value
*
* @param string $value
* @return string
*/
abstract public function hash(string $value): string;

/**
* Verify a value against a hash
*
* @param string $value
* @param string $hash
* @return bool
*/
abstract public function verify(string $value, string $hash): bool;

/**
* Get the name of the hash algorithm
*
* @return string
*/
abstract public function getName(): string;
}
23 changes: 10 additions & 13 deletions src/Auth/Hashes/Argon2.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Argon2 extends Hash
public function __construct()
{
$this->setOption('type', $this->getName());
$this->setOption('memoryCost', 65536);
$this->setOption('timeCost', 4);
$this->setOption('memory_cost', 65536);
$this->setOption('time_cost', 4);
$this->setOption('threads', 3);
}

Expand All @@ -36,42 +36,39 @@ public function verify(string $value, string $hash): bool
/**
* Set memory cost
*
* @param int $cost Memory cost in KiB
* @return self
* @param int $cost Memory cost in KiB
*
* @throws \InvalidArgumentException
*/
public function setMemoryCost(int $cost): self
public function setMemoryCost(int $cost): static
{
$this->setOption('memoryCost', $cost);
$this->setOption('memory_cost', $cost);

return $this;
}

/**
* Set time cost
*
* @param int $cost Number of iterations
* @return self
* @param int $cost Number of iterations
*
* @throws \InvalidArgumentException
*/
public function setTimeCost(int $cost): self
public function setTimeCost(int $cost): static
{
$this->setOption('timeCost', $cost);
$this->setOption('time_cost', $cost);

return $this;
}

/**
* Set number of threads
*
* @param int $threads Number of threads to use
* @return self
* @param int $threads Number of threads to use
*
* @throws \InvalidArgumentException
*/
public function setThreads(int $threads): self
public function setThreads(int $threads): static
{
$this->setOption('threads', $threads);

Expand Down
5 changes: 2 additions & 3 deletions src/Auth/Hashes/Bcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ public function verify(string $value, string $hash): bool
/**
* Set cost parameter
*
* @param int $cost Cost parameter between 4 and 31
* @return self
* @param int $cost Cost parameter between 4 and 31
*
* @throws \InvalidArgumentException
*/
public function setCost(int $cost): self
public function setCost(int $cost): static
{
if ($cost < 4 || $cost > 31) {
throw new \InvalidArgumentException('Cost must be between 4 and 31');
Expand Down
12 changes: 6 additions & 6 deletions src/Auth/Hashes/PHPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function verify(string $value, string $hash): bool
*/
protected function getRandomBytes(int $count): string
{
if (! is_int($count) || $count < 1) {
if ($count < 1) {
throw new \Exception('Argument count must be a positive integer');
}

Expand Down Expand Up @@ -106,7 +106,7 @@ protected function getRandomBytes(int $count): string
*/
protected function encode64(string $input, int $count): string
{
if (! is_int($count) || $count < 1) {
if ($count < 1) {
throw new \Exception('Argument count must be a positive integer');
}

Expand Down Expand Up @@ -226,8 +226,8 @@ private function cryptPrivate(string $password, string $setting): string
/**
* Set iteration count (log2)
*
* @param int $count Iteration count (log2) between 4 and 31
* @return self
* @param int $count Iteration count (log2) between 4 and 31
* @return static
*
* @throws \InvalidArgumentException
*/
Expand All @@ -245,8 +245,8 @@ public function setIterationCount(int $count): PHPass
/**
* Set portable hashes mode
*
* @param bool $portable Whether to use portable hashes
* @return self
* @param bool $portable Whether to use portable hashes
* @return static
*/
public function setPortableHashes(bool $portable): PHPass
{
Expand Down
24 changes: 10 additions & 14 deletions src/Auth/Hashes/Scrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function verify(string $value, string $hash): bool
/**
* Set CPU cost parameter
*
* @param int $cost CPU cost parameter N. Must be larger than 1 and a power of 2
* @return self
* @param int $cost CPU cost parameter N. Must be larger than 1 and a power of 2
* @return static
*
* @throws \InvalidArgumentException
*/
Expand All @@ -68,12 +68,11 @@ public function setCpuCost(int $cost): self
/**
* Set memory cost parameter
*
* @param int $cost Memory cost parameter r
* @return self
* @param int $cost Memory cost parameter r
*
* @throws \InvalidArgumentException
*/
public function setMemoryCost(int $cost): self
public function setMemoryCost(int $cost): static
{
if ($cost < 1) {
throw new \InvalidArgumentException('Memory cost must be >= 1');
Expand All @@ -87,12 +86,11 @@ public function setMemoryCost(int $cost): self
/**
* Set parallelization parameter
*
* @param int $cost Parallelization parameter p
* @return self
* @param int $cost Parallelization parameter p
*
* @throws \InvalidArgumentException
*/
public function setParallelCost(int $cost): self
public function setParallelCost(int $cost): static
{
if ($cost < 1) {
throw new \InvalidArgumentException('Parallel cost must be >= 1');
Expand All @@ -106,12 +104,11 @@ public function setParallelCost(int $cost): self
/**
* Set output length
*
* @param int $length Desired output length in bytes
* @return self
* @param int $length Desired output length in bytes
*
* @throws \InvalidArgumentException
*/
public function setLength(int $length): self
public function setLength(int $length): static
{
if ($length < 16) {
throw new \InvalidArgumentException('Length must be >= 16 bytes');
Expand All @@ -125,12 +122,11 @@ public function setLength(int $length): self
/**
* Set salt value
*
* @param string $salt Salt value for the hash
* @return self
* @param string $salt Salt value for the hash
*
* @throws \InvalidArgumentException
*/
public function setSalt(string $salt): self
public function setSalt(string $salt): static
{
if (empty($salt)) {
throw new \InvalidArgumentException('Salt cannot be empty');
Expand Down
15 changes: 6 additions & 9 deletions src/Auth/Hashes/ScryptModified.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ private function hashKeys(string $signerKeyBytes, string $derivedKeyBytes): stri
/**
* Set salt value
*
* @param string $salt Base64 encoded salt value
* @return self
* @param string $salt Base64 encoded salt value
*
* @throws \InvalidArgumentException
*/
public function setSalt(string $salt): self
public function setSalt(string $salt): static
{
if (empty($salt)) {
throw new \InvalidArgumentException('Salt cannot be empty');
Expand All @@ -128,12 +127,11 @@ public function setSalt(string $salt): self
/**
* Set salt separator
*
* @param string $separator Base64 encoded salt separator
* @return self
* @param string $separator Base64 encoded salt separator
*
* @throws \InvalidArgumentException
*/
public function setSaltSeparator(string $separator): self
public function setSaltSeparator(string $separator): static
{
if (! preg_match('/^[A-Za-z0-9+\/]+={0,2}$/', $separator)) {
throw new \InvalidArgumentException('Salt separator must be base64 encoded');
Expand All @@ -147,12 +145,11 @@ public function setSaltSeparator(string $separator): self
/**
* Set signer key
*
* @param string $key Base64 encoded signer key
* @return self
* @param string $key Base64 encoded signer key
*
* @throws \InvalidArgumentException
*/
public function setSignerKey(string $key): self
public function setSignerKey(string $key): static
{
if (empty($key)) {
throw new \InvalidArgumentException('Signer key cannot be empty');
Expand Down
5 changes: 2 additions & 3 deletions src/Auth/Hashes/Sha.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public function __construct()
/**
* Set SHA version
*
* @param string $version SHA version to use
* @return self
* @param string $version SHA version to use
*
* @throws \InvalidArgumentException
*/
public function setVersion(string $version): self
public function setVersion(string $version): static
{
if (! in_array($version, self::VALID_VERSIONS, true)) {
throw new \InvalidArgumentException('Invalid SHA version. Valid versions are: '.implode(', ', self::VALID_VERSIONS));
Expand Down
Loading