Skip to content

Commit b1d09b3

Browse files
committed
unescape decode errors
1 parent a1a08c5 commit b1d09b3

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ If object is a map, the keys are the environment variables and the values are th
150150
- Add a `-force` flag to `sicher init` to overwrite the encrypted file if it already exists
151151
- Enable support for nested yaml env files
152152
- Add support for other types of encryption
153+
- Dont replace the file if the content is the same
153154
- test for Edit
154155

155156
### License

encryption.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import (
1010

1111
// encrypt encrypts the given plaintext with the given key and returns the ciphertext
1212
func encrypt(key string, fileData []byte) (nonce []byte, ciphertext []byte, err error) {
13-
hKey, _ := hex.DecodeString(key)
13+
hKey, err := hex.DecodeString(key)
14+
if err != nil {
15+
return
16+
}
17+
1418
block, err := aes.NewCipher(hKey)
1519
if err != nil {
1620
return
@@ -31,7 +35,11 @@ func encrypt(key string, fileData []byte) (nonce []byte, ciphertext []byte, err
3135
}
3236

3337
func decrypt(key string, nonce, text []byte) (plaintext []byte, err error) {
34-
hKey, _ := hex.DecodeString(key)
38+
hKey, err := hex.DecodeString(key)
39+
if err != nil {
40+
return
41+
}
42+
3543
block, err := aes.NewCipher(hKey)
3644
if err != nil {
3745
return

sicher.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ func (s *sicher) Initialize(scanReader io.Reader) error {
7070
}
7171
defer keyFile.Close()
7272

73-
keyFileStats, _ := keyFile.Stat()
73+
keyFileStats, err := keyFile.Stat()
74+
if err != nil {
75+
return fmt.Errorf("error getting key file stats: %s", err)
76+
}
7477

7578
// create the encrypted credentials file if it doesn't exist
7679
encFile, err := os.OpenFile(fmt.Sprintf("%s%s.enc", s.Path, s.Environment), os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600)
@@ -79,7 +82,10 @@ func (s *sicher) Initialize(scanReader io.Reader) error {
7982
}
8083
defer encFile.Close()
8184

82-
encFileStats, _ := encFile.Stat()
85+
encFileStats, err := encFile.Stat()
86+
if err != nil {
87+
return fmt.Errorf("error getting key file stats: %s", err)
88+
}
8389

8490
// if keyfile is new
8591
// Absence of keyfile indicates that the project is new or keyfile is lost
@@ -114,7 +120,10 @@ func (s *sicher) Initialize(scanReader io.Reader) error {
114120
}
115121

116122
// stats will have changed if the file was truncated
117-
encFileStats, _ = encFile.Stat()
123+
encFileStats, err = encFile.Stat()
124+
if err != nil {
125+
return fmt.Errorf("error getting key file stats: %s", err)
126+
}
118127

119128
// if the encrypted file is new, write some random data to it
120129
if encFileStats.Size() < 1 {

0 commit comments

Comments
 (0)