Skip to content

Commit dbbd613

Browse files
authored
2.5 exec go fix (#5407)
Signed-off-by: Fedor Partanskiy <fredprtnsk@gmail.com>
1 parent 16a1c59 commit dbbd613

File tree

488 files changed

+2088
-2444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

488 files changed

+2088
-2444
lines changed

bccsp/bccsp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ type SignerOpts interface {
8080
}
8181

8282
// EncrypterOpts contains options for encrypting with a CSP.
83-
type EncrypterOpts interface{}
83+
type EncrypterOpts any
8484

8585
// DecrypterOpts contains options for decrypting with a CSP.
86-
type DecrypterOpts interface{}
86+
type DecrypterOpts any
8787

8888
// BCCSP is the blockchain cryptographic service provider that offers
8989
// the implementation of cryptographic standards and algorithms.
@@ -98,7 +98,7 @@ type BCCSP interface {
9898

9999
// KeyImport imports a key from its raw representation using opts.
100100
// The opts argument should be appropriate for the primitive used.
101-
KeyImport(raw interface{}, opts KeyImportOpts) (k Key, err error)
101+
KeyImport(raw any, opts KeyImportOpts) (k Key, err error)
102102

103103
// GetKey returns the key this CSP associates to
104104
// the Subject Key Identifier ski.

bccsp/bccsp_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ func TestHMAC(t *testing.T) {
116116

117117
func TestKeyGenOpts(t *testing.T) {
118118
expectedAlgorithms := map[reflect.Type]string{
119-
reflect.TypeOf(&HMACImportKeyOpts{}): "HMAC",
120-
reflect.TypeOf(&X509PublicKeyImportOpts{}): "X509Certificate",
121-
reflect.TypeOf(&AES256ImportKeyOpts{}): "AES",
119+
reflect.TypeFor[*HMACImportKeyOpts](): "HMAC",
120+
reflect.TypeFor[*X509PublicKeyImportOpts](): "X509Certificate",
121+
reflect.TypeFor[*AES256ImportKeyOpts](): "AES",
122122
}
123123
test := func(ephemeral bool) {
124124
for _, opts := range []KeyGenOpts{

bccsp/factory/nopkcs11.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func StringToKeyIds() mapstructure.DecodeHookFunc {
9090
return func(
9191
f reflect.Type,
9292
t reflect.Type,
93-
data interface{}) (interface{}, error) {
93+
data any) (any, error) {
9494
return data, nil
9595
}
9696
}

bccsp/mocks/mocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (*MockBCCSP) KeyDeriv(k bccsp.Key, opts bccsp.KeyDerivOpts) (bccsp.Key, err
5757
panic("Not yet implemented")
5858
}
5959

60-
func (m *MockBCCSP) KeyImport(raw interface{}, opts bccsp.KeyImportOpts) (bccsp.Key, error) {
60+
func (m *MockBCCSP) KeyImport(raw any, opts bccsp.KeyImportOpts) (bccsp.Key, error) {
6161
return m.KeyImportValue, m.KeyImportErr
6262
}
6363

bccsp/pkcs11/pkcs11_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"crypto/rand"
1414
"crypto/sha256"
1515
"encoding/asn1"
16-
"io/ioutil"
1716
"os"
1817
"strconv"
1918
"strings"
@@ -41,7 +40,7 @@ func defaultOptions() PKCS11Opts {
4140
}
4241

4342
func newKeyStore(t *testing.T) (bccsp.KeyStore, func()) {
44-
tempDir, err := ioutil.TempDir("", "pkcs11_ks")
43+
tempDir, err := os.MkdirTemp("", "pkcs11_ks")
4544
require.NoError(t, err)
4645
ks, err := sw.NewFileBasedKeyStore(nil, tempDir, false)
4746
require.NoError(t, err)

bccsp/signer/signer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
type bccspCryptoSigner struct {
2020
csp bccsp.BCCSP
2121
key bccsp.Key
22-
pk interface{}
22+
pk any
2323
}
2424

2525
// New returns a new BCCSP-based crypto.Signer

bccsp/sw/aes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func pkcs7UnPadding(src []byte) ([]byte, error) {
6262
}
6363

6464
pad := src[len(src)-unpadding:]
65-
for i := 0; i < unpadding; i++ {
65+
for i := range unpadding {
6666
if pad[i] != byte(unpadding) {
6767
return nil, errors.New("Invalid pkcs7 padding (pad[i] != unpadding)")
6868
}

bccsp/sw/enc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestEncrypt(t *testing.T) {
3636
expectedErr := errors.New("no error")
3737

3838
encryptors := make(map[reflect.Type]Encryptor)
39-
encryptors[reflect.TypeOf(&mocks2.MockKey{})] = &mocks.Encryptor{
39+
encryptors[reflect.TypeFor[*mocks2.MockKey]()] = &mocks.Encryptor{
4040
KeyArg: expectedKey,
4141
PlaintextArg: expectedPlaintext,
4242
OptsArg: expectedOpts,

bccsp/sw/fileks.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"errors"
1414
"fmt"
1515
"io"
16-
"io/ioutil"
1716
"os"
1817
"path/filepath"
1918
"strings"
@@ -200,17 +199,22 @@ func (ks *fileBasedKeyStore) StoreKey(k bccsp.Key) (err error) {
200199
}
201200

202201
func (ks *fileBasedKeyStore) searchKeystoreForSKI(ski []byte) (k bccsp.Key, err error) {
203-
files, _ := ioutil.ReadDir(ks.path)
202+
files, _ := os.ReadDir(ks.path)
204203
for _, f := range files {
205204
if f.IsDir() {
206205
continue
207206
}
208207

209-
if f.Size() > (1 << 16) { // 64k, somewhat arbitrary limit, considering even large keys
208+
info, err := f.Info()
209+
if err != nil {
210+
continue
211+
}
212+
213+
if info.Size() > (1 << 16) { // 64k, somewhat arbitrary limit, considering even large keys
210214
continue
211215
}
212216

213-
raw, err := ioutil.ReadFile(filepath.Join(ks.path, f.Name()))
217+
raw, err := os.ReadFile(filepath.Join(ks.path, f.Name()))
214218
if err != nil {
215219
continue
216220
}
@@ -237,7 +241,7 @@ func (ks *fileBasedKeyStore) searchKeystoreForSKI(ski []byte) (k bccsp.Key, err
237241
}
238242

239243
func (ks *fileBasedKeyStore) getSuffix(alias string) string {
240-
files, _ := ioutil.ReadDir(ks.path)
244+
files, _ := os.ReadDir(ks.path)
241245
for _, f := range files {
242246
if strings.HasPrefix(f.Name(), alias) {
243247
if strings.HasSuffix(f.Name(), "sk") {
@@ -255,14 +259,14 @@ func (ks *fileBasedKeyStore) getSuffix(alias string) string {
255259
return ""
256260
}
257261

258-
func (ks *fileBasedKeyStore) storePrivateKey(alias string, privateKey interface{}) error {
262+
func (ks *fileBasedKeyStore) storePrivateKey(alias string, privateKey any) error {
259263
rawKey, err := privateKeyToPEM(privateKey, ks.pwd)
260264
if err != nil {
261265
logger.Errorf("Failed converting private key to PEM [%s]: [%s]", alias, err)
262266
return err
263267
}
264268

265-
err = ioutil.WriteFile(ks.getPathForAlias(alias, "sk"), rawKey, 0o600)
269+
err = os.WriteFile(ks.getPathForAlias(alias, "sk"), rawKey, 0o600)
266270
if err != nil {
267271
logger.Errorf("Failed storing private key [%s]: [%s]", alias, err)
268272
return err
@@ -271,14 +275,14 @@ func (ks *fileBasedKeyStore) storePrivateKey(alias string, privateKey interface{
271275
return nil
272276
}
273277

274-
func (ks *fileBasedKeyStore) storePublicKey(alias string, publicKey interface{}) error {
278+
func (ks *fileBasedKeyStore) storePublicKey(alias string, publicKey any) error {
275279
rawKey, err := publicKeyToPEM(publicKey, ks.pwd)
276280
if err != nil {
277281
logger.Errorf("Failed converting public key to PEM [%s]: [%s]", alias, err)
278282
return err
279283
}
280284

281-
err = ioutil.WriteFile(ks.getPathForAlias(alias, "pk"), rawKey, 0o600)
285+
err = os.WriteFile(ks.getPathForAlias(alias, "pk"), rawKey, 0o600)
282286
if err != nil {
283287
logger.Errorf("Failed storing private key [%s]: [%s]", alias, err)
284288
return err
@@ -294,7 +298,7 @@ func (ks *fileBasedKeyStore) storeKey(alias string, key []byte) error {
294298
return err
295299
}
296300

297-
err = ioutil.WriteFile(ks.getPathForAlias(alias, "key"), pem, 0o600)
301+
err = os.WriteFile(ks.getPathForAlias(alias, "key"), pem, 0o600)
298302
if err != nil {
299303
logger.Errorf("Failed storing key [%s]: [%s]", alias, err)
300304
return err
@@ -303,11 +307,11 @@ func (ks *fileBasedKeyStore) storeKey(alias string, key []byte) error {
303307
return nil
304308
}
305309

306-
func (ks *fileBasedKeyStore) loadPrivateKey(alias string) (interface{}, error) {
310+
func (ks *fileBasedKeyStore) loadPrivateKey(alias string) (any, error) {
307311
path := ks.getPathForAlias(alias, "sk")
308312
logger.Debugf("Loading private key [%s] at [%s]...", alias, path)
309313

310-
raw, err := ioutil.ReadFile(path)
314+
raw, err := os.ReadFile(path)
311315
if err != nil {
312316
logger.Errorf("Failed loading private key [%s]: [%s].", alias, err.Error())
313317

@@ -324,11 +328,11 @@ func (ks *fileBasedKeyStore) loadPrivateKey(alias string) (interface{}, error) {
324328
return privateKey, nil
325329
}
326330

327-
func (ks *fileBasedKeyStore) loadPublicKey(alias string) (interface{}, error) {
331+
func (ks *fileBasedKeyStore) loadPublicKey(alias string) (any, error) {
328332
path := ks.getPathForAlias(alias, "pk")
329333
logger.Debugf("Loading public key [%s] at [%s]...", alias, path)
330334

331-
raw, err := ioutil.ReadFile(path)
335+
raw, err := os.ReadFile(path)
332336
if err != nil {
333337
logger.Errorf("Failed loading public key [%s]: [%s].", alias, err.Error())
334338

@@ -349,7 +353,7 @@ func (ks *fileBasedKeyStore) loadKey(alias string) ([]byte, error) {
349353
path := ks.getPathForAlias(alias, "key")
350354
logger.Debugf("Loading key [%s] at [%s]...", alias, path)
351355

352-
pem, err := ioutil.ReadFile(path)
356+
pem, err := os.ReadFile(path)
353357
if err != nil {
354358
logger.Errorf("Failed loading key [%s]: [%s].", alias, err.Error())
355359

bccsp/sw/fileks_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"crypto/elliptic"
1212
"crypto/rand"
1313
"fmt"
14-
"io/ioutil"
1514
"os"
1615
"path/filepath"
1716
"testing"
@@ -22,7 +21,7 @@ import (
2221
func TestInvalidStoreKey(t *testing.T) {
2322
t.Parallel()
2423

25-
tempDir, err := ioutil.TempDir("", "bccspks")
24+
tempDir, err := os.MkdirTemp("", "bccspks")
2625
require.NoError(t, err)
2726
defer os.RemoveAll(tempDir)
2827

@@ -58,7 +57,7 @@ func TestInvalidStoreKey(t *testing.T) {
5857
}
5958

6059
func TestBigKeyFile(t *testing.T) {
61-
ksPath, err := ioutil.TempDir("", "bccspks")
60+
ksPath, err := os.MkdirTemp("", "bccspks")
6261
require.NoError(t, err)
6362
defer os.RemoveAll(ksPath)
6463

@@ -81,23 +80,23 @@ func TestBigKeyFile(t *testing.T) {
8180
}
8281
copy(bigBuff, rawKey)
8382

84-
//>64k, so that total file size will be too big
85-
ioutil.WriteFile(filepath.Join(ksPath, "bigfile.pem"), bigBuff, 0o666)
83+
// >64k, so that total file size will be too big
84+
os.WriteFile(filepath.Join(ksPath, "bigfile.pem"), bigBuff, 0o666)
8685

8786
_, err = ks.GetKey(ski)
8887
require.Error(t, err)
8988
expected := fmt.Sprintf("key with SKI %x not found in %s", ski, ksPath)
9089
require.EqualError(t, err, expected)
9190

9291
// 1k, so that the key would be found
93-
ioutil.WriteFile(filepath.Join(ksPath, "smallerfile.pem"), bigBuff[0:1<<10], 0o666)
92+
os.WriteFile(filepath.Join(ksPath, "smallerfile.pem"), bigBuff[0:1<<10], 0o666)
9493

9594
_, err = ks.GetKey(ski)
9695
require.NoError(t, err)
9796
}
9897

9998
func TestReInitKeyStore(t *testing.T) {
100-
ksPath, err := ioutil.TempDir("", "bccspks")
99+
ksPath, err := os.MkdirTemp("", "bccspks")
101100
require.NoError(t, err)
102101
defer os.RemoveAll(ksPath)
103102

0 commit comments

Comments
 (0)