Skip to content

Commit 94552e6

Browse files
committed
Encryption update, linting fixes
1 parent 61b6926 commit 94552e6

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

.golangci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ linters:
166166
# - structcheck # deprecated
167167
- stylecheck
168168
# - tagliatelle
169-
- tenv
169+
# - tenv
170170
- testpackage
171171
- thelper
172172
- tparallel
@@ -175,6 +175,7 @@ linters:
175175
# - unparam
176176
- unused
177177
- usestdlibvars
178+
- usetesting
178179
# - varcheck # deprecated
179180
# - varnamelen
180181
- wastedassign

app/lib/filter/params.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,9 @@ func (p *Params) Filtered(key string, available []string, logger util.Logger) *P
166166
})
167167
if containsCol {
168168
allowed = append(allowed, o)
169-
} else {
170-
if logger != nil {
171-
const msg = "no column [%s] for [%s] available in allowed columns [%s]"
172-
logger.Warnf(msg, o.Column, p.Key, util.StringArrayOxfordComma(available, "and"))
173-
}
169+
} else if logger != nil {
170+
const msg = "no column [%s] for [%s] available in allowed columns [%s]"
171+
logger.Warnf(msg, o.Column, p.Key, util.StringArrayOxfordComma(available, "and"))
174172
}
175173
})
176174
return &Params{Key: p.Key, Orderings: allowed, Limit: p.Limit, Offset: p.Offset}

app/util/encryption.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func EncryptMessage(key []byte, message string, logger Logger) (string, error) {
3232
return "", errors.Wrap(err, "could not encrypt")
3333
}
3434

35-
stream := cipher.NewCFBEncrypter(block, iv)
35+
stream := cipher.NewCTR(block, iv)
3636
stream.XORKeyStream(cipherText[aes.BlockSize:], byteMsg)
3737

3838
return base64.StdEncoding.EncodeToString(cipherText), nil
@@ -55,7 +55,7 @@ func DecryptMessage(key []byte, message string, logger Logger) (string, error) {
5555
iv := cipherText[:aes.BlockSize]
5656
cipherText = cipherText[aes.BlockSize:]
5757

58-
stream := cipher.NewCFBDecrypter(block, iv)
58+
stream := cipher.NewCTR(block, iv)
5959
stream.XORKeyStream(cipherText, cipherText)
6060

6161
return string(cipherText), nil

app/util/random.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/samber/lo"
12+
"github.com/samber/lo/mutable"
1213
)
1314

1415
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
@@ -93,7 +94,10 @@ func RandomURL() *url.URL {
9394

9495
func RandomElements[T any](slice []T, idx int) []T {
9596
if len(slice) <= idx {
96-
return lo.Shuffle(slice)
97+
x := make([]T, len(slice))
98+
copy(slice, x)
99+
mutable.Shuffle(x)
100+
return x
97101
}
98102
return lo.Map(lo.Range(idx), func(_ int, _ int) T {
99103
return slice[RandomInt(len(slice))]

0 commit comments

Comments
 (0)