File: close_others.go

package info (click to toggle)
golang-github-smallstep-crypto 0.57.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,284 kB
  • sloc: sh: 53; makefile: 36
file content (27 lines) | stat: -rw-r--r-- 655 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//go:build !windows
// +build !windows

package closer

import (
	"io"

	"github.com/google/go-tpm/tpmutil"
	"github.com/smallstep/go-attestation/attest"

	"go.step.sm/crypto/tpm/internal/socket"
)

func closeRWC(rwc io.ReadWriteCloser) error {
	if _, ok := rwc.(*tpmutil.EmulatorReadWriteCloser); ok {
		return nil // EmulatorReadWriteCloser automatically closes on every write/read cycle
	}
	return rwc.Close()
}

func attestTPM(t *attest.TPM, c *attest.OpenConfig) error {
	if _, ok := c.CommandChannel.(*socket.CommandChannelWithoutMeasurementLog); ok {
		return nil // backed by tpmutil.EmulatorReadWriteCloser; already closed
	}
	return t.Close()
}