Skip to content

Commit

Permalink
WIP: pkg/tpm/structures: fix TPM 2.0 digests marshalling - AHA!!
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Maslowski <info@orangecms.org>
  • Loading branch information
orangecms committed Aug 15, 2021
1 parent 687de8e commit ef2ec2c
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions pkg/tpm/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,12 @@ type THA struct {
digest IHA
}

func (t *THA) MarshalJSON() ([]byte, error) {
m := make(map[string]string)
m["algorithm"] = HashAlgoToName[t.hashAlg]
m["digest"] = string(t.digest.hash)
return json.Marshal(m)
}

// LDigestValues is a TPM2 structure
type LDigestValues struct {
count uint32
digests []THA
}

func (d *LDigestValues) MarshalJSON() ([]byte, error) {
return json.Marshal(d.digests)
/*
var m []string
for _, digest := range d.digests {
j, err := json.Marshal(digest)
if err != nil {
return nil, err
}
m = append(m, string(j))
}
return json.Marshal(m)
*/
}

// TcgEfiSpecIDEventAlgorithmSize is a TPM2 structure
type TcgEfiSpecIDEventAlgorithmSize struct {
algorithID uint16
Expand Down Expand Up @@ -160,11 +138,14 @@ type MDigest struct {
digest string `json:"digest"`
}

type JSONThis interface {
String() string
MDigest() MDigest
func (md *MDigest) MarshalJSON() ([]byte, error) {
m := make(map[string]string)
m["algorithm"] = md.algorithm
m["digest"] = md.digest
return json.Marshal(m)
}

// This could be a ton nicer, probably
func (e *TcgPcrEvent2) MarshalJSON() ([]byte, error) {
m := make(map[string]json.RawMessage)
// this works
Expand All @@ -186,10 +167,9 @@ func (e *TcgPcrEvent2) MarshalJSON() ([]byte, error) {
d := &e.digests.digests[i]
ds = append(ds, MDigest{
algorithm: HashAlgoToName[d.hashAlg],
digest: string(d.digest.hash),
digest: fmt.Sprintf("%x", d.digest.hash),
})
}
// this is left with empty objects, i.e., [{}, {}] - wat?
dsj, err := json.Marshal(ds)
if err != nil {
return nil, err
Expand Down

0 comments on commit ef2ec2c

Please sign in to comment.