Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package crypto |
||
2 | |||
3 | // ICrypto is the interface for the crypto methods |
||
4 | // It's used to abstract the crypto methods used in the application |
||
5 | // so that they can be easily swapped out if needed |
||
6 | type ICrypto interface { |
||
7 | // Hash hashes a password using the configured crypto method |
||
8 | Hash(password string) ([]byte, error) |
||
9 | // Verify compares a crypto hashed password with its possible plaintext equivalent |
||
10 | Verify(password string, hash []byte) (bool, error) |
||
11 | } |
||
12 | |||
13 | // Crypto is the struct that holds the crypto methods |
||
14 | type Crypto struct { |
||
15 | crypto ICrypto |
||
16 | } |
||
17 | |||
18 | // Hash hashes a password using the configured crypto method |
||
19 | // password is the plaintext password to hash. |
||
20 | // Returns the hashed password, or an error on failure. |
||
21 | func (c *Crypto) Hash(password string) ([]byte, error) { |
||
22 | return c.crypto.Hash(password) //nolint:wrapcheck |
||
23 | } |
||
24 | |||
25 | // Verify compares a crypto hashed password with its possible plaintext equivalent |
||
26 | // password is the plaintext password to verify. |
||
27 | // hash is the bcrypt hashed password. |
||
28 | // Returns nil on success, or an error on failure. |
||
29 | // Returns true if the password matches, false if it does not. |
||
30 | func (c *Crypto) Verify(password string, hash []byte) (bool, error) { |
||
31 | return c.crypto.Verify(password, hash) //nolint:wrapcheck |
||
32 | } |
||
33 |