Configure golangci-lint and fix warnings

This commit is contained in:
Jan Dittberner 2021-01-09 11:24:40 +01:00
parent ecd1846975
commit 2e467b3d2e
20 changed files with 915 additions and 559 deletions

View file

@ -13,12 +13,15 @@ import (
func ReceiveBytes(port io.Reader, count int, timeout time.Duration) ([]byte, error) {
readCh := make(chan []byte, 1)
errCh := make(chan error, 1)
go func() {
buffer := bytes.NewBuffer([]byte{})
for remainder := count; remainder > 0; {
data := make([]byte, remainder)
if readBytes, err := port.Read(data); err != nil {
errCh <- err
return
} else if readBytes > 0 {
buffer.Write(data[0:readBytes])
@ -26,6 +29,7 @@ func ReceiveBytes(port io.Reader, count int, timeout time.Duration) ([]byte, err
log.Tracef("%d bytes read, remaining %d", readBytes, remainder)
}
}
readCh <- buffer.Bytes()
close(readCh)
}()
@ -38,19 +42,24 @@ func ReceiveBytes(port io.Reader, count int, timeout time.Duration) ([]byte, err
return nil, err
case data := <-readCh:
log.Tracef("received %d bytes from channel", len(data))
if data == nil {
break
}
buffer.Write(data)
}
return buffer.Bytes(), nil
}
func SendBytes(port io.Writer, data []byte) error {
if bytesWritten, err := port.Write(data); err != nil {
return err
} else {
log.Tracef("wrote %d bytes", bytesWritten)
n, err := port.Write(data)
if err != nil {
return fmt.Errorf("could not send bytes: %w", err)
}
log.Tracef("wrote %d bytes", n)
return nil
}

View file

@ -19,7 +19,7 @@ type Action byte
const (
ActionNul = Action(0)
ActionSign = Action(1)
ActionRevoke = Action(2)
ActionRevoke = Action(2) // nolint:gomnd
)
func (a Action) String() string {
@ -35,10 +35,10 @@ func (a Action) String() string {
}
}
type CryptoSystemRootId byte
type CryptoSystemRootID byte
type CertificateProfileId byte
type CertificateProfileID byte
type MessageDigestAlgorithmId byte
type SignatureAlgorithmID byte
type CryptoSystemId byte
type CryptoSystemID byte