Address linter issues

This commit is contained in:
Andrea Maria Piana 2022-03-28 11:10:40 +01:00
parent 3b3921f483
commit 8a5f77dc37
22 changed files with 90 additions and 85 deletions

View File

@ -88,7 +88,7 @@ func TestVerifyAccountPassword(t *testing.T) {
require.FailNow(t, fmt.Sprintf("unexpected error: expected \n'%v', got \n'%v'", testCase.expectedError, err))
}
if err == nil {
if accountKey == nil {
if accountKey == nil { // nolint: staticcheck
require.Fail(t, "no error reported, but account key is missing")
}
accountAddress := types.BytesToAddress(types.FromHex(testCase.address))

View File

@ -1022,7 +1022,7 @@ func (b *GethStatusBackend) ConnectionChange(typ string, expensive bool) {
defer b.mu.Unlock()
state := connection.State{
Type: connection.NewConnectionType(typ),
Type: connection.NewType(typ),
Expensive: expensive,
}
if typ == connection.None {

View File

@ -239,7 +239,7 @@ func (db *Database) SetToProcessedByIDs(ids []int) (err error) {
}
in = in[:len(in)-1] + ")"
update, err = tx.Prepare("UPDATE app_metrics SET processed = 1 WHERE id IN " + in)
update, err = tx.Prepare("UPDATE app_metrics SET processed = 1 WHERE id IN " + in) // nolint: gosec
if err != nil {
return err
}

View File

@ -10,16 +10,16 @@ import (
// Zero value represents default assumption about network (online and unknown type).
type State struct {
Offline bool `json:"offline"`
Type connectionType `json:"type"`
Type Type `json:"type"`
Expensive bool `json:"expensive"`
}
// connectionType represents description of available
// Type represents description of available
// connection types as reported by React Native (see
// https://facebook.github.io/react-native/docs/netinfo.html)
// We're interested mainly in 'wifi' and 'cellular', but
// other types are also may be used.
type connectionType byte
type Type byte
const (
Offline = "offline"
@ -29,8 +29,8 @@ const (
None = "none"
)
// NewConnectionType creates new connectionType from string.
func NewConnectionType(s string) connectionType {
// NewType creates new Type from string.
func NewType(s string) Type {
switch s {
case Cellular:
return connectionCellular
@ -41,9 +41,9 @@ func NewConnectionType(s string) connectionType {
return connectionUnknown
}
// ConnectionType constants
// Type constants
const (
connectionUnknown connectionType = iota
connectionUnknown Type = iota
connectionCellular // cellular, LTE, 4G, 3G, EDGE, etc.
connectionWifi // WIFI or iOS simulator
)

View File

@ -3,15 +3,15 @@ package connection
import "testing"
func TestConnectionType(t *testing.T) {
c := NewConnectionType("wifi")
c := NewType("wifi")
if c != connectionWifi {
t.Fatalf("Wrong connection type: %v", c)
}
c = NewConnectionType("cellular")
c = NewType("cellular")
if c != connectionCellular {
t.Fatalf("Wrong connection type: %v", c)
}
c = NewConnectionType("bluetooth")
c = NewType("bluetooth")
if c != connectionUnknown {
t.Fatalf("Wrong connection type: %v", c)
}

View File

@ -44,9 +44,9 @@ func TestGetExistingHistory(t *testing.T) {
func TestNewHistoryRequest(t *testing.T) {
store := createInMemStore(t)
id := types.Hash{1}
req, err := store.GetRequest(id)
_, err := store.GetRequest(id)
require.Error(t, err)
req = store.NewRequest()
req := store.NewRequest()
req.ID = id
th, err := store.GetHistory(types.TopicType{1}, time.Hour)

1
go.mod
View File

@ -74,7 +74,6 @@ require (
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
golang.org/x/tools v0.1.2 // indirect
google.golang.org/protobuf v1.27.1
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0

View File

@ -913,7 +913,7 @@ func (m *Manager) SetPrivateKey(id []byte, privKey *ecdsa.PrivateKey) error {
return m.persistence.SetPrivateKey(id, privKey)
}
func (m *Manager) GetSyncedRawCommunity(id []byte) (*rawCommunityRow, error) {
func (m *Manager) GetSyncedRawCommunity(id []byte) (*RawCommunityRow, error) {
return m.persistence.getSyncedRawCommunity(id)
}

View File

@ -6,7 +6,7 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
)
type rawCommunityRow struct {
type RawCommunityRow struct {
ID []byte
PrivateKey []byte
Description []byte
@ -16,8 +16,8 @@ type rawCommunityRow struct {
Muted bool
}
func fromSyncCommunityProtobuf(syncCommProto *protobuf.SyncCommunity) rawCommunityRow {
return rawCommunityRow{
func fromSyncCommunityProtobuf(syncCommProto *protobuf.SyncCommunity) RawCommunityRow {
return RawCommunityRow{
ID: syncCommProto.Id,
PrivateKey: syncCommProto.PrivateKey,
Description: syncCommProto.Description,
@ -28,8 +28,8 @@ func fromSyncCommunityProtobuf(syncCommProto *protobuf.SyncCommunity) rawCommuni
}
}
func (p *Persistence) scanRowToStruct(rowScan func(dest ...interface{}) error) (*rawCommunityRow, error) {
rcr := new(rawCommunityRow)
func (p *Persistence) scanRowToStruct(rowScan func(dest ...interface{}) error) (*RawCommunityRow, error) {
rcr := new(RawCommunityRow)
syncedAt := sql.NullTime{}
err := rowScan(
@ -52,7 +52,7 @@ func (p *Persistence) scanRowToStruct(rowScan func(dest ...interface{}) error) (
return rcr, nil
}
func (p *Persistence) getAllCommunitiesRaw() (rcrs []*rawCommunityRow, err error) {
func (p *Persistence) getAllCommunitiesRaw() (rcrs []*RawCommunityRow, err error) {
var rows *sql.Rows
// Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing.
rows, err = p.db.Query(`SELECT * FROM communities_communities`)
@ -81,19 +81,19 @@ func (p *Persistence) getAllCommunitiesRaw() (rcrs []*rawCommunityRow, err error
return rcrs, nil
}
func (p *Persistence) getRawCommunityRow(id []byte) (*rawCommunityRow, error) {
func (p *Persistence) getRawCommunityRow(id []byte) (*RawCommunityRow, error) {
// Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing.
qr := p.db.QueryRow(`SELECT * FROM communities_communities WHERE id = ?`, id)
return p.scanRowToStruct(qr.Scan)
}
func (p *Persistence) getSyncedRawCommunity(id []byte) (*rawCommunityRow, error) {
func (p *Persistence) getSyncedRawCommunity(id []byte) (*RawCommunityRow, error) {
// Keep "*", if the db table is updated, syncing needs to match, this fail will force us to update syncing.
qr := p.db.QueryRow(`SELECT * FROM communities_communities WHERE id = ? AND synced_at > 0`, id)
return p.scanRowToStruct(qr.Scan)
}
func (p *Persistence) saveRawCommunityRow(rawCommRow rawCommunityRow) error {
func (p *Persistence) saveRawCommunityRow(rawCommRow RawCommunityRow) error {
_, err := p.db.Exec(
`INSERT INTO communities_communities ("id", "private_key", "description", "joined", "verified", "synced_at", "muted") VALUES (?, ?, ?, ?, ?, ?, ?)`,
rawCommRow.ID,
@ -107,7 +107,7 @@ func (p *Persistence) saveRawCommunityRow(rawCommRow rawCommunityRow) error {
return err
}
func (p *Persistence) saveRawCommunityRowWithoutSyncedAt(rawCommRow rawCommunityRow) error {
func (p *Persistence) saveRawCommunityRowWithoutSyncedAt(rawCommRow RawCommunityRow) error {
_, err := p.db.Exec(
`INSERT INTO communities_communities ("id", "private_key", "description", "joined", "verified", "muted") VALUES (?, ?, ?, ?, ?, ?)`,
rawCommRow.ID,

View File

@ -567,6 +567,7 @@ func (s *MessengerCommunitiesSuite) TestImportCommunity() {
}
response, err = s.bob.CreateCommunityCategory(category)
s.Require().NoError(err)
community = response.Communities()[0]
privateKey, err := s.bob.ExportCommunity(community.ID())

View File

@ -714,7 +714,8 @@ func (db sqlitePersistence) AllMessagesFromChatsAndCommunitiesWhichMatchTerm(com
allFields := db.tableUserMessagesAllFieldsJoin()
finalQuery := fmt.Sprintf(`
finalQuery := fmt.Sprintf( // nolint: gosec
`
SELECT
%s,
substr('0000000000000000000000000000000000000000000000000000000000000000' || m1.clock_value, -64, 64) || m1.id as cursor

View File

@ -369,7 +369,7 @@ func NewMessenger(
pushNotificationClientConfig = &pushnotificationclient.Config{}
}
sqlitePersistence := NewSQLitePersistence(database)
sqlitePersistence := newSQLitePersistence(database)
// Overriding until we handle different identities
pushNotificationClientConfig.Identity = identity
pushNotificationClientConfig.Logger = logger

View File

@ -28,7 +28,7 @@ type sqlitePersistence struct {
db *sql.DB
}
func NewSQLitePersistence(db *sql.DB) *sqlitePersistence {
func newSQLitePersistence(db *sql.DB) *sqlitePersistence {
return &sqlitePersistence{common.NewRawMessagesPersistence(db), db}
}

View File

@ -29,7 +29,7 @@ func TestTableUserMessagesAllFieldsCount(t *testing.T) {
func TestSaveMessages(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
for i := 0; i < 10; i++ {
id := strconv.Itoa(i)
@ -45,7 +45,7 @@ func TestSaveMessages(t *testing.T) {
func TestMessagesByIDs(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
var ids []string
for i := 0; i < 10; i++ {
@ -63,7 +63,7 @@ func TestMessagesByIDs(t *testing.T) {
func TestMessageByID(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
id := "1"
err = insertMinimalMessage(p, id)
@ -77,7 +77,7 @@ func TestMessageByID(t *testing.T) {
func TestMessagesExist(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
err = insertMinimalMessage(p, "1")
require.NoError(t, err)
@ -101,7 +101,7 @@ func TestMessagesExist(t *testing.T) {
func TestMessageByChatID(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
chatID := testPublicChatID
count := 1000
pageSize := 50
@ -308,7 +308,7 @@ func TestPinMessageByChatID(t *testing.T) {
func TestMessageReplies(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
chatID := testPublicChatID
message1 := &common.Message{
ID: "id-1",
@ -363,7 +363,7 @@ func TestMessageReplies(t *testing.T) {
func TestMessageByChatIDWithTheSameClocks(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
chatID := testPublicChatID
clockValues := []uint64{10, 10, 9, 9, 9, 11, 12, 11, 100000, 6, 4, 5, 5, 5, 5}
count := len(clockValues)
@ -423,7 +423,7 @@ func TestMessageByChatIDWithTheSameClocks(t *testing.T) {
func TestDeleteMessageByID(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
id := "1"
err = insertMinimalMessage(p, id)
@ -443,7 +443,7 @@ func TestDeleteMessageByID(t *testing.T) {
func TestDeleteMessagesByChatID(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
err = insertMinimalMessage(p, "1")
require.NoError(t, err)
@ -468,7 +468,7 @@ func TestMarkMessageSeen(t *testing.T) {
chatID := "test-chat"
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
id := "1"
err = insertMinimalMessage(p, id)
@ -491,7 +491,7 @@ func TestMarkMessageSeen(t *testing.T) {
func TestUpdateMessageOutgoingStatus(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
id := "1"
err = insertMinimalMessage(p, id)
@ -508,7 +508,7 @@ func TestUpdateMessageOutgoingStatus(t *testing.T) {
func TestMessagesIDsByType(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
ids, err := p.RawMessagesIDsByType(protobuf.ApplicationMetadataMessage_CHAT_MESSAGE)
require.NoError(t, err)
@ -536,7 +536,7 @@ func TestMessagesIDsByType(t *testing.T) {
func TestExpiredMessagesIDs(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
ids, err := p.ExpiredMessagesIDs(messageResendMaxCount)
require.NoError(t, err)
@ -568,7 +568,7 @@ func TestExpiredMessagesIDs(t *testing.T) {
func TestPersistenceEmojiReactions(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
// reverse order as we use DESC
id1 := "1"
id2 := "2"
@ -695,7 +695,7 @@ func minimalRawMessage(id string, messageType protobuf.ApplicationMetadataMessag
func TestMessagesAudioDurationMsNull(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
id := "message-id-1"
err = insertMinimalMessage(p, id)
@ -716,7 +716,7 @@ func TestMessagesAudioDurationMsNull(t *testing.T) {
func TestSaveChat(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
chat := CreatePublicChat("test-chat", &testTimeSource{})
chat.LastMessage = &common.Message{}
@ -732,7 +732,7 @@ func TestSaveMentions(t *testing.T) {
chatID := testPublicChatID
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
key, err := crypto.GenerateKey()
require.NoError(t, err)
@ -760,7 +760,7 @@ func TestSaveMentions(t *testing.T) {
func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
chatID := "0xabcd1234"
hash := []byte{0x1}
@ -788,7 +788,7 @@ func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) {
func TestSaveContactIdentityImage(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
key, err := crypto.GenerateKey()
require.NoError(t, err)
@ -837,7 +837,7 @@ func TestSaveLinks(t *testing.T) {
chatID := testPublicChatID
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
require.NoError(t, err)
@ -863,7 +863,7 @@ func TestSaveLinks(t *testing.T) {
func TestHideMessage(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
chatID := testPublicChatID
message := &common.Message{
ID: "id-1",
@ -894,7 +894,7 @@ func TestHideMessage(t *testing.T) {
func TestDeactivatePublicChat(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
publicChatID := "public-chat-id"
var currentClockValue uint64 = 10
@ -962,7 +962,7 @@ func TestDeactivateOneToOneChat(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
var currentClockValue uint64 = 10
timesource := &testTimeSource{}
@ -1038,7 +1038,7 @@ func TestConfirmations(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
confirmation1 := &common.RawMessageConfirmation{
DataSyncID: dataSyncID1,
@ -1101,7 +1101,7 @@ func TestConfirmationsAtLeastOne(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
confirmation1 := &common.RawMessageConfirmation{
DataSyncID: dataSyncID1,
@ -1142,7 +1142,7 @@ func TestActivityCenterPersistence(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
chat := CreatePublicChat("test-chat", &testTimeSource{})
message := &common.Message{}
@ -1279,7 +1279,7 @@ func TestActivityCenterPersistence(t *testing.T) {
func TestSaveCommunityChat(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
identity := &protobuf.ChatIdentity{
DisplayName: "community-chat-name",
@ -1307,7 +1307,7 @@ func TestSaveCommunityChat(t *testing.T) {
func TestHasPendingNotificationsForChatSanityCheck(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := NewSQLitePersistence(db)
p := newSQLitePersistence(db)
result, err := p.HasPendingNotificationsForChat("test-chat-id")
require.NoError(t, err)

View File

@ -100,7 +100,8 @@ func TestCommunitiesMigrationNotDirty(t *testing.T) {
require.Error(t, err)
// Set dirty to false
_, err = db.Exec(`UPDATE ` + migrationsTable + ` SET dirty = 0`)
// Disabling linter as migrationsTable is controlled by us
_, err = db.Exec(`UPDATE ` + migrationsTable + ` SET dirty = 0`) // nolint: gosec
require.NoError(t, err)
// Version and dirty should be true and set to communities migration

View File

@ -15,7 +15,8 @@ func newSQLitePersistence(db *sql.DB, tableName string) *SqlitePersistence {
}
func (s *SqlitePersistence) Add(chatID string, key []byte) error {
statement := fmt.Sprintf("INSERT INTO %s(chat_id, key) VALUES(?, ?)", s.tableName)
// tableName controlled by us
statement := fmt.Sprintf("INSERT INTO %s(chat_id, key) VALUES(?, ?)", s.tableName) // nolint:gosec
stmt, err := s.db.Prepare(statement)
if err != nil {
return err
@ -29,7 +30,8 @@ func (s *SqlitePersistence) Add(chatID string, key []byte) error {
func (s *SqlitePersistence) All() (map[string][]byte, error) {
keys := make(map[string][]byte)
statement := fmt.Sprintf("SELECT chat_id, key FROM %s", s.tableName)
// tableName controlled by us
statement := fmt.Sprintf("SELECT chat_id, key FROM %s", s.tableName) // nolint: gosec
stmt, err := s.db.Prepare(statement)
if err != nil {

View File

@ -43,7 +43,7 @@ func NewAPI(rpcClient *rpc.Client, accountsManager *account.GethManager, rpcFilt
}
}
type uri struct {
type URI struct {
Scheme string
Host string
Path string
@ -450,7 +450,7 @@ func (api *API) SetPubKeyEstimate(ctx context.Context, chainID uint64, txArgs tr
return ethClient.EstimateGas(ctx, callMsg)
}
func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string) (*uri, error) {
func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string) (*URI, error) {
scheme := "https"
contentHash, err := api.ContentHash(ctx, chainID, username)
if err != nil {
@ -458,7 +458,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
}
if len(contentHash) == 0 {
return &uri{}, nil
return &URI{}, nil
}
data, codec, err := multicodec.RemoveCodec(contentHash)
@ -481,7 +481,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
return nil, errors.Wrap(err, "failed to obtain base36 representation")
}
host := str + ".ipfs.infura-ipfs.io/"
return &uri{scheme, host, ""}, nil
return &URI{scheme, host, ""}, nil
case "ipns-ns":
id, offset := binary.Uvarint(data)
if id == 0 {
@ -497,7 +497,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
return nil, err
}
return &uri{scheme, string(decodedMHash.Digest), ""}, nil
return &URI{scheme, string(decodedMHash.Digest), ""}, nil
case "swarm-ns":
id, offset := binary.Uvarint(data)
if id == 0 {
@ -512,7 +512,7 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string
return nil, err
}
path := "/bzz:/" + hex.EncodeToString(decodedMHash.Digest) + "/"
return &uri{scheme, "swarm-gateways.net", path}, nil
return &URI{scheme, "swarm-gateways.net", path}, nil
default:
return nil, fmt.Errorf("unknown codec name %s", codecName)
}

View File

@ -61,7 +61,7 @@ func (e *Envelope) rlpWithoutNonce() []byte {
// NewEnvelope wraps a Waku message with expiration and destination data
// included into an envelope for network forwarding.
func NewEnvelope(ttl uint32, topic TopicType, msg *sentMessage, now time.Time) *Envelope {
func NewEnvelope(ttl uint32, topic TopicType, msg *SentMessage, now time.Time) *Envelope {
env := Envelope{
Expiry: uint32(now.Add(time.Second * time.Duration(ttl)).Unix()),
TTL: ttl,

View File

@ -53,7 +53,7 @@ type MessageParams struct {
// SentMessage represents an end-user data packet to transmit through the
// Waku protocol. These are wrapped into Envelopes that need not be
// understood by intermediate nodes, just forwarded.
type sentMessage struct {
type SentMessage struct {
Raw []byte
}
@ -148,9 +148,9 @@ func (msg *ReceivedMessage) isAsymmetricEncryption() bool {
}
// NewSentMessage creates and initializes a non-signed, non-encrypted Waku message.
func NewSentMessage(params *MessageParams) (*sentMessage, error) {
func NewSentMessage(params *MessageParams) (*SentMessage, error) {
const payloadSizeFieldMaxSize = 4
msg := sentMessage{}
msg := SentMessage{}
msg.Raw = make([]byte, 1,
flagsLength+payloadSizeFieldMaxSize+len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit)
msg.Raw[0] = 0 // set all the flags to zero
@ -161,7 +161,7 @@ func NewSentMessage(params *MessageParams) (*sentMessage, error) {
}
// addPayloadSizeField appends the auxiliary field containing the size of payload
func (msg *sentMessage) addPayloadSizeField(payload []byte) {
func (msg *SentMessage) addPayloadSizeField(payload []byte) {
fieldSize := getSizeOfPayloadSizeField(payload)
field := make([]byte, 4)
binary.LittleEndian.PutUint32(field, uint32(len(payload)))
@ -181,7 +181,7 @@ func getSizeOfPayloadSizeField(payload []byte) int {
// appendPadding appends the padding specified in params.
// If no padding is provided in params, then random padding is generated.
func (msg *sentMessage) appendPadding(params *MessageParams) error {
func (msg *SentMessage) appendPadding(params *MessageParams) error {
if len(params.Padding) != 0 {
// padding data was provided by the Dapp, just use it as is
msg.Raw = append(msg.Raw, params.Padding...)
@ -208,7 +208,7 @@ func (msg *sentMessage) appendPadding(params *MessageParams) error {
// sign calculates and sets the cryptographic signature for the message,
// also setting the sign flag.
func (msg *sentMessage) sign(key *ecdsa.PrivateKey) error {
func (msg *SentMessage) sign(key *ecdsa.PrivateKey) error {
if IsMessageSigned(msg.Raw[0]) {
// this should not happen, but no reason to panic
log.Error("failed to sign the message: already signed")
@ -227,7 +227,7 @@ func (msg *sentMessage) sign(key *ecdsa.PrivateKey) error {
}
// encryptAsymmetric encrypts a message with a public key.
func (msg *sentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
func (msg *SentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
if !ValidatePublicKey(key) {
return errors.New("invalid public key provided for asymmetric encryption")
}
@ -240,7 +240,7 @@ func (msg *sentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
// encryptSymmetric encrypts a message with a topic key, using AES-GCM-256.
// nonce size should be 12 bytes (see cipher.gcmStandardNonceSize).
func (msg *sentMessage) encryptSymmetric(key []byte) (err error) {
func (msg *SentMessage) encryptSymmetric(key []byte) (err error) {
if !ValidateDataIntegrity(key, AESKeyLength) {
return errors.New("invalid key provided for symmetric encryption, size: " + strconv.Itoa(len(key)))
}
@ -262,7 +262,7 @@ func (msg *sentMessage) encryptSymmetric(key []byte) (err error) {
}
// Wrap bundles the message into an Envelope to transmit over the network.
func (msg *sentMessage) Wrap(options *MessageParams, now time.Time) (envelope *Envelope, err error) {
func (msg *SentMessage) Wrap(options *MessageParams, now time.Time) (envelope *Envelope, err error) {
if options.TTL == 0 {
options.TTL = DefaultTTL
}

View File

@ -444,7 +444,7 @@ func TestPaddingAppendedToSymMessagesWithSignature(t *testing.T) {
// Simulate a message with a payload just under 256 so that
// payload + flag + signature > 256. Check that the result
// is padded on the next 256 boundary.
msg := sentMessage{}
msg := SentMessage{}
const payloadSizeFieldMinSize = 1
msg.Raw = make([]byte, flagsLength+payloadSizeFieldMinSize+len(params.Payload))

View File

@ -212,7 +212,7 @@ func initializeBloomFilterMode(t *testing.T) {
},
}
go startServer(t, node.server) // nolint: staticcheck
go startServer(t, node.server) // nolint: staticcheck, govet
nodes[i] = &node
}
@ -232,7 +232,7 @@ func initializeBloomFilterMode(t *testing.T) {
func startServer(t *testing.T, s *p2p.Server) {
err := s.Start()
if err != nil {
t.Fatalf("failed to start the first server. err: %v", err)
t.Fatalf("failed to start the first server. err: %v", err) // nolint: staticcheck
}
atomic.AddInt64(&result.started, 1)

View File

@ -93,7 +93,8 @@ func CreateTable(db *sql.DB, tableName string) error {
}
func Clean(db *sql.DB, tableName string) error {
sqlStmt := fmt.Sprintf("DELETE FROM %s;", tableName)
// This is fully controlled by us
sqlStmt := fmt.Sprintf("DELETE FROM %s;", tableName) // nolint: gosec
_, err := db.Exec(sqlStmt)
if err != nil {
return err