From cea3d0da4dccee2c94105f505a4584ea5afdaee3 Mon Sep 17 00:00:00 2001 From: marinthiercelin Date: Fri, 19 Feb 2021 14:54:31 +0100 Subject: [PATCH] Removed the cloning of the final data in the attachment processor (#114) * removed the cloning of the final data in the attachment processor * fix linter --- .golangci.yml | 7 ++++++- CHANGELOG.md | 5 +++++ crypto/attachment.go | 4 +++- crypto/keyring.go | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5548f18..8a94046 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,9 @@ linters-settings: funlen: lines: 100 statements: 80 + cyclop: + # the minimal code complexity to report + max-complexity: 20 issues: exclude-use-default: false @@ -32,4 +35,6 @@ linters: - exhaustivestruct # Enforce structures to be fully filled on instantiation - terrible with openpgp configs - paralleltest # Detects missing usage of t.Parallel() method in your Go test - forbidigo # Static analysis tool to forbid use of particular identifiers - - thelper # Enforce test helper formatting \ No newline at end of file + - thelper # Enforce test helper formatting + - revive # Force CamelCase instead of all caps + - cyclop # Temp disabling because of a bug that ignores the setting TODO : enable it once the fix as been released \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b735477..b41e8d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +## Changed +- Removed an unecessary cloning in the attachment processor, to perform better in low memory settings + ## [2.1.4] 2021-01-08 ### Added - Methods for generating an verifying encrypted detached signatures diff --git a/crypto/attachment.go b/crypto/attachment.go index 6a1d0a3..2944002 100644 --- a/crypto/attachment.go +++ b/crypto/attachment.go @@ -90,7 +90,9 @@ func (keyRing *KeyRing) newAttachmentProcessor( go func() { defer attachmentProc.done.Done() ciphertext, _ := ioutil.ReadAll(reader) - message := NewPGPMessage(ciphertext) + message := &PGPMessage{ + Data: ciphertext, + } split, splitError := message.SeparateKeyAndData(estimatedSize, garbageCollector) if attachmentProc.err != nil { attachmentProc.err = splitError diff --git a/crypto/keyring.go b/crypto/keyring.go index a1f3d6e..774b160 100644 --- a/crypto/keyring.go +++ b/crypto/keyring.go @@ -130,7 +130,7 @@ func (keyRing *KeyRing) GetKeyIDs() []uint64 { // parts of these KeyRings. func FilterExpiredKeys(contactKeys []*KeyRing) (filteredKeys []*KeyRing, err error) { now := time.Now() - hasExpiredEntity := false + hasExpiredEntity := false //nolint:ifshort filteredKeys = make([]*KeyRing, 0) for _, contactKeyRing := range contactKeys {