mirror of
https://codeberg.org/scip/anydb.git
synced 2026-10-08 03:04:20 +02:00
update linter config, satisfy linter (#28)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
package app
|
||||
|
||||
/*
|
||||
Copyright © 2024 Thomas von Dein
|
||||
|
||||
@@ -14,7 +16,6 @@ GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package app
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
@@ -35,7 +36,7 @@ const (
|
||||
ArgonParallel uint8 = 2
|
||||
ArgonSaltLen int = 16
|
||||
ArgonKeyLen uint32 = 32
|
||||
B64SaltLen int = 16 //22
|
||||
B64SaltLen int = 16 // 22
|
||||
)
|
||||
|
||||
type Key struct {
|
||||
@@ -47,7 +48,8 @@ type Key struct {
|
||||
// password
|
||||
func AskForPassword() ([]byte, error) {
|
||||
fmt.Fprint(os.Stderr, "Password: ")
|
||||
pass, err := term.ReadPassword(int(syscall.Stdin))
|
||||
|
||||
pass, err := term.ReadPassword(syscall.Stdin)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read password: %w", err)
|
||||
}
|
||||
@@ -57,6 +59,8 @@ func AskForPassword() ([]byte, error) {
|
||||
return pass, nil
|
||||
}
|
||||
|
||||
// DeriveKey derives a key from password.
|
||||
//
|
||||
// We're using the Argon2id key derivation algorithm to derive a
|
||||
// secure key from the given password. This is important, because
|
||||
// users might use unsecure passwords. The resulting encrypted data
|
||||
@@ -78,7 +82,7 @@ func DeriveKey(password []byte, salt []byte) (*Key, error) {
|
||||
}
|
||||
|
||||
hash := argon2.IDKey(
|
||||
[]byte(password), salt,
|
||||
password, salt,
|
||||
ArgonIter,
|
||||
ArgonMem,
|
||||
ArgonParallel,
|
||||
@@ -95,6 +99,7 @@ func DeriveKey(password []byte, salt []byte) (*Key, error) {
|
||||
// Retrieve a random chunk of given size
|
||||
func GetRandom(size int, capacity int) ([]byte, error) {
|
||||
buf := make([]byte, size, capacity)
|
||||
|
||||
_, err := rand.Read(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve random bytes: %w", err)
|
||||
@@ -103,7 +108,7 @@ func GetRandom(size int, capacity int) ([]byte, error) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
// Encrypt clear text given in attr using ChaCha20 and auhtenticate
|
||||
// Encrypt clear text given in attr using ChaCha20 and authenticate
|
||||
// using the mac Poly1305. The cipher text will be put into attr, thus
|
||||
// modifying it.
|
||||
//
|
||||
@@ -143,7 +148,7 @@ func Encrypt(pass []byte, attr *DbAttr) error {
|
||||
// Do the reverse
|
||||
func Decrypt(pass []byte, cipherb []byte) ([]byte, error) {
|
||||
if len(cipherb) < B64SaltLen {
|
||||
return nil, fmt.Errorf("encrypted cipher block too small")
|
||||
return nil, errors.New("encrypted cipher block too small")
|
||||
}
|
||||
|
||||
key, err := DeriveKey(pass, cipherb[0:B64SaltLen])
|
||||
|
||||
Reference in New Issue
Block a user