func OpenTPM(path string) (io.ReadWriteCloser, error) {
	var rwc io.ReadWriteCloser
	fi, err := os.Stat(path)
	if err != nil {
		return nil, err
	}
	if fi.Mode()&os.ModeDevice != 0 {
		var f *os.File
		f, err = os.OpenFile(path, os.O_RDWR, 0600)
		if err != nil {
			return nil, err
		}
		rwc = io.ReadWriteCloser(f)
	} else if fi.Mode()&os.ModeSocket != 0 {
		rwc = NewEmulatorReadWriteCloser(path)
	} else {
		return nil, fmt.Errorf("unsupported TPM file mode %s", fi.Mode().String())
	}
	return rwc, nil
}
OpenTPM opens a channel to the TPM at the given path. If the file is a
device, then it treats it like a normal TPM device, and if the file is a
Unix domain socket, then it opens a connection to the socket.
package tpmutil
import (
	"fmt"
	"io"
	"net"
	"os"
)