Skip to content

Commit 486b056

Browse files
committed
Fixed 'getPepper' method in 'PepperTrait'
1 parent 0544078 commit 486b056

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Released Notes
22

3+
## v3.1.1 - (2024-02-18)
4+
5+
### Fixed
6+
7+
- Fixed `getPepper` method in `PepperTrait`
8+
9+
-----------------------------------------------------------
10+
311
## v3.1.0 - (2024-01-31)
412

513
### Added

src/PepperTrait.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ trait PepperTrait
1212
*/
1313
private string $pepper;
1414

15+
/**
16+
* @var string
17+
*/
18+
private string $crypt_type;
19+
1520
/**
1621
* Create a secret entry (commonly called `pepper`)
1722
*
@@ -22,7 +27,9 @@ trait PepperTrait
2227
public function setPepper(string $pepper = "default_hash", string $crypt_type = "openssl"): self
2328
{
2429
$this->pepper = $pepper;
25-
$this->pepper = match ($crypt_type) {
30+
$this->crypt_type = $crypt_type;
31+
32+
$this->pepper = match ($this->crypt_type) {
2633
'openssl' => $this->useOpenSSL(),
2734
'sodium' => $this->useSodium(),
2835
};
@@ -35,6 +42,18 @@ public function setPepper(string $pepper = "default_hash", string $crypt_type =
3542
*/
3643
public function getPepper(): string
3744
{
45+
if ($this->pepper !== '') {
46+
if ($this->crypt_type == 'openssl') {
47+
$encryption = new Encryption(new OpenSslEncryption($this->pepper));
48+
$this->pepper = $encryption->decrypt($this->pepper);
49+
}
50+
51+
if ($this->crypt_type == 'sodium') {
52+
$encryption = new Encryption(new SodiumEncryption($this->pepper));
53+
$this->pepper = $encryption->decrypt($this->pepper);
54+
}
55+
}
56+
3857
return $this->pepper;
3958
}
4059

0 commit comments

Comments
 (0)