blob: f9499692e40acbe258d2d356e931fad0b2e51ba4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package crud
import (
"fmt"
"os"
"gitlab.com/whiteboardguy/eno/internal/crypt"
"gitlab.com/whiteboardguy/eno/internal/utils"
)
func NewNote(output string) error {
fmt.Printf("Enter the passphrase: ")
password, err := utils.TakeSecureUserInput()
if err != nil {
return fmt.Errorf("failed to read passphrase: %v", err)
}
utils.TryMlock(password)
defer clear(password)
fmt.Printf("Confirm the passphrase: ")
passwordConfirm, err := utils.TakeSecureUserInput()
if err != nil {
return fmt.Errorf("failed to read passphrase: %v", err)
}
utils.TryMlock(passwordConfirm)
defer clear(passwordConfirm)
if string(password) != string(passwordConfirm) {
return fmt.Errorf("passphrases do not match")
}
encrypted, err := crypt.EncryptRawBytes(
[]byte(string(utils.RandomLettersNumbers(37))+"\nYou can Delete all of this ^^^"),
password,
)
if err != nil {
return err
}
fmt.Println(output)
file, err := os.Create(output)
if err != nil {
return err
}
_, err = file.Write(encrypted)
if err != nil {
return err
}
file.Sync()
// utils.ClearTerm()
fmt.Println("New note saved at:", file.Name())
return nil
}
|