Make KeyAndSignature optional in PrettyString

Signed-off-by: Dmitrii Okunev <xaionaro@fb.com>
This commit is contained in:
Dmitrii Okunev 2021-02-22 13:42:44 +00:00
parent a554793219
commit 48544069a1
No known key found for this signature in database
GPG Key ID: B49BACEF2B95D555
37 changed files with 227 additions and 197 deletions

View File

@ -13,7 +13,7 @@ jobs:
- checkout
- run: sudo apt install -y golint
# specify any bash command here prefixed with `run: `
- run: GO111MODULE=off go get github.com/tjfoc/gmsm/sm2 && go run ./pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen -check ./pkg/intel/metadata/manifest ./pkg/intel/metadata/manifest/bootpolicy ./pkg/intel/metadata/manifest/key
- run: GO111MODULE=off go get github.com/tjfoc/gmsm/sm2 && go run ./pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen -check ./pkg/intel/metadata/manifest ./pkg/intel/metadata/manifest/bootpolicy ./pkg/intel/metadata/manifest/key
- run: if [ "$(gofmt -l .)" != "" ]; then exit 1; fi
- run: golint -set_exit_status ./pkg/test
- run: golint -set_exit_status ./pkg/tools

1
go.mod
View File

@ -29,5 +29,4 @@ require (
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b // indirect
golang.org/x/text v0.3.3 // indirect
)

View File

@ -9,7 +9,7 @@ To generalize all the logic related to Boot Policy Manifest and Key Manifest
we use code generation. Therefore it is enough to create structure declarations
and run command from this directory:
```
go run ./internal/manifestcodegen/cmd/manifestcodegen/ . ./bootpolicy ./key
go run ./common/manifestcodegen/cmd/manifestcodegen/ . ./bootpolicy ./key
```
It will performe the code autogeneration in directories:
@ -19,18 +19,18 @@ It will performe the code autogeneration in directories:
To check if the files are in the up-to-date state, one may add option `-check`:
```
go run ./internal/manifestcodegen/cmd/manifestcodegen/ -check . ./bootpolicy ./key
go run ./common/manifestcodegen/cmd/manifestcodegen/ -check . ./bootpolicy ./key
```
Or if it is required to debug/trace the behavior of autogenerated code, one
may add option `-trace`:
```
go run ./internal/manifestcodegen/cmd/manifestcodegen/ -trace . ./bootpolicy ./key
go run ./common/manifestcodegen/cmd/manifestcodegen/ -trace . ./bootpolicy ./key
```
In this case the code will write a verbose log into stdout.
If you need to edit the template, please edit file: `./internal/manifestcodegen/cmd/manifestcodegen/template_methods.tpl.go`.
If you need to edit the template, please edit file: `./common/manifestcodegen/cmd/manifestcodegen/template_methods.tpl.go`.
# Field tags

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -175,7 +175,7 @@ func (s *Reserved) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *Reserved) PrettyString(depth uint, withHeader bool) string {
func (s *Reserved) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Reserved", s))
@ -184,9 +184,9 @@ func (s *Reserved) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved Data", "", &s.ReservedData))
lines = append(lines, pretty.SubValue(depth+1, "Reserved Data", "", &s.ReservedData, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -326,7 +326,7 @@ func (s *BPMH) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *BPMH) PrettyString(depth uint, withHeader bool) string {
func (s *BPMH) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "BPMH", s))
@ -335,19 +335,19 @@ func (s *BPMH) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Key Signature Offset", "", &s.KeySignatureOffset))
lines = append(lines, pretty.SubValue(depth+1, "Key Signature Offset", "", &s.KeySignatureOffset, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "BPM Revision", "", &s.BPMRevision))
lines = append(lines, pretty.SubValue(depth+1, "BPM Revision", "", &s.BPMRevision, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "BPM SVN", "", &s.BPMSVN))
lines = append(lines, pretty.SubValue(depth+1, "BPM SVN", "", &s.BPMSVN, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "ACM SVN Auth", "", &s.ACMSVNAuth))
lines = append(lines, pretty.SubValue(depth+1, "ACM SVN Auth", "", &s.ACMSVNAuth, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "NEM Data Stack", "", &s.NEMDataStack))
lines = append(lines, pretty.SubValue(depth+1, "NEM Data Stack", "", &s.NEMDataStack, opts...)...)
if depth < 2 {
lines = append(lines, "")
}
@ -355,11 +355,11 @@ func (s *BPMH) PrettyString(depth uint, withHeader bool) string {
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags Size4K) PrettyString(depth uint, withHeader bool) string {
func (flags Size4K) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Size 4 K", flags))
}
lines = append(lines, pretty.SubValue(depth+1, "In Bytes", "", flags.InBytes()))
lines = append(lines, pretty.SubValue(depth+1, "In Bytes", "", flags.InBytes(), opts...)...)
return strings.Join(lines, "\n")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -410,7 +410,7 @@ func (s *Manifest) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *Manifest) PrettyString(depth uint, withHeader bool) string {
func (s *Manifest) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Boot Policy Manifest", s))
@ -419,7 +419,7 @@ func (s *Manifest) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is element
lines = append(lines, pretty.SubValue(depth+1, "BPMH: Header", "", &s.BPMH))
lines = append(lines, pretty.SubValue(depth+1, "BPMH: Header", "", &s.BPMH, opts...)...)
// ManifestFieldType is elementList
lines = append(lines, pretty.Header(depth+1, fmt.Sprintf("SE: Array of \"IBB Segments Element\" of length %d", len(s.SE)), s.SE))
for i := 0; i < len(s.SE); i++ {
@ -429,15 +429,15 @@ func (s *Manifest) PrettyString(depth uint, withHeader bool) string {
lines = append(lines, "")
}
// ManifestFieldType is element
lines = append(lines, pretty.SubValue(depth+1, "TXTE", "", s.TXTE))
lines = append(lines, pretty.SubValue(depth+1, "TXTE", "", s.TXTE, opts...)...)
// ManifestFieldType is element
lines = append(lines, pretty.SubValue(depth+1, "Res", "", s.Res))
lines = append(lines, pretty.SubValue(depth+1, "Res", "", s.Res, opts...)...)
// ManifestFieldType is element
lines = append(lines, pretty.SubValue(depth+1, "PCDE: Platform Config Data", "", s.PCDE))
lines = append(lines, pretty.SubValue(depth+1, "PCDE: Platform Config Data", "", s.PCDE, opts...)...)
// ManifestFieldType is element
lines = append(lines, pretty.SubValue(depth+1, "PME: Platform Manufacturer", "", s.PME))
lines = append(lines, pretty.SubValue(depth+1, "PME: Platform Manufacturer", "", s.PME, opts...)...)
// ManifestFieldType is element
lines = append(lines, pretty.SubValue(depth+1, "PMSE: Signature", "", &s.PMSE))
lines = append(lines, pretty.SubValue(depth+1, "PMSE: Signature", "", &s.PMSE, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -3,7 +3,7 @@ package bootpolicy
import (
"testing"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/unittest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/unittest"
)
func TestReadWrite(t *testing.T) {

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -219,7 +219,7 @@ func (s *PCD) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *PCD) PrettyString(depth uint, withHeader bool) string {
func (s *PCD) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "PCD", s))
@ -228,11 +228,11 @@ func (s *PCD) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0, opts...)...)
// ManifestFieldType is arrayDynamic
lines = append(lines, pretty.SubValue(depth+1, "Data", "", &s.Data))
lines = append(lines, pretty.SubValue(depth+1, "Data", "", &s.Data, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -225,7 +225,7 @@ func (s *PM) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *PM) PrettyString(depth uint, withHeader bool) string {
func (s *PM) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "PM", s))
@ -234,11 +234,11 @@ func (s *PM) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0, opts...)...)
// ManifestFieldType is arrayDynamic
lines = append(lines, pretty.SubValue(depth+1, "Data", "", &s.Data))
lines = append(lines, pretty.SubValue(depth+1, "Data", "", &s.Data, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -198,7 +198,7 @@ func (s *IBBSegment) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *IBBSegment) PrettyString(depth uint, withHeader bool) string {
func (s *IBBSegment) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "IBB Segment", s))
@ -207,13 +207,13 @@ func (s *IBBSegment) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved", "", &s.Reserved))
lines = append(lines, pretty.SubValue(depth+1, "Reserved", "", &s.Reserved, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Flags", "", &s.Flags))
lines = append(lines, pretty.SubValue(depth+1, "Flags", "", &s.Flags, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Base", "", &s.Base))
lines = append(lines, pretty.SubValue(depth+1, "Base", "", &s.Base, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Size", "", &s.Size))
lines = append(lines, pretty.SubValue(depth+1, "Size", "", &s.Size, opts...)...)
if depth < 2 {
lines = append(lines, "")
}
@ -903,7 +903,7 @@ func (s *SE) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *SE) PrettyString(depth uint, withHeader bool) string {
func (s *SE) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "IBB Segments Element", s))
@ -912,39 +912,39 @@ func (s *SE) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Set Number", "", &s.SetNumber))
lines = append(lines, pretty.SubValue(depth+1, "Set Number", "", &s.SetNumber, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 1", "", &s.Reserved1))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 1", "", &s.Reserved1, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "PBET Value", "", &s.PBETValue))
lines = append(lines, pretty.SubValue(depth+1, "PBET Value", "", &s.PBETValue, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Flags", "", &s.Flags))
lines = append(lines, pretty.SubValue(depth+1, "Flags", "", &s.Flags, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "IBB MCHBAR", "", &s.IBBMCHBAR))
lines = append(lines, pretty.SubValue(depth+1, "IBB MCHBAR", "", &s.IBBMCHBAR, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "VT-d BAR", "", &s.VTdBAR))
lines = append(lines, pretty.SubValue(depth+1, "VT-d BAR", "", &s.VTdBAR, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 0 Base Address", "", &s.DMAProtBase0))
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 0 Base Address", "", &s.DMAProtBase0, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 0 Limit Address", "", &s.DMAProtLimit0))
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 0 Limit Address", "", &s.DMAProtLimit0, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 1 Base Address", "", &s.DMAProtBase1))
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 1 Base Address", "", &s.DMAProtBase1, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 2 Limit Address", "", &s.DMAProtLimit1))
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 2 Limit Address", "", &s.DMAProtLimit1, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Post IBB Hash", "", &s.PostIBBHash))
lines = append(lines, pretty.SubValue(depth+1, "Post IBB Hash", "", &s.PostIBBHash, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "IBB Entry Point", "", &s.IBBEntryPoint))
lines = append(lines, pretty.SubValue(depth+1, "IBB Entry Point", "", &s.IBBEntryPoint, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Digest List", "", &s.DigestList))
lines = append(lines, pretty.SubValue(depth+1, "Digest List", "", &s.DigestList, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "OBB Hash", "", &s.OBBHash))
lines = append(lines, pretty.SubValue(depth+1, "OBB Hash", "", &s.OBBHash, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 2", "", &s.Reserved2))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 2", "", &s.Reserved2, opts...)...)
// ManifestFieldType is list
lines = append(lines, pretty.Header(depth+1, fmt.Sprintf("IBBSegments: Array of \"IBB Segment\" of length %d", len(s.IBBSegments)), s.IBBSegments))
for i := 0; i < len(s.IBBSegments); i++ {
@ -960,51 +960,51 @@ func (s *SE) PrettyString(depth uint, withHeader bool) string {
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags CachingType) PrettyString(depth uint, withHeader bool) string {
func (flags CachingType) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
return flags.String()
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags PBETValue) PrettyString(depth uint, withHeader bool) string {
func (flags PBETValue) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "PBET Value", flags))
}
lines = append(lines, pretty.SubValue(depth+1, "PBET Value", "", flags.PBETValue()))
lines = append(lines, pretty.SubValue(depth+1, "PBET Value", "", flags.PBETValue(), opts...)...)
return strings.Join(lines, "\n")
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags SEFlags) PrettyString(depth uint, withHeader bool) string {
func (flags SEFlags) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "SE Flags", flags))
}
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", flags.Reserved0()))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", flags.Reserved0(), opts...)...)
if flags.SupportsTopSwapRemediation() {
lines = append(lines, pretty.SubValue(depth+1, "Supports Top Swap Remediation", "BIOS supports Top Swap remediation action", true))
lines = append(lines, pretty.SubValue(depth+1, "Supports Top Swap Remediation", "BIOS supports Top Swap remediation action", true, opts...)...)
} else {
lines = append(lines, pretty.SubValue(depth+1, "Supports Top Swap Remediation", "BIOS does not support Top Swap remediation action", false))
lines = append(lines, pretty.SubValue(depth+1, "Supports Top Swap Remediation", "BIOS does not support Top Swap remediation action", false, opts...)...)
}
if flags.TPMFailureLeavesHierarchiesEnabled() {
lines = append(lines, pretty.SubValue(depth+1, "TPM Failure Leaves Hierarchies Enabled", "Leave Hierarchies enabled. Cap all PCRs on failure.", true))
lines = append(lines, pretty.SubValue(depth+1, "TPM Failure Leaves Hierarchies Enabled", "Leave Hierarchies enabled. Cap all PCRs on failure.", true, opts...)...)
} else {
lines = append(lines, pretty.SubValue(depth+1, "TPM Failure Leaves Hierarchies Enabled", "Do not leave enabled. Disable all Hierarchies or deactivate on failure.", false))
lines = append(lines, pretty.SubValue(depth+1, "TPM Failure Leaves Hierarchies Enabled", "Do not leave enabled. Disable all Hierarchies or deactivate on failure.", false, opts...)...)
}
if flags.AuthorityMeasure() {
lines = append(lines, pretty.SubValue(depth+1, "Authority Measure", "Extend Authority Measurements into the Authority PCR 7", true))
lines = append(lines, pretty.SubValue(depth+1, "Authority Measure", "Extend Authority Measurements into the Authority PCR 7", true, opts...)...)
} else {
lines = append(lines, pretty.SubValue(depth+1, "Authority Measure", "Do not extend into the Authority PCR 7", false))
lines = append(lines, pretty.SubValue(depth+1, "Authority Measure", "Do not extend into the Authority PCR 7", false, opts...)...)
}
if flags.Locality3Startup() {
lines = append(lines, pretty.SubValue(depth+1, "Locality 3 Startup", "Issue TPM Start-up from Locality 3", true))
lines = append(lines, pretty.SubValue(depth+1, "Locality 3 Startup", "Issue TPM Start-up from Locality 3", true, opts...)...)
} else {
lines = append(lines, pretty.SubValue(depth+1, "Locality 3 Startup", "Disabled", false))
lines = append(lines, pretty.SubValue(depth+1, "Locality 3 Startup", "Disabled", false, opts...)...)
}
if flags.DMAProtection() {
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection", "Enable DMA Protection", true))
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection", "Enable DMA Protection", true, opts...)...)
} else {
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection", "Disable DMA Protection", false))
lines = append(lines, pretty.SubValue(depth+1, "DMA Protection", "Disable DMA Protection", false, opts...)...)
}
return strings.Join(lines, "\n")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -182,7 +182,7 @@ func (s *Signature) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *Signature) PrettyString(depth uint, withHeader bool) string {
func (s *Signature) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Signature", s))
@ -191,9 +191,9 @@ func (s *Signature) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Key Signature", "", &s.KeySignature))
lines = append(lines, pretty.SubValue(depth+1, "Key Signature", "", &s.KeySignature, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -25,39 +25,39 @@ var (
)
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags BackupActionPolicy) PrettyString(depth uint, withHeader bool) string {
func (flags BackupActionPolicy) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
return flags.String()
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags ExecutionProfile) PrettyString(depth uint, withHeader bool) string {
func (flags ExecutionProfile) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
return flags.String()
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags MemoryScrubbingPolicy) PrettyString(depth uint, withHeader bool) string {
func (flags MemoryScrubbingPolicy) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
return flags.String()
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags ResetAUXControl) PrettyString(depth uint, withHeader bool) string {
func (flags ResetAUXControl) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
return flags.String()
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags TXTControlFlags) PrettyString(depth uint, withHeader bool) string {
func (flags TXTControlFlags) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "TXT Control Flags", flags))
}
lines = append(lines, pretty.SubValue(depth+1, "Execution Profile", "", flags.ExecutionProfile()))
lines = append(lines, pretty.SubValue(depth+1, "Memory Scrubbing Policy", "", flags.MemoryScrubbingPolicy()))
lines = append(lines, pretty.SubValue(depth+1, "Backup Action Policy", "", flags.BackupActionPolicy()))
lines = append(lines, pretty.SubValue(depth+1, "Execution Profile", "", flags.ExecutionProfile(), opts...)...)
lines = append(lines, pretty.SubValue(depth+1, "Memory Scrubbing Policy", "", flags.MemoryScrubbingPolicy(), opts...)...)
lines = append(lines, pretty.SubValue(depth+1, "Backup Action Policy", "", flags.BackupActionPolicy(), opts...)...)
if flags.IsSACMRequestedToExtendStaticPCRs() {
lines = append(lines, pretty.SubValue(depth+1, "Is SACM Requested To Extend Static PC Rs", "Default setting. S-ACM is requested to extend static PCRs", true))
lines = append(lines, pretty.SubValue(depth+1, "Is SACM Requested To Extend Static PC Rs", "Default setting. S-ACM is requested to extend static PCRs", true, opts...)...)
} else {
lines = append(lines, pretty.SubValue(depth+1, "Is SACM Requested To Extend Static PC Rs", "S-ACM is not requested to extend static PCRs", false))
lines = append(lines, pretty.SubValue(depth+1, "Is SACM Requested To Extend Static PC Rs", "S-ACM is not requested to extend static PCRs", false, opts...)...)
}
lines = append(lines, pretty.SubValue(depth+1, "Reset AUX Control", "", flags.ResetAUXControl()))
lines = append(lines, pretty.SubValue(depth+1, "Reset AUX Control", "", flags.ResetAUXControl(), opts...)...)
return strings.Join(lines, "\n")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/bootpolicy
package bootpolicy
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -597,7 +597,7 @@ func (s *TXT) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *TXT) PrettyString(depth uint, withHeader bool) string {
func (s *TXT) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "TXT", s))
@ -606,35 +606,35 @@ func (s *TXT) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Set Number", "", &s.SetNumber))
lines = append(lines, pretty.SubValue(depth+1, "Set Number", "", &s.SetNumber, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "S Init Min SVN Auth", "", &s.SInitMinSVNAuth))
lines = append(lines, pretty.SubValue(depth+1, "S Init Min SVN Auth", "", &s.SInitMinSVNAuth, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 1", "", &s.Reserved1))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 1", "", &s.Reserved1, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Control Flags", "", &s.ControlFlags))
lines = append(lines, pretty.SubValue(depth+1, "Control Flags", "", &s.ControlFlags, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Pwr Down Interval", "", &s.PwrDownInterval))
lines = append(lines, pretty.SubValue(depth+1, "Pwr Down Interval", "", &s.PwrDownInterval, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "PTT CMOS Offset 0", "", &s.PTTCMOSOffset0))
lines = append(lines, pretty.SubValue(depth+1, "PTT CMOS Offset 0", "", &s.PTTCMOSOffset0, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "PTT CMOS Offset 1", "", &s.PTTCMOSOffset1))
lines = append(lines, pretty.SubValue(depth+1, "PTT CMOS Offset 1", "", &s.PTTCMOSOffset1, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "ACPI Base Offset", "", &s.ACPIBaseOffset))
lines = append(lines, pretty.SubValue(depth+1, "ACPI Base Offset", "", &s.ACPIBaseOffset, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 2", "", &s.Reserved2))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 2", "", &s.Reserved2, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "ACPI MMIO Offset", "", &s.PwrMBaseOffset))
lines = append(lines, pretty.SubValue(depth+1, "ACPI MMIO Offset", "", &s.PwrMBaseOffset, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Digest List", "", &s.DigestList))
lines = append(lines, pretty.SubValue(depth+1, "Digest List", "", &s.DigestList, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 3", "", &s.Reserved3))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 3", "", &s.Reserved3, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Segment Count", "", &s.SegmentCount))
lines = append(lines, pretty.SubValue(depth+1, "Segment Count", "", &s.SegmentCount, opts...)...)
if depth < 2 {
lines = append(lines, "")
}
@ -642,6 +642,6 @@ func (s *TXT) PrettyString(depth uint, withHeader bool) string {
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags Duration16In5Sec) PrettyString(depth uint, withHeader bool) string {
func (flags Duration16In5Sec) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
return flags.String()
}

View File

@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/pkg/analyze"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/pkg/analyze"
)
func assertNoError(err error) {

View File

@ -12,7 +12,7 @@ import (
"strings"
"text/template"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/pkg/analyze"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/pkg/analyze"
"github.com/fatih/camelcase"
)
@ -104,7 +104,7 @@ func generateMethodsFile(file analyze.File, isCheck, enableTracing bool) error {
}
if bytes.Compare(b0, b1) != 0 {
return fmt.Errorf("file '%s' is not up-to-date; please run command: "+
"go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen %s",
"go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen %s",
generatedFile, file.Package.Path())
}
}

View File

@ -1,7 +1,7 @@
package main // TODO: replace this file with "embed", when it will be released: https://github.com/golang/go/issues/41191
const templateMethods = `// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen {{ .Package.Path }}
// To reproduce: go run github.com/9elements/converged-security-suite/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen {{ .Package.Path }}
package {{ .Package.Name }}
@ -9,13 +9,13 @@ import (
{{- if not .EnableTracing }}
"encoding/binary"
{{- else }}
binary "github.com/9elements/converged-security-suite/pkg/intel/metadata/manifest/internal/tracedbinary"
binary "github.com/9elements/converged-security-suite/pkg/intel/metadata/manifest/common/tracedbinary"
{{- end }}
"fmt"
"io"
"strings"
"github.com/9elements/converged-security-suite/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/pkg/intel/metadata/manifest/common/pretty"
{{- if ne .Package.Name "manifest" }}
"github.com/9elements/converged-security-suite/pkg/intel/metadata/manifest"
{{- end }}
@ -485,7 +485,7 @@ func (s *{{ $struct.Name }}) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *{{ $struct.Name }}) PrettyString(depth uint, withHeader bool) string {
func (s *{{ $struct.Name }}) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, {{ $struct.PrettyString | printf "%q" }}, s))
@ -507,7 +507,7 @@ func (s *{{ $struct.Name }}) PrettyString(depth uint, withHeader bool) string {
{{- else }}
{{- $fieldValue := ternary $field.IsPointer (printf "s.%s" $field.Name) (printf "&s.%s" $field.Name) }}
{{- $prettyValue := ternary (ne $field.PrettyValue "") (printf "s.%s" $field.PrettyValue) $fieldValue }}
lines = append(lines, pretty.SubValue(depth+1, {{ $field.PrettyString | printf "%q" }}, "", {{ $prettyValue }}))
lines = append(lines, pretty.SubValue(depth+1, {{ $field.PrettyString | printf "%q" }}, "", {{ $prettyValue }}, opts...)...)
{{- end }}
{{- end }}
if depth < 2 {
@ -520,7 +520,7 @@ func (s *{{ $struct.Name }}) PrettyString(depth uint, withHeader bool) string {
{{- range $index,$type := .BasicNamedTypes }}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags {{ $type.Name }}) PrettyString(depth uint, withHeader bool) string {
func (flags {{ $type.Name }}) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
{{- if not (isNil ($type.MethodByName "String")) }}
return flags.String()
{{- else }}
@ -532,12 +532,12 @@ func (flags {{ $type.Name }}) PrettyString(depth uint, withHeader bool) string {
{{- if $method.ReturnsFlagValue }}
{{- if eq $method.ReturnsTypeName "bool" }}
if flags.{{ $method.Name }}() {
lines = append(lines, pretty.SubValue(depth+1, "{{ $method.Name.Name | camelcaseToSentence }}", {{ $method.PrettyStringForResult true | printf "%q" }}, true))
lines = append(lines, pretty.SubValue(depth+1, "{{ $method.Name.Name | camelcaseToSentence }}", {{ $method.PrettyStringForResult true | printf "%q" }}, true, opts...)...)
} else {
lines = append(lines, pretty.SubValue(depth+1, "{{ $method.Name.Name | camelcaseToSentence }}", {{ $method.PrettyStringForResult false | printf "%q" }}, false))
lines = append(lines, pretty.SubValue(depth+1, "{{ $method.Name.Name | camelcaseToSentence }}", {{ $method.PrettyStringForResult false | printf "%q" }}, false, opts...)...)
}
{{- else }}
lines = append(lines, pretty.SubValue(depth+1, "{{ $method.Name.Name | camelcaseToSentence }}", "", flags.{{ $method.Name }}()))
lines = append(lines, pretty.SubValue(depth+1, "{{ $method.Name.Name | camelcaseToSentence }}", "", flags.{{ $method.Name }}(), opts...)...)
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,23 @@
package pretty
type Option interface {
apply(*config)
}
type OptionOmitKeySignature bool
func (opt OptionOmitKeySignature) apply(cfg *config) {
cfg.OmitKeySignature = bool(opt)
}
type config struct {
OmitKeySignature bool
}
func getConfig(opts []Option) config {
var cfg config
for _, opt := range opts {
opt.apply(&cfg)
}
return cfg
}

View File

@ -24,14 +24,22 @@ func Header(depth uint, description string, obj interface{}) string {
return description
}
func SubValue(depth uint, fieldName, valueDescription string, value interface{}) string {
if valueDescription == "" {
valueDescription = getDescriptionForValue(depth, value)
func SubValue(depth uint, fieldName, valueDescription string, value interface{}, opts ...Option) []string {
cfg := getConfig(opts)
if cfg.OmitKeySignature {
switch fieldName {
case "PMSE: Signature", "Key And Signature":
return nil
}
}
return fmt.Sprintf("%s %s", Header(depth, fieldName, nil), valueDescription)
if valueDescription == "" {
valueDescription = getDescriptionForValue(depth, value, opts...)
}
return []string{fmt.Sprintf("%s %s", Header(depth, fieldName, nil), valueDescription)}
}
func getDescriptionForValue(depth uint, value interface{}) string {
func getDescriptionForValue(depth uint, value interface{}, opts ...Option) string {
v := reflect.ValueOf(value)
if v.Kind() == reflect.Ptr && v.IsNil() {
return "is not set (nil)"
@ -39,9 +47,9 @@ func getDescriptionForValue(depth uint, value interface{}) string {
switch value := value.(type) {
case interface {
PrettyString(depth uint, withHeader bool) string
PrettyString(depth uint, withHeader bool, opts ...Option) string
}:
description := value.PrettyString(depth, false)
description := value.PrettyString(depth, false, opts...)
if len(strings.Split(description, "\n")) > 1 {
return "\n" + description
} else {

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
package manifest
@ -10,7 +10,7 @@ import (
"io"
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -163,7 +163,7 @@ func (s *HashList) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *HashList) PrettyString(depth uint, withHeader bool) string {
func (s *HashList) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Hash List", s))
@ -172,7 +172,7 @@ func (s *HashList) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Size", "", &s.Size))
lines = append(lines, pretty.SubValue(depth+1, "Size", "", &s.Size, opts...)...)
// ManifestFieldType is list
lines = append(lines, pretty.Header(depth+1, fmt.Sprintf("List: Array of \"Hash Structure\" of length %d", len(s.List)), s.List))
for i := 0; i < len(s.List); i++ {
@ -314,7 +314,7 @@ func (s *HashStructure) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *HashStructure) PrettyString(depth uint, withHeader bool) string {
func (s *HashStructure) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Hash Structure", s))
@ -323,9 +323,9 @@ func (s *HashStructure) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Hash Alg", "", &s.HashAlg))
lines = append(lines, pretty.SubValue(depth+1, "Hash Alg", "", &s.HashAlg, opts...)...)
// ManifestFieldType is arrayDynamic
lines = append(lines, pretty.SubValue(depth+1, "Hash Buffer", "", &s.HashBuffer))
lines = append(lines, pretty.SubValue(depth+1, "Hash Buffer", "", &s.HashBuffer, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/key
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/key
package key
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -141,7 +141,7 @@ func (s *Hash) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *Hash) PrettyString(depth uint, withHeader bool) string {
func (s *Hash) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Hash", s))
@ -150,9 +150,9 @@ func (s *Hash) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Usage", "", &s.Usage))
lines = append(lines, pretty.SubValue(depth+1, "Usage", "", &s.Usage, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Digest", "", &s.Digest))
lines = append(lines, pretty.SubValue(depth+1, "Digest", "", &s.Digest, opts...)...)
if depth < 2 {
lines = append(lines, "")
}
@ -160,6 +160,6 @@ func (s *Hash) PrettyString(depth uint, withHeader bool) string {
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags Usage) PrettyString(depth uint, withHeader bool) string {
func (flags Usage) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
return flags.String()
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/key
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/key
package key
@ -11,7 +11,7 @@ import (
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -416,7 +416,7 @@ func (s *Manifest) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *Manifest) PrettyString(depth uint, withHeader bool) string {
func (s *Manifest) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Key Manifest", s))
@ -425,19 +425,19 @@ func (s *Manifest) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is structInfo
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo))
lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Key Manifest Signature Offset", "", &s.KeyManifestSignatureOffset))
lines = append(lines, pretty.SubValue(depth+1, "Key Manifest Signature Offset", "", &s.KeyManifestSignatureOffset, opts...)...)
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "Reserved 2", "", &s.Reserved2))
lines = append(lines, pretty.SubValue(depth+1, "Reserved 2", "", &s.Reserved2, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Revision", "", &s.Revision))
lines = append(lines, pretty.SubValue(depth+1, "Revision", "", &s.Revision, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "KMSVN", "", &s.KMSVN))
lines = append(lines, pretty.SubValue(depth+1, "KMSVN", "", &s.KMSVN, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "KMID", "", &s.KMID))
lines = append(lines, pretty.SubValue(depth+1, "KMID", "", &s.KMID, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Pub Key Hash Alg", "", &s.PubKeyHashAlg))
lines = append(lines, pretty.SubValue(depth+1, "Pub Key Hash Alg", "", &s.PubKeyHashAlg, opts...)...)
// ManifestFieldType is list
lines = append(lines, pretty.Header(depth+1, fmt.Sprintf("Hash: Array of \"Hash\" of length %d", len(s.Hash)), s.Hash))
for i := 0; i < len(s.Hash); i++ {
@ -447,7 +447,7 @@ func (s *Manifest) PrettyString(depth uint, withHeader bool) string {
lines = append(lines, "")
}
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Key And Signature", "", &s.KeyAndSignature))
lines = append(lines, pretty.SubValue(depth+1, "Key And Signature", "", &s.KeyAndSignature, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -3,7 +3,7 @@ package key
import (
"testing"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/unittest"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/unittest"
)
func TestReadWrite(t *testing.T) {

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
package manifest
@ -10,7 +10,7 @@ import (
"io"
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -198,7 +198,7 @@ func (s *Key) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *Key) PrettyString(depth uint, withHeader bool) string {
func (s *Key) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Key", s))
@ -207,13 +207,13 @@ func (s *Key) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Key Alg", "", &s.KeyAlg))
lines = append(lines, pretty.SubValue(depth+1, "Key Alg", "", &s.KeyAlg, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version))
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Key Size", "", &s.KeySize))
lines = append(lines, pretty.SubValue(depth+1, "Key Size", "", &s.KeySize, opts...)...)
// ManifestFieldType is arrayDynamic
lines = append(lines, pretty.SubValue(depth+1, "Data", "", &s.Data))
lines = append(lines, pretty.SubValue(depth+1, "Data", "", &s.Data, opts...)...)
if depth < 2 {
lines = append(lines, "")
}
@ -221,12 +221,12 @@ func (s *Key) PrettyString(depth uint, withHeader bool) string {
}
// PrettyString returns the bits of the flags in an easy-to-read format.
func (flags BitSize) PrettyString(depth uint, withHeader bool) string {
func (flags BitSize) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Bit Size", flags))
}
lines = append(lines, pretty.SubValue(depth+1, "In Bits", "", flags.InBits()))
lines = append(lines, pretty.SubValue(depth+1, "In Bytes", "", flags.InBytes()))
lines = append(lines, pretty.SubValue(depth+1, "In Bits", "", flags.InBits(), opts...)...)
lines = append(lines, pretty.SubValue(depth+1, "In Bytes", "", flags.InBytes(), opts...)...)
return strings.Join(lines, "\n")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
package manifest
@ -10,7 +10,7 @@ import (
"io"
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -181,7 +181,7 @@ func (s *KeySignature) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *KeySignature) PrettyString(depth uint, withHeader bool) string {
func (s *KeySignature) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Key Signature", s))
@ -190,11 +190,11 @@ func (s *KeySignature) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version))
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Key", "", &s.Key))
lines = append(lines, pretty.SubValue(depth+1, "Key", "", &s.Key, opts...)...)
// ManifestFieldType is subStruct
lines = append(lines, pretty.SubValue(depth+1, "Signature", "", &s.Signature))
lines = append(lines, pretty.SubValue(depth+1, "Signature", "", &s.Signature, opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
package manifest
@ -10,7 +10,7 @@ import (
"io"
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -227,7 +227,7 @@ func (s *Signature) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *Signature) PrettyString(depth uint, withHeader bool) string {
func (s *Signature) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Signature", s))
@ -236,15 +236,15 @@ func (s *Signature) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Sig Scheme", "", &s.SigScheme))
lines = append(lines, pretty.SubValue(depth+1, "Sig Scheme", "", &s.SigScheme, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version))
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Key Size", "", &s.KeySize))
lines = append(lines, pretty.SubValue(depth+1, "Key Size", "", &s.KeySize, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Hash Alg", "", &s.HashAlg))
lines = append(lines, pretty.SubValue(depth+1, "Hash Alg", "", &s.HashAlg, opts...)...)
// ManifestFieldType is arrayDynamic
lines = append(lines, pretty.SubValue(depth+1, "Data", "", s.dataPrettyValue()))
lines = append(lines, pretty.SubValue(depth+1, "Data", "", s.dataPrettyValue(), opts...)...)
if depth < 2 {
lines = append(lines, "")
}

View File

@ -1,6 +1,6 @@
// +build !manifestcodegen
// Code generated by "menifestcodegen". DO NOT EDIT.
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
// To reproduce: go run github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/manifestcodegen/cmd/manifestcodegen github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest
package manifest
@ -10,7 +10,7 @@ import (
"io"
"strings"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/internal/pretty"
"github.com/9elements/converged-security-suite/v2/pkg/intel/metadata/manifest/common/pretty"
)
var (
@ -190,7 +190,7 @@ func (s *StructInfo) TotalSize() uint64 {
}
// PrettyString returns the content of the structure in an easy-to-read format.
func (s *StructInfo) PrettyString(depth uint, withHeader bool) string {
func (s *StructInfo) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
var lines []string
if withHeader {
lines = append(lines, pretty.Header(depth, "Struct Info", s))
@ -199,13 +199,13 @@ func (s *StructInfo) PrettyString(depth uint, withHeader bool) string {
return strings.Join(lines, "\n")
}
// ManifestFieldType is arrayStatic
lines = append(lines, pretty.SubValue(depth+1, "ID", "", &s.ID))
lines = append(lines, pretty.SubValue(depth+1, "ID", "", &s.ID, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version))
lines = append(lines, pretty.SubValue(depth+1, "Version", "", &s.Version, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Variable 0", "", &s.Variable0))
lines = append(lines, pretty.SubValue(depth+1, "Variable 0", "", &s.Variable0, opts...)...)
// ManifestFieldType is endValue
lines = append(lines, pretty.SubValue(depth+1, "Element Size", "", &s.ElementSize))
lines = append(lines, pretty.SubValue(depth+1, "Element Size", "", &s.ElementSize, opts...)...)
if depth < 2 {
lines = append(lines, "")
}