Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Jun 4, 2024
1 parent f6f961f commit bd806d8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
8 changes: 4 additions & 4 deletions tpm/debug/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 5 additions & 5 deletions tpm/debug/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ var decodeOptions = gopacket.DecodeOptions{
const snapLen = uint32(65536)

var once sync.Once
var headerWriteError error
var errHeaderWrite 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)
Expand Down Expand Up @@ -126,11 +126,11 @@ func write(w *pcapgo.Writer, data []byte, in bool, inSeq uint32, outSeq uint32)
once.Do(func() {
// TODO: do once on the very first write to the output; if it's a file, check there's no pcap header yet
if err := w.WriteFileHeader(snapLen, layers.LinkTypeEthernet); err != nil {
headerWriteError = err
errHeaderWrite = err
}
})
if headerWriteError != nil {
return fmt.Errorf("failed writing pcap header: %w", headerWriteError)
if errHeaderWrite != nil {
return fmt.Errorf("failed writing pcap header: %w", errHeaderWrite)
}

ci := p.Metadata().CaptureInfo
Expand Down
6 changes: 3 additions & 3 deletions tpm/debug/tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tpm/debug/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
)

func NewTextTap(reads io.Writer, writes io.Writer) Tap {
func NewTextTap(reads, writes io.Writer) Tap {
return &tap{
in: &wrapper{reads, true},
out: &wrapper{writes, false},
Expand All @@ -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)
}
16 changes: 0 additions & 16 deletions tpm/tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit bd806d8

Please sign in to comment.