You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since a lot of the tpmdirect structs have private members, we should create a convenient way to compare two values without hassling with adding enough types into cmpopts.IgnoreUnexportedFields.
The text was updated successfully, but these errors were encountered:
This is unfortunately a large change, but I think it does a lot for the ergonomics of the TPMDirect API.
This change uses the new Go 1.18 generics to solve a few problems:
- We want people to be able to provide a flat `[]byte` or actual structure when instantiating TPM2Bs
- We want to avoid people directly manipulating pointer values in the TPMUs or having their TPMUs in an invalid state
- We want a nice Marshal and Unmarshal function (and later, to be able to make a nice Compare function, see #309 )
Generics to the rescue. Here's what this commit does:
- Add a new file called `marshalling.go` that handles a lot of the high level marshalling work. `reflect.go` is still the dirty reflection guts of the library
- Embed a new type called `marshalByReflection` into all the structs that can be marshalled by reflection, as a clear hint to the reflection library
- Add a new interface called `UnmarshallableWithHint` - most of the TPMU implement this, and the old `marshalUnion` and `unmarshalUnion` functions are gone now
- Bonus: I noticed using profiling that the `tags` function was allocating several orders of magnitude more memory than the rest of the library, so I rewrote it
- Introduced a generic TPM2B helper that is aliased by the concrete TPM2B types; there are constructors for instantiating TPM2B from data or structured contents.
- TPMU is public, with private fields. Introduced constructors for these with type constraints.
Fixes#307 and #292.
Since a lot of the tpmdirect structs have private members, we should create a convenient way to compare two values without hassling with adding enough types into
cmpopts.IgnoreUnexportedFields
.The text was updated successfully, but these errors were encountered: