From 1d235c82e67d54080a358e7610759a12e8b9a4db Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Tue, 4 Jun 2024 13:28:32 +0200 Subject: [PATCH] Fix linting issues --- tpm/debug/bin.go | 8 ++++---- tpm/debug/pcap.go | 2 +- tpm/debug/tap.go | 6 +++--- tpm/debug/text.go | 6 +++--- tpm/tpm.go | 16 ---------------- 5 files changed, 11 insertions(+), 27 deletions(-) diff --git a/tpm/debug/bin.go b/tpm/debug/bin.go index 2ef3a20a..88f64314 100644 --- a/tpm/debug/bin.go +++ b/tpm/debug/bin.go @@ -22,9 +22,9 @@ func NewBinTap(w io.Writer) Tap { return &binTap{w: w} } -func (w *binTap) Write(data []byte) (int, error) { - w.Lock() - defer w.Unlock() +func (t *binTap) Write(data []byte) (int, error) { + t.Lock() + defer t.Unlock() - return w.w.Write(data) + return t.w.Write(data) } diff --git a/tpm/debug/pcap.go b/tpm/debug/pcap.go index 82728901..2587a2f9 100644 --- a/tpm/debug/pcap.go +++ b/tpm/debug/pcap.go @@ -94,7 +94,7 @@ const snapLen = uint32(65536) var once sync.Once var headerWriteError error -func write(w *pcapgo.Writer, data []byte, in bool, inSeq uint32, outSeq uint32) error { +func write(w *pcapgo.Writer, data []byte, in bool, inSeq, outSeq uint32) error { var tcpLayer = &layers.TCP{Window: 16} if in { tcpLayer.SrcPort = layers.TCPPort(2321) diff --git a/tpm/debug/tap.go b/tpm/debug/tap.go index 021a604d..276af06b 100644 --- a/tpm/debug/tap.go +++ b/tpm/debug/tap.go @@ -14,15 +14,15 @@ type tap struct { out io.Writer } -func (t tap) Rx() io.Writer { +func (t *tap) Rx() io.Writer { return t.in } -func (t tap) Tx() io.Writer { +func (t *tap) Tx() io.Writer { return t.out } -func NewTap(rx io.Writer, tx io.Writer) Tap { +func NewTap(rx, tx io.Writer) Tap { return &tap{ in: rx, out: tx, diff --git a/tpm/debug/text.go b/tpm/debug/text.go index f3e34f67..60884411 100644 --- a/tpm/debug/text.go +++ b/tpm/debug/text.go @@ -19,8 +19,8 @@ type wrapper struct { func (w *wrapper) Write(data []byte) (int, error) { if w.in { - return w.w.Write([]byte(fmt.Sprintf("<- %x\n", data))) - } else { - return w.w.Write([]byte(fmt.Sprintf("-> %x\n", data))) + return fmt.Fprintf(w.w, "<- %x\n", data) } + + return fmt.Fprintf(w.w, "-> %x\n", data) } diff --git a/tpm/tpm.go b/tpm/tpm.go index b2598d4e..aecd95ca 100644 --- a/tpm/tpm.go +++ b/tpm/tpm.go @@ -318,22 +318,6 @@ func (t *TPM) initializeCommandChannel() error { } } - // if t.tap != nil && runtime.GOOS != "windows" { - // if t.commandChannel == nil { - // rwc, err := open.TPM(t.deviceName) - // if err != nil { - // return fmt.Errorf("failed opening TPM: %w", err) - // } - // //cc := interceptor.RWCFromTap(t.tap).Wrap(rwc) - // //at = inject.Inject(interceptor.RWCFromTap(t.tap).Wrap(rwc)) // TODO: can we circumvent inject? - // //t.attestConfig.CommandChannel = cc - // cc := &linuxCmdChannel{rwc} - // t.tappedChannel = interceptor.CommandChannelFromTap(t.tap).Wrap(cc) - // } else { - // t.tappedChannel = interceptor.CommandChannelFromTap(t.tap).Wrap(t.commandChannel) - // } - // } - // update `attestConfig` with the command channel, so that it is used whenever // attestation operations are being performed. Note that the command channel can // still be nil. It simply won't be used (wrapped) by `go-attestation` in that case.