@@ -35,7 +35,7 @@ const IDLen = 32
3535// ID represents a channelID.
3636type ID = [IDLen ]byte
3737
38- // IDMap is a map of IDs with keys corresponding to backendIDs
38+ // IDMap is a map of IDs with keys corresponding to backendIDs.
3939type IDMap map [wallet.BackendID ]ID
4040
4141// MaxNonceLen is the maximum byte count of a nonce.
@@ -75,12 +75,12 @@ func EqualIDs(a, b map[wallet.BackendID]ID) bool {
7575}
7676
7777func (ids IDMap ) Encode (w stdio.Writer ) error {
78- length := int32 (len (ids ))
78+ length := int32 (len (ids )) //nolint:gosec
7979 if err := perunio .Encode (w , length ); err != nil {
8080 return errors .WithMessage (err , "encoding map length" )
8181 }
8282 for i , id := range ids {
83- if err := perunio .Encode (w , int32 (i )); err != nil {
83+ if err := perunio .Encode (w , int32 (i )); err != nil { //nolint:gosec
8484 return errors .WithMessage (err , "encoding map index" )
8585 }
8686 if err := perunio .Encode (w , id ); err != nil {
@@ -112,14 +112,11 @@ func (ids *IDMap) Decode(r stdio.Reader) error {
112112
113113func IDKey (ids IDMap ) string {
114114 var buff strings.Builder
115- // Encode the number of elements in the map first.
116- length := int32 (len (ids )) // Using int32 to encode the length
117- err := binary .Write (& buff , binary .BigEndian , length )
115+ length := int32 (len (ids )) //nolint:gosec
116+ err := binary .Write (& buff , binary .BigEndian , length ) //nolint:gosec
118117 if err != nil {
119118 log .Panic ("could not encode map length in Key: " , err )
120-
121119 }
122- // Iterate over the map and encode each key-value pair.
123120 sortedKeys , sortedIDs := sortIDMap (ids )
124121 for i , id := range sortedIDs {
125122 if err := binary .Write (& buff , binary .BigEndian , int32 (sortedKeys [i ])); err != nil {
@@ -133,9 +130,9 @@ func IDKey(ids IDMap) string {
133130}
134131
135132func sortIDMap (ids IDMap ) ([]wallet.BackendID , []ID ) {
136- var indexes []int
133+ indexes := make ( []int , len ( ids ))
137134 for i := range ids {
138- indexes = append ( indexes , int (i ) )
135+ indexes [ i ] = int (i )
139136 }
140137 sort .Ints (indexes )
141138 sortedIndexes := make ([]wallet.BackendID , len (indexes ))
@@ -279,12 +276,12 @@ func NewParamsUnsafe(challengeDuration uint64, parts []map[wallet.BackendID]wall
279276 return p
280277}
281278
282- // CloneAddress returns a clone of an Address using its binary marshaling
279+ // CloneAddresses returns a clone of an Address using its binary marshaling
283280// implementation. It panics if an error occurs during binary (un)marshaling.
284281func CloneAddresses (as []map [wallet.BackendID ]wallet.Address ) []map [wallet.BackendID ]wallet.Address {
285- var cloneMap []map [wallet.BackendID ]wallet.Address
286- for _ , a := range as {
287- cloneMap = append ( cloneMap , wallet .CloneAddressesMap (a ) )
282+ cloneMap := make ( []map [wallet.BackendID ]wallet.Address , len ( as ))
283+ for i , a := range as {
284+ cloneMap [ i ] = wallet .CloneAddressesMap (a )
288285 }
289286 return cloneMap
290287}
@@ -304,7 +301,6 @@ func (p *Params) Clone() *Params {
304301
305302// Encode uses the pkg/io module to serialize a params instance.
306303func (p * Params ) Encode (w stdio.Writer ) error {
307-
308304 return perunio .Encode (w ,
309305 p .ChallengeDuration ,
310306 wallet.AddressMapArray {Addr : p .Parts },
0 commit comments