From 75df78ad39eee7e5043e15407bb1cdd37ff335d6 Mon Sep 17 00:00:00 2001 From: Alexandra Pirvulescu Date: Wed, 12 Oct 2022 16:02:05 +0300 Subject: [PATCH] Add ReadPCRsRaw() to tpm2 The ReadPCRsRaw() function is similar to ReadPCRs, but it returns the raw output of TPM2_PCR_Read() without decoding it to a map[int][]byte. Signed-off-by: Alexandra Pirvulescu --- tpm2/tpm2.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tpm2/tpm2.go b/tpm2/tpm2.go index 0f2d32c7..8460caef 100644 --- a/tpm2/tpm2.go +++ b/tpm2/tpm2.go @@ -183,6 +183,17 @@ func decodeReadPCRs(in []byte) (map[int][]byte, error) { // This is only a wrapper over TPM2_PCR_Read() call, thus can only return // at most 8 PCRs digests. func ReadPCRs(rw io.ReadWriter, sel PCRSelection) (map[int][]byte, error) { + resp, err := ReadPCRsRaw(rw, sel) + if err != nil { + return nil, err + } + + return decodeReadPCRs(resp) +} + +// ReadPCRsRaw is very similar to ReadPCRs, except that it will return +// the raw response of TPM2_PCR_Read() in a byte array without decoding. +func ReadPCRsRaw(rw io.ReadWriter, sel PCRSelection) ([]byte, error) { Cmd, err := encodeTPMLPCRSelection(sel) if err != nil { return nil, err @@ -192,7 +203,7 @@ func ReadPCRs(rw io.ReadWriter, sel PCRSelection) (map[int][]byte, error) { return nil, err } - return decodeReadPCRs(resp) + return resp, nil } func decodeReadClock(in []byte) (uint64, uint64, error) {