Skip to content

Commit

Permalink
chore: remove redundant copy and slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
mrf345 committed Sep 9, 2024
1 parent c38cfdb commit a77c0b3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion safelock/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func getGCM(pwd string, nonce []byte, config EncryptionConfig) (gcm cipher.AEAD,
func (ag *asyncGcm) encryptChunk(chunk []byte) []byte {
item := <-ag.items
return append(
(*item.gcm).Seal(nil, *item.nonce, chunk[:], nil),
(*item.gcm).Seal(nil, *item.nonce, chunk, nil),
*item.nonce...,
)
}
Expand Down
4 changes: 2 additions & 2 deletions safelock/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestEncryptFile(t *testing.T) {

assert.Nil(inErr)
assert.Nil(outErr)
assert.Equal(content, string(decrypted[:]))
assert.Equal(content, string(decrypted))
}

func TestEncryptFileWithSha256AndGzip(t *testing.T) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestEncryptFileWithSha256AndGzip(t *testing.T) {

assert.Nil(inErr)
assert.Nil(outErr)
assert.Equal(content, string(decrypted[:]))
assert.Equal(content, string(decrypted))
}

func TestEncryptFileWithTimeout(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions safelock/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (sr *safelockReader) ReadHeader() (err error) {
return sr.handleErr(err)
}

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

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

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

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

copied = copy(*chunk, chunked)
sr.overflow = chunked[copied:]
copy(*chunk, chunked[:])

return
}

0 comments on commit a77c0b3

Please sign in to comment.