Other: add straightforward linters

This commit is contained in:
Jakub
2021-04-08 08:00:39 +02:00
parent 7d0af7624c
commit 2d95f21567
49 changed files with 148 additions and 139 deletions

View File

@ -19,7 +19,7 @@ package algo
import "reflect"
// SetIntersection complexity: O(n^2), could be better but this is simple enough
// SetIntersection complexity: O(n^2), could be better but this is simple enough.
func SetIntersection(a, b interface{}, eq func(a, b interface{}) bool) []interface{} {
set := make([]interface{}, 0)
av := reflect.ValueOf(a)

View File

@ -51,9 +51,8 @@ func WriteAttachmentBody(w io.Writer, kr *crypto.KeyRing, m *pmapi.Message, att
var dr io.Reader
dr, err = att.Decrypt(r, kr)
if err == openpgperrors.ErrKeyIncorrect {
// Do not fail if attachment is encrypted with a different key.
err = nil //nolint[wastedassing] Do not fail if attachment is encrypted with a different key.
dr = r
err = nil
att.Name += ".gpg"
att.MIMEType = "application/pgp-encrypted" //nolint
} else if err != nil && err != openpgperrors.ErrSignatureExpired {

View File

@ -48,7 +48,7 @@ func NewBuilder(client pmapi.Client, message *pmapi.Message) *Builder {
return &Builder{cl: client, msg: message, EncryptedToHTML: true, successfullyDecrypted: false}
}
// fetchMessage will update original PM message if successful
// fetchMessage will update original PM message if successful.
func (bld *Builder) fetchMessage() (err error) {
if bld.msg.Body != "" {
return nil
@ -211,11 +211,11 @@ func (bld *Builder) BuildMessage() (structure *BodyStructure, message []byte, er
return structure, message, err
}
// SuccessfullyDecrypted is true when message was fetched and decrypted successfully
// SuccessfullyDecrypted is true when message was fetched and decrypted successfully.
func (bld *Builder) SuccessfullyDecrypted() bool { return bld.successfullyDecrypted }
// WriteBody decrypts PM message and writes main body section. The external PGP
// message is written as is (including attachments)
// message is written as is (including attachments).
func (bld *Builder) WriteBody(w io.Writer) error {
kr, err := bld.cl.KeyRingForAddressID(bld.msg.AddressID)
if err != nil {
@ -238,7 +238,7 @@ func (bld *Builder) WriteBody(w io.Writer) error {
return err
}
// WriteAttachmentBody decrypts and writes the attachments
// WriteAttachmentBody decrypts and writes the attachments.
func (bld *Builder) WriteAttachmentBody(w io.Writer, att *pmapi.Attachment, attReader io.Reader) (err error) {
kr, err := bld.cl.KeyRingForAddressID(bld.msg.AddressID)
if err != nil {
@ -248,9 +248,8 @@ func (bld *Builder) WriteAttachmentBody(w io.Writer, att *pmapi.Attachment, attR
var dr io.Reader
dr, err = att.Decrypt(attReader, kr)
if err == openpgperrors.ErrKeyIncorrect {
// Do not fail if attachment is encrypted with a different key
err = nil //nolint[wastedasign] Do not fail if attachment is encrypted with a different key
dr = attReader
err = nil
att.Name += ".gpg"
att.MIMEType = "application/pgp-encrypted"
} else if err != nil && err != openpgperrors.ErrSignatureExpired {

View File

@ -38,7 +38,7 @@ type SectionInfo struct {
reader io.Reader
}
// Read and count
// Read and count.
func (si *SectionInfo) Read(p []byte) (n int, err error) {
n, err = si.reader.Read(p)
si.Size += n
@ -237,11 +237,11 @@ func (bs *BodyStructure) parseAllChildSections(r io.Reader, currentPath []int, s
}
// Clear all buffers.
bodyReader = nil
bodyReader = nil //nolint[wastedassign] just to be sure we clear garbage collector
bodyInfo.reader = nil
tp.R = nil
tp = nil
bufInfo = nil // nolint
tp = nil //nolint[wastedassign] just to be sure we clear garbage collector
bufInfo = nil //nolint[ineffassign] just to be sure we clear garbage collector
info.reader = nil
// Store boundaries.
@ -305,6 +305,11 @@ func stringPathFromInts(ints []int) (ret string) {
return
}
func (bs *BodyStructure) hasInfo(sectionPath []int) bool {
_, err := bs.getInfo(sectionPath)
return err == nil
}
func (bs *BodyStructure) getInfo(sectionPath []int) (sectionInfo *SectionInfo, err error) {
path := stringPathFromInts(sectionPath)
sectionInfo, ok := (*bs)[path]
@ -404,7 +409,7 @@ func (bs *BodyStructure) IMAPBodyStructure(currentPart []int) (imapBS *imap.Body
nextPart := append(currentPart, 1)
for {
if _, err := bs.getInfo(nextPart); err != nil {
if !bs.hasInfo(nextPart) {
break
}
var subStruct *imap.BodyStructure

View File

@ -89,7 +89,7 @@ func TestParallelErrorInProcess(t *testing.T) {
return value, nil
}
collect := func(idx int, value interface{}) error {
lastCollected = value.(int)
lastCollected = value.(int) //nolint[forcetypeassert]
return nil
}

View File

@ -61,7 +61,7 @@ func NewBasicTLSDialer() *BasicTLSDialer {
func (b *BasicTLSDialer) DialTLS(network, address string) (conn net.Conn, err error) {
dialer := &net.Dialer{Timeout: 30 * time.Second} // Alternative Routes spec says this should be a 30s timeout.
var tlsConfig *tls.Config = nil
var tlsConfig *tls.Config
// If we are not dialing the standard API then we should skip cert verification checks.
if address != rootURL {

View File

@ -39,7 +39,7 @@ func NewProxyTLSDialer(dialer TLSDialer, cm *ClientManager) *ProxyTLSDialer {
// DialTLS dials the given network/address. If it fails, it retries using a proxy.
func (d *ProxyTLSDialer) DialTLS(network, address string) (conn net.Conn, err error) {
if conn, err = d.dialer.DialTLS(network, address); err == nil {
return
return conn, nil
}
if !d.cm.allowProxy {

View File

@ -107,6 +107,8 @@ func (em *EventMessage) UnmarshalJSON(b []byte) (err error) {
case EventUpdate, EventUpdateFlags:
em.Updated = &EventMessageUpdated{ID: raw.ID}
return json.Unmarshal(raw.Message, em.Updated)
case EventDelete:
return nil
}
return nil
}
@ -121,6 +123,7 @@ func (em *EventMessage) MarshalJSON() ([]byte, error) {
raw.Message, err = json.Marshal(em.Created)
case EventUpdate, EventUpdateFlags:
raw.Message, err = json.Marshal(em.Updated)
case EventDelete:
}
if err != nil {
return nil, err

View File

@ -25,7 +25,7 @@ import (
"github.com/ProtonMail/gopenpgp/v2/crypto"
)
// Flags
// Key flags.
const (
UseToVerifyFlag = 1 << iota
UseToEncryptFlag

View File

@ -22,7 +22,7 @@ import (
"fmt"
)
// System labels
// System labels.
const (
InboxLabel = "0"
AllDraftsLabel = "1"
@ -188,7 +188,7 @@ func (c *client) DeleteLabel(id string) (err error) {
return
}
// LeastUsedColor is intended to return color for creating a new inbox or label
// LeastUsedColor is intended to return color for creating a new inbox or label.
func LeastUsedColor(colors []string) (color string) {
color = LabelColors[0]
frequency := map[string]int{}

View File

@ -24,14 +24,14 @@ import (
"github.com/ProtonMail/gopenpgp/v2/crypto"
)
// Draft actions
// Draft actions.
const (
DraftActionReply = 0
DraftActionReplyAll = 1
DraftActionForward = 2
)
// PackageFlag for send message package types
// PackageFlag for send message package types.
type PackageFlag int
func (p *PackageFlag) Has(flag PackageFlag) bool { return iHasFlag(int(*p), int(flag)) }
@ -65,7 +65,7 @@ const (
SignatureAttachedArmored = SignatureFlag(2)
)
// DraftReq defines paylod for creating drafts
// DraftReq defines paylod for creating drafts.
type DraftReq struct {
Message *Message
ParentID string `json:",omitempty"`

View File

@ -52,7 +52,7 @@ func getTrustedServerWithHandler(handler http.HandlerFunc) *httptest.Server {
return proxy
}
// server.crt
// server.crt data.
const servercrt = `
-----BEGIN CERTIFICATE-----
MIIE5TCCA82gAwIBAgIJAKsmhcMFGfGcMA0GCSqGSIb3DQEBCwUAMIGsMQswCQYD

View File

@ -172,11 +172,11 @@ func checkHeader(h http.Header, field, exp string) error {
return nil
}
func isAuthReq(r *http.Request, uid, token string) error { // nolint[unparam]
func isAuthReq(r *http.Request, uid, token string) error { //nolint[unparam] always retrieves testUID
if err := checkHeader(r.Header, "x-pm-uid", uid); err != nil {
return err
}
if err := checkHeader(r.Header, "authorization", "Bearer "+token); err != nil {
if err := checkHeader(r.Header, "authorization", "Bearer "+token); err != nil { //nolint[revive] can return the error right away but this is easier to read
return err
}
return nil

View File

@ -33,7 +33,7 @@ import (
var ErrTLSMismatch = errors.New("no TLS fingerprint match found")
// TrustedAPIPins contains trusted public keys of the protonmail API and proxies.
// NOTE: the proxy pins are the same for all proxy servers, guaranteed by infra team ;)
// NOTE: the proxy pins are the same for all proxy servers, guaranteed by infra team ;).
var TrustedAPIPins = []string{ // nolint[gochecknoglobals]
// api.protonmail.ch
`pin-sha256="drtmcR2kFkM8qJClsuWgUzxgBkePfRCkRpqUesyDmeE="`, // current

View File

@ -29,7 +29,7 @@ const (
PaidAdminRole
)
// User status
// User status.
const (
DeletedUser = 0
DisabledUser = 1

View File

@ -29,12 +29,12 @@ import (
"github.com/jameskeane/bcrypt"
)
// BCryptHash function bcrypt algorithm to hash password with salt
// BCryptHash function bcrypt algorithm to hash password with salt.
func BCryptHash(password string, salt string) (string, error) {
return bcrypt.Hash(password, salt)
}
// ExpandHash extends the byte data for SRP flow
// ExpandHash extends the byte data for SRP flow.
func ExpandHash(data []byte) []byte {
part0 := sha512.Sum512(append(data, 0))
part1 := sha512.Sum512(append(data, 1))
@ -51,7 +51,7 @@ func ExpandHash(data []byte) []byte {
// HashPassword returns the hash of password argument. Based on version number
// following arguments are used in addition to password:
// * 0, 1, 2: userName and modulus
// * 3, 4: salt and modulus
// * 3, 4: salt and modulus.
func HashPassword(authVersion int, password, userName string, salt, modulus []byte) ([]byte, error) {
switch authVersion {
case 4, 3:

View File

@ -37,7 +37,7 @@ var (
// Store random reader in a variable to be able to overwrite it in tests
// Amored pubkey for modulus verification
// Amored pubkey for modulus verification.
const modulusPubkey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
xjMEXAHLgxYJKwYBBAHaRw8BAQdAFurWXXwjTemqjD7CXjXVyKf0of7n9Ctm
@ -73,12 +73,12 @@ func ReadClearSignedMessage(signedMessage string) (string, error) {
return string(modulusBlock.Bytes), nil
}
// SrpProofs object
// SrpProofs object.
type SrpProofs struct { //nolint[golint]
ClientProof, ClientEphemeral, ExpectedServerProof []byte
}
// SrpAuth stores byte data for the calculation of SRP proofs
// SrpAuth stores byte data for the calculation of SRP proofs.
type SrpAuth struct { //nolint[golint]
Modulus, ServerEphemeral, HashedPassword []byte
}
@ -213,7 +213,7 @@ func (s *SrpAuth) GenerateSrpProofs(length int) (res *SrpProofs, err error) { //
return &SrpProofs{ClientEphemeral: fromInt(clientEphemeral), ClientProof: clientProof, ExpectedServerProof: serverProof}, nil
}
// GenerateVerifier verifier for update pwds and create accounts
// GenerateVerifier verifier for update pwds and create accounts.
func (s *SrpAuth) GenerateVerifier(length int) ([]byte, error) {
return nil, errors.New("pm-srp: the client doesn't need SRP GenerateVerifier")
}

View File

@ -28,10 +28,10 @@ import (
"github.com/sirupsen/logrus"
)
// maxFileSize limit tre single file size after decopression is not larger than 1GB
// maxFileSize limit tre single file size after decopression is not larger than 1GB.
const maxFileSize = int64(1 * 1024 * 1024 * 1024) // 1 GB
// ErrFileTooLarge returned when decompressed file is too large
// ErrFileTooLarge returned when decompressed file is too large.
var ErrFileTooLarge = errors.New("trying to decompress file larger than 1GB")
type limitReader struct {
@ -40,6 +40,7 @@ type limitReader struct {
}
// Read returns error if limit was exceeded. Inspired by io.LimitReader.Read
// implementation.
func (lr *limitReader) Read(p []byte) (n int, err error) {
if lr.n <= 0 {
return 0, ErrFileTooLarge
@ -52,7 +53,7 @@ func (lr *limitReader) Read(p []byte) (n int, err error) {
return
}
// UntarToDir decopmress and unarchive the files into directory
// UntarToDir decopmress and unarchive the files into directory.
func UntarToDir(r io.Reader, dir string) error {
tr := tar.NewReader(r)