Skip to content

Commit 28278cf

Browse files
committed
Fix some utilities functions
1 parent 67412b9 commit 28278cf

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

flasher/certificate.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,35 @@ func calculateNameSha1(cert *x509.Certificate) (b []byte, err error) {
5151
return
5252
}
5353

54-
func convertTime(time time.Time) (b []byte, err error) {
54+
func convertTime(time time.Time) ([]byte, error) {
5555
asn1Bytes, err := asn1.Marshal(time)
5656
if err != nil {
5757
logrus.Error(err)
5858
return nil, err
5959
}
6060

61-
b = bytes.Repeat([]byte{0x00}, 20) // value must be zero bytes
62-
copy(b, asn1Bytes[2:]) // copy but drop the first two bytes
61+
b := bytes.Repeat([]byte{0x00}, 20) // value must be zero bytes
62+
copy(b, asn1Bytes[2:]) // copy but drop the first two bytes
6363

64-
return
64+
return b, err
6565
}
6666

6767
func modulusN(publicKey rsa.PublicKey) []byte {
6868
return publicKey.N.Bytes()
6969
}
7070

71-
func publicExponent(publicKey rsa.PublicKey) (b []byte) {
72-
b = make([]byte, 4)
71+
func publicExponent(publicKey rsa.PublicKey) []byte {
72+
b := make([]byte, 4)
7373
binary.BigEndian.PutUint32(b, uint32(publicKey.E))
7474
// strip leading zeros
7575
for b[0] == 0 {
7676
b = b[1:]
7777
}
78-
return
78+
return b
7979
}
8080

81-
func uint16ToBytes(i int) (b []byte) {
82-
b = make([]byte, 2)
81+
func uint16ToBytes(i int) []byte {
82+
b := make([]byte, 2)
8383
binary.LittleEndian.PutUint16(b, uint16(i))
84-
return
84+
return b
8585
}

indexes/firmwareindex/firmwareindex_test.go

+15-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
modify it under the terms of the GNU Lesser General Public
77
License as published by the Free Software Foundation; either
88
version 2.1 of the License, or (at your option) any later version.
9-
109
This library is distributed in the hope that it will be useful,
1110
but WITHOUT ANY WARRANTY; without even the implied warranty of
1211
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -38,41 +37,38 @@ func TestIndexParsing(t *testing.T) {
3837
require.NotEmpty(t, index)
3938
}
4039

41-
func TestGetLatestFirmwareURL(t *testing.T) {
40+
func TestGetLatestFirmware(t *testing.T) {
4241
indexFile := paths.New("testdata/module_firmware_index.json")
4342
t.Logf("testing with index: %s", indexFile)
4443
index, e := LoadIndexNoSign(indexFile)
4544
require.NoError(t, e)
4645
require.NotEmpty(t, index)
4746

48-
result, err := index.GetLatestFirmwareURL("arduino:samd:mkr1000")
49-
require.NoError(t, err)
50-
require.NotEmpty(t, result)
51-
require.Equal(t, "https://downloads.arduino.cc/arduino-fwuploader/firmwares/WINC1500/19.6.1/m2m_aio_3a0.bin", result)
47+
firmware := index.GetLatestFirmware("arduino:samd:mkr1000")
48+
require.Equal(t, firmware.Version, "19.6.1")
5249

53-
result, err = index.GetLatestFirmwareURL("arduino:samd:mkr1001")
54-
require.Error(t, err)
55-
require.Empty(t, result)
50+
firmware = index.GetLatestFirmware("arduino:samd:mkr1001")
51+
require.Nil(t, firmware)
5652
}
5753

58-
func TestGetFirmwareURL(t *testing.T) {
54+
func TestGetFirmware(t *testing.T) {
5955
indexFile := paths.New("testdata/module_firmware_index.json")
6056
t.Logf("testing with index: %s", indexFile)
6157
index, e := LoadIndexNoSign(indexFile)
6258
require.NoError(t, e)
6359
require.NotEmpty(t, index)
6460

65-
result, err := index.GetFirmwareURL("arduino:samd:mkr1000", "19.6.1")
66-
require.NoError(t, err)
67-
require.NotEmpty(t, result)
61+
firmware := index.GetFirmware("arduino:samd:mkr1000", "19.6.1")
62+
require.Equal(t, firmware.Version, "19.6.1")
6863

69-
result, err = index.GetFirmwareURL("arduino:samd:mkr1000", "0.0.0")
70-
require.Error(t, err)
71-
require.Empty(t, result)
64+
firmware = index.GetFirmware("arduino:samd:mkr1000", "19.5.2")
65+
require.Equal(t, firmware.Version, "19.5.2")
7266

73-
result, err = index.GetFirmwareURL("arduino:samd:mkr1001", "19.6.1")
74-
require.Error(t, err)
75-
require.Empty(t, result)
67+
firmware = index.GetFirmware("arduino:samd:mkr1000", "0.0.0")
68+
require.Nil(t, firmware)
69+
70+
firmware = index.GetFirmware("arduino:samd:mkr1001", "19.6.1")
71+
require.Nil(t, firmware)
7672
}
7773

7874
func TestGetLoaderSketchURL(t *testing.T) {

0 commit comments

Comments
 (0)