Skip to content

Commit a77c0b3

Browse files
committed
chore: remove redundant copy and slicing
1 parent c38cfdb commit a77c0b3

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

safelock/core.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func getGCM(pwd string, nonce []byte, config EncryptionConfig) (gcm cipher.AEAD,
8888
func (ag *asyncGcm) encryptChunk(chunk []byte) []byte {
8989
item := <-ag.items
9090
return append(
91-
(*item.gcm).Seal(nil, *item.nonce, chunk[:], nil),
91+
(*item.gcm).Seal(nil, *item.nonce, chunk, nil),
9292
*item.nonce...,
9393
)
9494
}

safelock/encrypt_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestEncryptFile(t *testing.T) {
5151

5252
assert.Nil(inErr)
5353
assert.Nil(outErr)
54-
assert.Equal(content, string(decrypted[:]))
54+
assert.Equal(content, string(decrypted))
5555
}
5656

5757
func TestEncryptFileWithSha256AndGzip(t *testing.T) {
@@ -79,7 +79,7 @@ func TestEncryptFileWithSha256AndGzip(t *testing.T) {
7979

8080
assert.Nil(inErr)
8181
assert.Nil(outErr)
82-
assert.Equal(content, string(decrypted[:]))
82+
assert.Equal(content, string(decrypted))
8383
}
8484

8585
func TestEncryptFileWithTimeout(t *testing.T) {

safelock/reader.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (sr *safelockReader) ReadHeader() (err error) {
6565
return sr.handleErr(err)
6666
}
6767

68-
header := string(bytes.Trim(headerBytes, "\x00")[:])
68+
header := string(bytes.Trim(headerBytes, "\x00"))
6969
sr.blocks = strings.Split(header, ";")[1:]
7070

7171
if len(sr.blocks) == 0 {
@@ -123,7 +123,7 @@ func (sr *safelockReader) Read(chunk []byte) (read int, err error) {
123123

124124
func (sr *safelockReader) handleOverflowIn(chunk *[]byte) (over int, done bool) {
125125
if len(sr.overflow) > 0 {
126-
over = copy(*chunk, sr.overflow[:])
126+
over = copy(*chunk, sr.overflow)
127127
sr.overflow = sr.overflow[over:]
128128
left := len(*chunk) - over
129129

@@ -146,7 +146,6 @@ func (sr *safelockReader) handleOverflowOut(chunk *[]byte, decrypted []byte) (co
146146

147147
copied = copy(*chunk, chunked)
148148
sr.overflow = chunked[copied:]
149-
copy(*chunk, chunked[:])
150149

151150
return
152151
}

0 commit comments

Comments
 (0)