Skip to content
Closed
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
15 changes: 13 additions & 2 deletions src/Cryptography/PersonalDataPayloadCryptographer.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

declare(strict_types=1);
Expand All @@ -23,6 +23,7 @@
private readonly CipherKeyStore $cipherKeyStore,
private readonly CipherKeyFactory $cipherKeyFactory,
private readonly Cipher $cipher,
private readonly string $encryptedDataPrefix = '',
) {
}

Expand Down Expand Up @@ -51,7 +52,7 @@
continue;
}

$data[$propertyMetadata->fieldName()] = $this->cipher->encrypt(
$data[$propertyMetadata->fieldName()] = $this->encryptedDataPrefix . $this->cipher->encrypt(
$cipherKey,
$data[$propertyMetadata->fieldName()],
);
Expand Down Expand Up @@ -84,6 +85,16 @@
continue;
}

$fieldData = $data[$propertyMetadata->fieldName()];

Check failure on line 88 in src/Cryptography/PersonalDataPayloadCryptographer.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.4, ubuntu-latest)

src/Cryptography/PersonalDataPayloadCryptographer.php:88:13: MixedAssignment: Unable to determine the type that $fieldData is being assigned to (see https://psalm.dev/032)

if ($this->encryptedDataPrefix !== '') {
if (str_starts_with($fieldData, $this->encryptedDataPrefix)) {

Check failure on line 91 in src/Cryptography/PersonalDataPayloadCryptographer.php

View workflow job for this annotation

GitHub Actions / Static Analysis by PHPStan (locked, 8.4, ubuntu-latest)

Parameter #1 $haystack of function str_starts_with expects string, mixed given.

Check failure on line 91 in src/Cryptography/PersonalDataPayloadCryptographer.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.4, ubuntu-latest)

src/Cryptography/PersonalDataPayloadCryptographer.php:91:37: MixedArgument: Argument 1 of str_starts_with cannot be mixed, expecting string (see https://psalm.dev/030)
$fieldData = mb_substr($fieldData, mb_strlen($this->encryptedDataPrefix));

Check failure on line 92 in src/Cryptography/PersonalDataPayloadCryptographer.php

View workflow job for this annotation

GitHub Actions / Static Analysis by PHPStan (locked, 8.4, ubuntu-latest)

Parameter #1 $string of function mb_substr expects string, mixed given.
} else {
continue;
}
}

if (!$cipherKey) {
$data[$propertyMetadata->fieldName()] = $propertyMetadata->personalDataFallback();
continue;
Expand All @@ -92,7 +103,7 @@
try {
$data[$propertyMetadata->fieldName()] = $this->cipher->decrypt(
$cipherKey,
$data[$propertyMetadata->fieldName()],
$fieldData,

Check failure on line 106 in src/Cryptography/PersonalDataPayloadCryptographer.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.4, ubuntu-latest)

src/Cryptography/PersonalDataPayloadCryptographer.php:106:21: MixedArgument: Argument 2 of Patchlevel\Hydrator\Cryptography\Cipher\Cipher::decrypt cannot be mixed|string, expecting string (see https://psalm.dev/030)
);
} catch (DecryptionFailed) {
$data[$propertyMetadata->fieldName()] = $propertyMetadata->personalDataFallback();
Expand Down
Loading