github.com/linuxboot/fiano@v1.2.0/pkg/intel/metadata/bg/bgbootpolicy/se_manifestcodegen.go (about)

     1  // Copyright 2017-2021 the LinuxBoot Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !manifestcodegen
     6  // +build !manifestcodegen
     7  
     8  // Code generated by "menifestcodegen". DO NOT EDIT.
     9  // To reproduce: go run github.com/linuxboot/fiano/pkg/intel/metadata/common/manifestcodegen/cmd/manifestcodegen -package bg github.com/linuxboot/fiano/pkg/intel/metadata/bg/bgbootpolicy
    10  
    11  package bgbootpolicy
    12  
    13  import (
    14  	"encoding/binary"
    15  	"fmt"
    16  	"io"
    17  	"strings"
    18  
    19  	"github.com/linuxboot/fiano/pkg/intel/metadata/bg"
    20  	"github.com/linuxboot/fiano/pkg/intel/metadata/common/pretty"
    21  )
    22  
    23  var (
    24  	// Just to avoid errors in "import" above in case if it wasn't used below
    25  	_ = binary.LittleEndian
    26  	_ = (fmt.Stringer)(nil)
    27  	_ = (io.Reader)(nil)
    28  	_ = pretty.Header
    29  	_ = strings.Join
    30  	_ = bg.StructInfo{}
    31  )
    32  
    33  // NewIBBSegment returns a new instance of IBBSegment with
    34  // all default values set.
    35  func NewIBBSegment() *IBBSegment {
    36  	s := &IBBSegment{}
    37  	s.Rehash()
    38  	return s
    39  }
    40  
    41  // Validate (recursively) checks the structure if there are any unexpected
    42  // values. It returns an error if so.
    43  func (s *IBBSegment) Validate() error {
    44  	// See tag "require"
    45  	for idx := range s.Reserved {
    46  		if s.Reserved[idx] != 0 {
    47  			return fmt.Errorf("'Reserved[%d]' is expected to be 0, but it is %v", idx, s.Reserved[idx])
    48  		}
    49  	}
    50  
    51  	return nil
    52  }
    53  
    54  // ReadFrom reads the IBBSegment from 'r' in format defined in the document #575623.
    55  func (s *IBBSegment) ReadFrom(r io.Reader) (int64, error) {
    56  	totalN := int64(0)
    57  
    58  	// Reserved (ManifestFieldType: arrayStatic)
    59  	{
    60  		n, err := 2, binary.Read(r, binary.LittleEndian, s.Reserved[:])
    61  		if err != nil {
    62  			return totalN, fmt.Errorf("unable to read field 'Reserved': %w", err)
    63  		}
    64  		totalN += int64(n)
    65  	}
    66  
    67  	// Flags (ManifestFieldType: endValue)
    68  	{
    69  		n, err := 2, binary.Read(r, binary.LittleEndian, &s.Flags)
    70  		if err != nil {
    71  			return totalN, fmt.Errorf("unable to read field 'Flags': %w", err)
    72  		}
    73  		totalN += int64(n)
    74  	}
    75  
    76  	// Base (ManifestFieldType: endValue)
    77  	{
    78  		n, err := 4, binary.Read(r, binary.LittleEndian, &s.Base)
    79  		if err != nil {
    80  			return totalN, fmt.Errorf("unable to read field 'Base': %w", err)
    81  		}
    82  		totalN += int64(n)
    83  	}
    84  
    85  	// Size (ManifestFieldType: endValue)
    86  	{
    87  		n, err := 4, binary.Read(r, binary.LittleEndian, &s.Size)
    88  		if err != nil {
    89  			return totalN, fmt.Errorf("unable to read field 'Size': %w", err)
    90  		}
    91  		totalN += int64(n)
    92  	}
    93  
    94  	return totalN, nil
    95  }
    96  
    97  // RehashRecursive calls Rehash (see below) recursively.
    98  func (s *IBBSegment) RehashRecursive() {
    99  	s.Rehash()
   100  }
   101  
   102  // Rehash sets values which are calculated automatically depending on the rest
   103  // data. It is usually about the total size field of an element.
   104  func (s *IBBSegment) Rehash() {
   105  }
   106  
   107  // WriteTo writes the IBBSegment into 'w' in format defined in
   108  // the document #575623.
   109  func (s *IBBSegment) WriteTo(w io.Writer) (int64, error) {
   110  	totalN := int64(0)
   111  	s.Rehash()
   112  
   113  	// Reserved (ManifestFieldType: arrayStatic)
   114  	{
   115  		n, err := 2, binary.Write(w, binary.LittleEndian, s.Reserved[:])
   116  		if err != nil {
   117  			return totalN, fmt.Errorf("unable to write field 'Reserved': %w", err)
   118  		}
   119  		totalN += int64(n)
   120  	}
   121  
   122  	// Flags (ManifestFieldType: endValue)
   123  	{
   124  		n, err := 2, binary.Write(w, binary.LittleEndian, &s.Flags)
   125  		if err != nil {
   126  			return totalN, fmt.Errorf("unable to write field 'Flags': %w", err)
   127  		}
   128  		totalN += int64(n)
   129  	}
   130  
   131  	// Base (ManifestFieldType: endValue)
   132  	{
   133  		n, err := 4, binary.Write(w, binary.LittleEndian, &s.Base)
   134  		if err != nil {
   135  			return totalN, fmt.Errorf("unable to write field 'Base': %w", err)
   136  		}
   137  		totalN += int64(n)
   138  	}
   139  
   140  	// Size (ManifestFieldType: endValue)
   141  	{
   142  		n, err := 4, binary.Write(w, binary.LittleEndian, &s.Size)
   143  		if err != nil {
   144  			return totalN, fmt.Errorf("unable to write field 'Size': %w", err)
   145  		}
   146  		totalN += int64(n)
   147  	}
   148  
   149  	return totalN, nil
   150  }
   151  
   152  // ReservedSize returns the size in bytes of the value of field Reserved
   153  func (s *IBBSegment) ReservedTotalSize() uint64 {
   154  	return 2
   155  }
   156  
   157  // FlagsSize returns the size in bytes of the value of field Flags
   158  func (s *IBBSegment) FlagsTotalSize() uint64 {
   159  	return 2
   160  }
   161  
   162  // BaseSize returns the size in bytes of the value of field Base
   163  func (s *IBBSegment) BaseTotalSize() uint64 {
   164  	return 4
   165  }
   166  
   167  // SizeSize returns the size in bytes of the value of field Size
   168  func (s *IBBSegment) SizeTotalSize() uint64 {
   169  	return 4
   170  }
   171  
   172  // ReservedOffset returns the offset in bytes of field Reserved
   173  func (s *IBBSegment) ReservedOffset() uint64 {
   174  	return 0
   175  }
   176  
   177  // FlagsOffset returns the offset in bytes of field Flags
   178  func (s *IBBSegment) FlagsOffset() uint64 {
   179  	return s.ReservedOffset() + s.ReservedTotalSize()
   180  }
   181  
   182  // BaseOffset returns the offset in bytes of field Base
   183  func (s *IBBSegment) BaseOffset() uint64 {
   184  	return s.FlagsOffset() + s.FlagsTotalSize()
   185  }
   186  
   187  // SizeOffset returns the offset in bytes of field Size
   188  func (s *IBBSegment) SizeOffset() uint64 {
   189  	return s.BaseOffset() + s.BaseTotalSize()
   190  }
   191  
   192  // Size returns the total size of the IBBSegment.
   193  func (s *IBBSegment) TotalSize() uint64 {
   194  	if s == nil {
   195  		return 0
   196  	}
   197  
   198  	var size uint64
   199  	size += s.ReservedTotalSize()
   200  	size += s.FlagsTotalSize()
   201  	size += s.BaseTotalSize()
   202  	size += s.SizeTotalSize()
   203  	return size
   204  }
   205  
   206  // PrettyString returns the content of the structure in an easy-to-read format.
   207  func (s *IBBSegment) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
   208  	var lines []string
   209  	if withHeader {
   210  		lines = append(lines, pretty.Header(depth, "IBB Segment", s))
   211  	}
   212  	if s == nil {
   213  		return strings.Join(lines, "\n")
   214  	}
   215  	// ManifestFieldType is arrayStatic
   216  	lines = append(lines, pretty.SubValue(depth+1, "Reserved", "", &s.Reserved, opts...)...)
   217  	// ManifestFieldType is endValue
   218  	lines = append(lines, pretty.SubValue(depth+1, "Flags", "", &s.Flags, opts...)...)
   219  	// ManifestFieldType is endValue
   220  	lines = append(lines, pretty.SubValue(depth+1, "Base", "", &s.Base, opts...)...)
   221  	// ManifestFieldType is endValue
   222  	lines = append(lines, pretty.SubValue(depth+1, "Size", "", &s.Size, opts...)...)
   223  	if depth < 2 {
   224  		lines = append(lines, "")
   225  	}
   226  	return strings.Join(lines, "\n")
   227  }
   228  
   229  // NewSE returns a new instance of SE with
   230  // all default values set.
   231  func NewSE() *SE {
   232  	s := &SE{}
   233  	copy(s.StructInfo.ID[:], []byte(StructureIDSE))
   234  	s.StructInfo.Version = 0x10
   235  	// Recursively initializing a child structure:
   236  	s.PostIBBHash = *bg.NewHashStructureFill()
   237  	// Recursively initializing a child structure:
   238  	s.Digest = *bg.NewHashStructure()
   239  	s.Rehash()
   240  	return s
   241  }
   242  
   243  // Validate (recursively) checks the structure if there are any unexpected
   244  // values. It returns an error if so.
   245  func (s *SE) Validate() error {
   246  	// See tag "require"
   247  	for idx := range s.Reserved0 {
   248  		if s.Reserved0[idx] != 0 {
   249  			return fmt.Errorf("'Reserved0[%d]' is expected to be 0, but it is %v", idx, s.Reserved0[idx])
   250  		}
   251  	}
   252  	// See tag "require"
   253  	for idx := range s.Reserved1 {
   254  		if s.Reserved1[idx] != 0 {
   255  			return fmt.Errorf("'Reserved1[%d]' is expected to be 0, but it is %v", idx, s.Reserved1[idx])
   256  		}
   257  	}
   258  	// Recursively validating a child structure:
   259  	if err := s.PostIBBHash.Validate(); err != nil {
   260  		return fmt.Errorf("error on field 'PostIBBHash': %w", err)
   261  	}
   262  	// Recursively validating a child structure:
   263  	if err := s.Digest.Validate(); err != nil {
   264  		return fmt.Errorf("error on field 'Digest': %w", err)
   265  	}
   266  
   267  	return nil
   268  }
   269  
   270  // StructureIDSE is the StructureID (in terms of
   271  // the document #575623) of element 'SE'.
   272  const StructureIDSE = "__IBBS__"
   273  
   274  // GetStructInfo returns current value of StructInfo of the structure.
   275  //
   276  // StructInfo is a set of standard fields with presented in any element
   277  // ("element" in terms of document #575623).
   278  func (s *SE) GetStructInfo() bg.StructInfo {
   279  	return s.StructInfo
   280  }
   281  
   282  // SetStructInfo sets new value of StructInfo to the structure.
   283  //
   284  // StructInfo is a set of standard fields with presented in any element
   285  // ("element" in terms of document #575623).
   286  func (s *SE) SetStructInfo(newStructInfo bg.StructInfo) {
   287  	s.StructInfo = newStructInfo
   288  }
   289  
   290  // ReadFrom reads the SE from 'r' in format defined in the document #575623.
   291  func (s *SE) ReadFrom(r io.Reader) (int64, error) {
   292  	var totalN int64
   293  
   294  	err := binary.Read(r, binary.LittleEndian, &s.StructInfo)
   295  	if err != nil {
   296  		return totalN, fmt.Errorf("unable to read structure info at %d: %w", totalN, err)
   297  	}
   298  	totalN += int64(binary.Size(s.StructInfo))
   299  
   300  	n, err := s.ReadDataFrom(r)
   301  	if err != nil {
   302  		return totalN, fmt.Errorf("unable to read data: %w", err)
   303  	}
   304  	totalN += n
   305  
   306  	return totalN, nil
   307  }
   308  
   309  // ReadDataFrom reads the SE from 'r' excluding StructInfo,
   310  // in format defined in the document #575623.
   311  func (s *SE) ReadDataFrom(r io.Reader) (int64, error) {
   312  	totalN := int64(0)
   313  
   314  	// StructInfo (ManifestFieldType: structInfo)
   315  	{
   316  		// ReadDataFrom does not read Struct, use ReadFrom for that.
   317  	}
   318  
   319  	// Reserved0 (ManifestFieldType: arrayStatic)
   320  	{
   321  		n, err := 1, binary.Read(r, binary.LittleEndian, s.Reserved0[:])
   322  		if err != nil {
   323  			return totalN, fmt.Errorf("unable to read field 'Reserved0': %w", err)
   324  		}
   325  		totalN += int64(n)
   326  	}
   327  
   328  	// Reserved1 (ManifestFieldType: arrayStatic)
   329  	{
   330  		n, err := 1, binary.Read(r, binary.LittleEndian, s.Reserved1[:])
   331  		if err != nil {
   332  			return totalN, fmt.Errorf("unable to read field 'Reserved1': %w", err)
   333  		}
   334  		totalN += int64(n)
   335  	}
   336  
   337  	// PBETValue (ManifestFieldType: endValue)
   338  	{
   339  		n, err := 1, binary.Read(r, binary.LittleEndian, &s.PBETValue)
   340  		if err != nil {
   341  			return totalN, fmt.Errorf("unable to read field 'PBETValue': %w", err)
   342  		}
   343  		totalN += int64(n)
   344  	}
   345  
   346  	// Flags (ManifestFieldType: endValue)
   347  	{
   348  		n, err := 4, binary.Read(r, binary.LittleEndian, &s.Flags)
   349  		if err != nil {
   350  			return totalN, fmt.Errorf("unable to read field 'Flags': %w", err)
   351  		}
   352  		totalN += int64(n)
   353  	}
   354  
   355  	// IBBMCHBAR (ManifestFieldType: endValue)
   356  	{
   357  		n, err := 8, binary.Read(r, binary.LittleEndian, &s.IBBMCHBAR)
   358  		if err != nil {
   359  			return totalN, fmt.Errorf("unable to read field 'IBBMCHBAR': %w", err)
   360  		}
   361  		totalN += int64(n)
   362  	}
   363  
   364  	// VTdBAR (ManifestFieldType: endValue)
   365  	{
   366  		n, err := 8, binary.Read(r, binary.LittleEndian, &s.VTdBAR)
   367  		if err != nil {
   368  			return totalN, fmt.Errorf("unable to read field 'VTdBAR': %w", err)
   369  		}
   370  		totalN += int64(n)
   371  	}
   372  
   373  	// PMRLBase (ManifestFieldType: endValue)
   374  	{
   375  		n, err := 4, binary.Read(r, binary.LittleEndian, &s.PMRLBase)
   376  		if err != nil {
   377  			return totalN, fmt.Errorf("unable to read field 'PMRLBase': %w", err)
   378  		}
   379  		totalN += int64(n)
   380  	}
   381  
   382  	// PMRLLimit (ManifestFieldType: endValue)
   383  	{
   384  		n, err := 4, binary.Read(r, binary.LittleEndian, &s.PMRLLimit)
   385  		if err != nil {
   386  			return totalN, fmt.Errorf("unable to read field 'PMRLLimit': %w", err)
   387  		}
   388  		totalN += int64(n)
   389  	}
   390  
   391  	// Reserved2 (ManifestFieldType: arrayStatic)
   392  	{
   393  		n, err := 8, binary.Read(r, binary.LittleEndian, s.Reserved2[:])
   394  		if err != nil {
   395  			return totalN, fmt.Errorf("unable to read field 'Reserved2': %w", err)
   396  		}
   397  		totalN += int64(n)
   398  	}
   399  
   400  	// Reserved3 (ManifestFieldType: arrayStatic)
   401  	{
   402  		n, err := 8, binary.Read(r, binary.LittleEndian, s.Reserved3[:])
   403  		if err != nil {
   404  			return totalN, fmt.Errorf("unable to read field 'Reserved3': %w", err)
   405  		}
   406  		totalN += int64(n)
   407  	}
   408  
   409  	// PostIBBHash (ManifestFieldType: subStruct)
   410  	{
   411  		n, err := s.PostIBBHash.ReadFrom(r)
   412  		if err != nil {
   413  			return totalN, fmt.Errorf("unable to read field 'PostIBBHash': %w", err)
   414  		}
   415  		totalN += int64(n)
   416  	}
   417  
   418  	// IBBEntryPoint (ManifestFieldType: endValue)
   419  	{
   420  		n, err := 4, binary.Read(r, binary.LittleEndian, &s.IBBEntryPoint)
   421  		if err != nil {
   422  			return totalN, fmt.Errorf("unable to read field 'IBBEntryPoint': %w", err)
   423  		}
   424  		totalN += int64(n)
   425  	}
   426  
   427  	// Digest (ManifestFieldType: subStruct)
   428  	{
   429  		n, err := s.Digest.ReadFrom(r)
   430  		if err != nil {
   431  			return totalN, fmt.Errorf("unable to read field 'Digest': %w", err)
   432  		}
   433  		totalN += int64(n)
   434  	}
   435  
   436  	// IBBSegments (ManifestFieldType: list)
   437  	{
   438  		var count uint8
   439  		err := binary.Read(r, binary.LittleEndian, &count)
   440  		if err != nil {
   441  			return totalN, fmt.Errorf("unable to read the count for field 'IBBSegments': %w", err)
   442  		}
   443  		totalN += int64(binary.Size(count))
   444  		s.IBBSegments = make([]IBBSegment, count)
   445  
   446  		for idx := range s.IBBSegments {
   447  			n, err := s.IBBSegments[idx].ReadFrom(r)
   448  			if err != nil {
   449  				return totalN, fmt.Errorf("unable to read field 'IBBSegments[%d]': %w", idx, err)
   450  			}
   451  			totalN += int64(n)
   452  		}
   453  	}
   454  
   455  	return totalN, nil
   456  }
   457  
   458  // RehashRecursive calls Rehash (see below) recursively.
   459  func (s *SE) RehashRecursive() {
   460  	s.StructInfo.Rehash()
   461  	s.PostIBBHash.Rehash()
   462  	s.Digest.Rehash()
   463  	s.Rehash()
   464  }
   465  
   466  // Rehash sets values which are calculated automatically depending on the rest
   467  // data. It is usually about the total size field of an element.
   468  func (s *SE) Rehash() {
   469  }
   470  
   471  // WriteTo writes the SE into 'w' in format defined in
   472  // the document #575623.
   473  func (s *SE) WriteTo(w io.Writer) (int64, error) {
   474  	totalN := int64(0)
   475  	s.Rehash()
   476  
   477  	// StructInfo (ManifestFieldType: structInfo)
   478  	{
   479  		n, err := s.StructInfo.WriteTo(w)
   480  		if err != nil {
   481  			return totalN, fmt.Errorf("unable to write field 'StructInfo': %w", err)
   482  		}
   483  		totalN += int64(n)
   484  	}
   485  
   486  	// Reserved0 (ManifestFieldType: arrayStatic)
   487  	{
   488  		n, err := 1, binary.Write(w, binary.LittleEndian, s.Reserved0[:])
   489  		if err != nil {
   490  			return totalN, fmt.Errorf("unable to write field 'Reserved0': %w", err)
   491  		}
   492  		totalN += int64(n)
   493  	}
   494  
   495  	// Reserved1 (ManifestFieldType: arrayStatic)
   496  	{
   497  		n, err := 1, binary.Write(w, binary.LittleEndian, s.Reserved1[:])
   498  		if err != nil {
   499  			return totalN, fmt.Errorf("unable to write field 'Reserved1': %w", err)
   500  		}
   501  		totalN += int64(n)
   502  	}
   503  
   504  	// PBETValue (ManifestFieldType: endValue)
   505  	{
   506  		n, err := 1, binary.Write(w, binary.LittleEndian, &s.PBETValue)
   507  		if err != nil {
   508  			return totalN, fmt.Errorf("unable to write field 'PBETValue': %w", err)
   509  		}
   510  		totalN += int64(n)
   511  	}
   512  
   513  	// Flags (ManifestFieldType: endValue)
   514  	{
   515  		n, err := 4, binary.Write(w, binary.LittleEndian, &s.Flags)
   516  		if err != nil {
   517  			return totalN, fmt.Errorf("unable to write field 'Flags': %w", err)
   518  		}
   519  		totalN += int64(n)
   520  	}
   521  
   522  	// IBBMCHBAR (ManifestFieldType: endValue)
   523  	{
   524  		n, err := 8, binary.Write(w, binary.LittleEndian, &s.IBBMCHBAR)
   525  		if err != nil {
   526  			return totalN, fmt.Errorf("unable to write field 'IBBMCHBAR': %w", err)
   527  		}
   528  		totalN += int64(n)
   529  	}
   530  
   531  	// VTdBAR (ManifestFieldType: endValue)
   532  	{
   533  		n, err := 8, binary.Write(w, binary.LittleEndian, &s.VTdBAR)
   534  		if err != nil {
   535  			return totalN, fmt.Errorf("unable to write field 'VTdBAR': %w", err)
   536  		}
   537  		totalN += int64(n)
   538  	}
   539  
   540  	// PMRLBase (ManifestFieldType: endValue)
   541  	{
   542  		n, err := 4, binary.Write(w, binary.LittleEndian, &s.PMRLBase)
   543  		if err != nil {
   544  			return totalN, fmt.Errorf("unable to write field 'PMRLBase': %w", err)
   545  		}
   546  		totalN += int64(n)
   547  	}
   548  
   549  	// PMRLLimit (ManifestFieldType: endValue)
   550  	{
   551  		n, err := 4, binary.Write(w, binary.LittleEndian, &s.PMRLLimit)
   552  		if err != nil {
   553  			return totalN, fmt.Errorf("unable to write field 'PMRLLimit': %w", err)
   554  		}
   555  		totalN += int64(n)
   556  	}
   557  
   558  	// Reserved2 (ManifestFieldType: arrayStatic)
   559  	{
   560  		n, err := 8, binary.Write(w, binary.LittleEndian, s.Reserved2[:])
   561  		if err != nil {
   562  			return totalN, fmt.Errorf("unable to write field 'Reserved2': %w", err)
   563  		}
   564  		totalN += int64(n)
   565  	}
   566  
   567  	// Reserved3 (ManifestFieldType: arrayStatic)
   568  	{
   569  		n, err := 8, binary.Write(w, binary.LittleEndian, s.Reserved3[:])
   570  		if err != nil {
   571  			return totalN, fmt.Errorf("unable to write field 'Reserved3': %w", err)
   572  		}
   573  		totalN += int64(n)
   574  	}
   575  
   576  	// PostIBBHash (ManifestFieldType: subStruct)
   577  	{
   578  		n, err := s.PostIBBHash.WriteTo(w)
   579  		if err != nil {
   580  			return totalN, fmt.Errorf("unable to write field 'PostIBBHash': %w", err)
   581  		}
   582  		totalN += int64(n)
   583  	}
   584  
   585  	// IBBEntryPoint (ManifestFieldType: endValue)
   586  	{
   587  		n, err := 4, binary.Write(w, binary.LittleEndian, &s.IBBEntryPoint)
   588  		if err != nil {
   589  			return totalN, fmt.Errorf("unable to write field 'IBBEntryPoint': %w", err)
   590  		}
   591  		totalN += int64(n)
   592  	}
   593  
   594  	// Digest (ManifestFieldType: subStruct)
   595  	{
   596  		n, err := s.Digest.WriteTo(w)
   597  		if err != nil {
   598  			return totalN, fmt.Errorf("unable to write field 'Digest': %w", err)
   599  		}
   600  		totalN += int64(n)
   601  	}
   602  
   603  	// IBBSegments (ManifestFieldType: list)
   604  	{
   605  		count := uint8(len(s.IBBSegments))
   606  		err := binary.Write(w, binary.LittleEndian, &count)
   607  		if err != nil {
   608  			return totalN, fmt.Errorf("unable to write the count for field 'IBBSegments': %w", err)
   609  		}
   610  		totalN += int64(binary.Size(count))
   611  		for idx := range s.IBBSegments {
   612  			n, err := s.IBBSegments[idx].WriteTo(w)
   613  			if err != nil {
   614  				return totalN, fmt.Errorf("unable to write field 'IBBSegments[%d]': %w", idx, err)
   615  			}
   616  			totalN += int64(n)
   617  		}
   618  	}
   619  
   620  	return totalN, nil
   621  }
   622  
   623  // StructInfoSize returns the size in bytes of the value of field StructInfo
   624  func (s *SE) StructInfoTotalSize() uint64 {
   625  	return s.StructInfo.TotalSize()
   626  }
   627  
   628  // Reserved0Size returns the size in bytes of the value of field Reserved0
   629  func (s *SE) Reserved0TotalSize() uint64 {
   630  	return 1
   631  }
   632  
   633  // Reserved1Size returns the size in bytes of the value of field Reserved1
   634  func (s *SE) Reserved1TotalSize() uint64 {
   635  	return 1
   636  }
   637  
   638  // PBETValueSize returns the size in bytes of the value of field PBETValue
   639  func (s *SE) PBETValueTotalSize() uint64 {
   640  	return 1
   641  }
   642  
   643  // FlagsSize returns the size in bytes of the value of field Flags
   644  func (s *SE) FlagsTotalSize() uint64 {
   645  	return 4
   646  }
   647  
   648  // IBBMCHBARSize returns the size in bytes of the value of field IBBMCHBAR
   649  func (s *SE) IBBMCHBARTotalSize() uint64 {
   650  	return 8
   651  }
   652  
   653  // VTdBARSize returns the size in bytes of the value of field VTdBAR
   654  func (s *SE) VTdBARTotalSize() uint64 {
   655  	return 8
   656  }
   657  
   658  // PMRLBaseSize returns the size in bytes of the value of field PMRLBase
   659  func (s *SE) PMRLBaseTotalSize() uint64 {
   660  	return 4
   661  }
   662  
   663  // PMRLLimitSize returns the size in bytes of the value of field PMRLLimit
   664  func (s *SE) PMRLLimitTotalSize() uint64 {
   665  	return 4
   666  }
   667  
   668  // Reserved2Size returns the size in bytes of the value of field Reserved2
   669  func (s *SE) Reserved2TotalSize() uint64 {
   670  	return 8
   671  }
   672  
   673  // Reserved3Size returns the size in bytes of the value of field Reserved3
   674  func (s *SE) Reserved3TotalSize() uint64 {
   675  	return 8
   676  }
   677  
   678  // PostIBBHashSize returns the size in bytes of the value of field PostIBBHash
   679  func (s *SE) PostIBBHashTotalSize() uint64 {
   680  	return s.PostIBBHash.TotalSize()
   681  }
   682  
   683  // IBBEntryPointSize returns the size in bytes of the value of field IBBEntryPoint
   684  func (s *SE) IBBEntryPointTotalSize() uint64 {
   685  	return 4
   686  }
   687  
   688  // DigestSize returns the size in bytes of the value of field Digest
   689  func (s *SE) DigestTotalSize() uint64 {
   690  	return s.Digest.TotalSize()
   691  }
   692  
   693  // IBBSegmentsSize returns the size in bytes of the value of field IBBSegments
   694  func (s *SE) IBBSegmentsTotalSize() uint64 {
   695  	var size uint64
   696  	size += uint64(binary.Size(uint8(0)))
   697  	for idx := range s.IBBSegments {
   698  		size += s.IBBSegments[idx].TotalSize()
   699  	}
   700  	return size
   701  }
   702  
   703  // StructInfoOffset returns the offset in bytes of field StructInfo
   704  func (s *SE) StructInfoOffset() uint64 {
   705  	return 0
   706  }
   707  
   708  // Reserved0Offset returns the offset in bytes of field Reserved0
   709  func (s *SE) Reserved0Offset() uint64 {
   710  	return s.StructInfoOffset() + s.StructInfoTotalSize()
   711  }
   712  
   713  // Reserved1Offset returns the offset in bytes of field Reserved1
   714  func (s *SE) Reserved1Offset() uint64 {
   715  	return s.Reserved0Offset() + s.Reserved0TotalSize()
   716  }
   717  
   718  // PBETValueOffset returns the offset in bytes of field PBETValue
   719  func (s *SE) PBETValueOffset() uint64 {
   720  	return s.Reserved1Offset() + s.Reserved1TotalSize()
   721  }
   722  
   723  // FlagsOffset returns the offset in bytes of field Flags
   724  func (s *SE) FlagsOffset() uint64 {
   725  	return s.PBETValueOffset() + s.PBETValueTotalSize()
   726  }
   727  
   728  // IBBMCHBAROffset returns the offset in bytes of field IBBMCHBAR
   729  func (s *SE) IBBMCHBAROffset() uint64 {
   730  	return s.FlagsOffset() + s.FlagsTotalSize()
   731  }
   732  
   733  // VTdBAROffset returns the offset in bytes of field VTdBAR
   734  func (s *SE) VTdBAROffset() uint64 {
   735  	return s.IBBMCHBAROffset() + s.IBBMCHBARTotalSize()
   736  }
   737  
   738  // PMRLBaseOffset returns the offset in bytes of field PMRLBase
   739  func (s *SE) PMRLBaseOffset() uint64 {
   740  	return s.VTdBAROffset() + s.VTdBARTotalSize()
   741  }
   742  
   743  // PMRLLimitOffset returns the offset in bytes of field PMRLLimit
   744  func (s *SE) PMRLLimitOffset() uint64 {
   745  	return s.PMRLBaseOffset() + s.PMRLBaseTotalSize()
   746  }
   747  
   748  // Reserved2Offset returns the offset in bytes of field Reserved2
   749  func (s *SE) Reserved2Offset() uint64 {
   750  	return s.PMRLLimitOffset() + s.PMRLLimitTotalSize()
   751  }
   752  
   753  // Reserved3Offset returns the offset in bytes of field Reserved3
   754  func (s *SE) Reserved3Offset() uint64 {
   755  	return s.Reserved2Offset() + s.Reserved2TotalSize()
   756  }
   757  
   758  // PostIBBHashOffset returns the offset in bytes of field PostIBBHash
   759  func (s *SE) PostIBBHashOffset() uint64 {
   760  	return s.Reserved3Offset() + s.Reserved3TotalSize()
   761  }
   762  
   763  // IBBEntryPointOffset returns the offset in bytes of field IBBEntryPoint
   764  func (s *SE) IBBEntryPointOffset() uint64 {
   765  	return s.PostIBBHashOffset() + s.PostIBBHashTotalSize()
   766  }
   767  
   768  // DigestOffset returns the offset in bytes of field Digest
   769  func (s *SE) DigestOffset() uint64 {
   770  	return s.IBBEntryPointOffset() + s.IBBEntryPointTotalSize()
   771  }
   772  
   773  // IBBSegmentsOffset returns the offset in bytes of field IBBSegments
   774  func (s *SE) IBBSegmentsOffset() uint64 {
   775  	return s.DigestOffset() + s.DigestTotalSize()
   776  }
   777  
   778  // Size returns the total size of the SE.
   779  func (s *SE) TotalSize() uint64 {
   780  	if s == nil {
   781  		return 0
   782  	}
   783  
   784  	var size uint64
   785  	size += s.StructInfoTotalSize()
   786  	size += s.Reserved0TotalSize()
   787  	size += s.Reserved1TotalSize()
   788  	size += s.PBETValueTotalSize()
   789  	size += s.FlagsTotalSize()
   790  	size += s.IBBMCHBARTotalSize()
   791  	size += s.VTdBARTotalSize()
   792  	size += s.PMRLBaseTotalSize()
   793  	size += s.PMRLLimitTotalSize()
   794  	size += s.Reserved2TotalSize()
   795  	size += s.Reserved3TotalSize()
   796  	size += s.PostIBBHashTotalSize()
   797  	size += s.IBBEntryPointTotalSize()
   798  	size += s.DigestTotalSize()
   799  	size += s.IBBSegmentsTotalSize()
   800  	return size
   801  }
   802  
   803  // PrettyString returns the content of the structure in an easy-to-read format.
   804  func (s *SE) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
   805  	var lines []string
   806  	if withHeader {
   807  		lines = append(lines, pretty.Header(depth, "IBB Segments Element", s))
   808  	}
   809  	if s == nil {
   810  		return strings.Join(lines, "\n")
   811  	}
   812  	// ManifestFieldType is structInfo
   813  	lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...)
   814  	// ManifestFieldType is arrayStatic
   815  	lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", &s.Reserved0, opts...)...)
   816  	// ManifestFieldType is arrayStatic
   817  	lines = append(lines, pretty.SubValue(depth+1, "Reserved 1", "", &s.Reserved1, opts...)...)
   818  	// ManifestFieldType is endValue
   819  	lines = append(lines, pretty.SubValue(depth+1, "PBET Value", "", &s.PBETValue, opts...)...)
   820  	// ManifestFieldType is endValue
   821  	lines = append(lines, pretty.SubValue(depth+1, "Flags", "", &s.Flags, opts...)...)
   822  	// ManifestFieldType is endValue
   823  	lines = append(lines, pretty.SubValue(depth+1, "IBB MCHBAR", "", &s.IBBMCHBAR, opts...)...)
   824  	// ManifestFieldType is endValue
   825  	lines = append(lines, pretty.SubValue(depth+1, "VT-d BAR", "", &s.VTdBAR, opts...)...)
   826  	// ManifestFieldType is endValue
   827  	lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 0 Base Address", "", &s.PMRLBase, opts...)...)
   828  	// ManifestFieldType is endValue
   829  	lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 0 Limit Address", "", &s.PMRLLimit, opts...)...)
   830  	// ManifestFieldType is arrayStatic
   831  	lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 1 Base Address", "", &s.Reserved2, opts...)...)
   832  	// ManifestFieldType is arrayStatic
   833  	lines = append(lines, pretty.SubValue(depth+1, "DMA Protection 2 Limit Address", "", &s.Reserved3, opts...)...)
   834  	// ManifestFieldType is subStruct
   835  	lines = append(lines, pretty.SubValue(depth+1, "Post IBB Hash", "", &s.PostIBBHash, opts...)...)
   836  	// ManifestFieldType is endValue
   837  	lines = append(lines, pretty.SubValue(depth+1, "IBB Entry Point", "", &s.IBBEntryPoint, opts...)...)
   838  	// ManifestFieldType is subStruct
   839  	lines = append(lines, pretty.SubValue(depth+1, "Digest", "", &s.Digest, opts...)...)
   840  	// ManifestFieldType is list
   841  	lines = append(lines, pretty.Header(depth+1, fmt.Sprintf("IBBSegments: Array of \"IBB Segments Element\" of length %d", len(s.IBBSegments)), s.IBBSegments))
   842  	for i := 0; i < len(s.IBBSegments); i++ {
   843  		lines = append(lines, fmt.Sprintf("%sitem #%d: ", strings.Repeat("  ", int(depth+2)), i)+strings.TrimSpace(s.IBBSegments[i].PrettyString(depth+2, true)))
   844  	}
   845  	if depth < 1 {
   846  		lines = append(lines, "")
   847  	}
   848  	if depth < 2 {
   849  		lines = append(lines, "")
   850  	}
   851  	return strings.Join(lines, "\n")
   852  }
   853  
   854  // PrettyString returns the bits of the flags in an easy-to-read format.
   855  func (v CachingType) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
   856  	return v.String()
   857  }
   858  
   859  // TotalSize returns the total size measured through binary.Size.
   860  func (v CachingType) TotalSize() uint64 {
   861  	return uint64(binary.Size(v))
   862  }
   863  
   864  // WriteTo writes the CachingType into 'w' in binary format.
   865  func (v CachingType) WriteTo(w io.Writer) (int64, error) {
   866  	return int64(v.TotalSize()), binary.Write(w, binary.LittleEndian, v)
   867  }
   868  
   869  // ReadFrom reads the CachingType from 'r' in binary format.
   870  func (v CachingType) ReadFrom(r io.Reader) (int64, error) {
   871  	return int64(v.TotalSize()), binary.Read(r, binary.LittleEndian, v)
   872  }
   873  
   874  // PrettyString returns the bits of the flags in an easy-to-read format.
   875  func (v PBETValue) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
   876  	var lines []string
   877  	if withHeader {
   878  		lines = append(lines, pretty.Header(depth, "PBET Value", v))
   879  	}
   880  	lines = append(lines, pretty.SubValue(depth+1, "PBET Value", "", v.PBETValue(), opts...)...)
   881  	return strings.Join(lines, "\n")
   882  }
   883  
   884  // TotalSize returns the total size measured through binary.Size.
   885  func (v PBETValue) TotalSize() uint64 {
   886  	return uint64(binary.Size(v))
   887  }
   888  
   889  // WriteTo writes the PBETValue into 'w' in binary format.
   890  func (v PBETValue) WriteTo(w io.Writer) (int64, error) {
   891  	return int64(v.TotalSize()), binary.Write(w, binary.LittleEndian, v)
   892  }
   893  
   894  // ReadFrom reads the PBETValue from 'r' in binary format.
   895  func (v PBETValue) ReadFrom(r io.Reader) (int64, error) {
   896  	return int64(v.TotalSize()), binary.Read(r, binary.LittleEndian, v)
   897  }
   898  
   899  // PrettyString returns the bits of the flags in an easy-to-read format.
   900  func (v SEFlags) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string {
   901  	var lines []string
   902  	if withHeader {
   903  		lines = append(lines, pretty.Header(depth, "SE Flags", v))
   904  	}
   905  	lines = append(lines, pretty.SubValue(depth+1, "Reserved 0", "", v.Reserved0(), opts...)...)
   906  	if v.SupportsTopSwapRemediation() {
   907  		lines = append(lines, pretty.SubValue(depth+1, "Supports Top Swap Remediation", "BIOS supports Top Swap remediation action", true, opts...)...)
   908  	} else {
   909  		lines = append(lines, pretty.SubValue(depth+1, "Supports Top Swap Remediation", "BIOS does not support Top Swap remediation action", false, opts...)...)
   910  	}
   911  	if v.TPMFailureLeavesHierarchiesEnabled() {
   912  		lines = append(lines, pretty.SubValue(depth+1, "TPM Failure Leaves Hierarchies Enabled", "Leave Hierarchies enabled. Cap all PCRs on failure.", true, opts...)...)
   913  	} else {
   914  		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...)...)
   915  	}
   916  	if v.AuthorityMeasure() {
   917  		lines = append(lines, pretty.SubValue(depth+1, "Authority Measure", "Extend Authority Measurements into the Authority PCR 7", true, opts...)...)
   918  	} else {
   919  		lines = append(lines, pretty.SubValue(depth+1, "Authority Measure", "Do not extend into the Authority PCR 7", false, opts...)...)
   920  	}
   921  	if v.Locality3Startup() {
   922  		lines = append(lines, pretty.SubValue(depth+1, "Locality 3 Startup", "Issue TPM Start-up from Locality 3", true, opts...)...)
   923  	} else {
   924  		lines = append(lines, pretty.SubValue(depth+1, "Locality 3 Startup", "Disabled", false, opts...)...)
   925  	}
   926  	if v.DMAProtection() {
   927  		lines = append(lines, pretty.SubValue(depth+1, "DMA Protection", "Enable DMA Protection", true, opts...)...)
   928  	} else {
   929  		lines = append(lines, pretty.SubValue(depth+1, "DMA Protection", "Disable DMA Protection", false, opts...)...)
   930  	}
   931  	return strings.Join(lines, "\n")
   932  }
   933  
   934  // TotalSize returns the total size measured through binary.Size.
   935  func (v SEFlags) TotalSize() uint64 {
   936  	return uint64(binary.Size(v))
   937  }
   938  
   939  // WriteTo writes the SEFlags into 'w' in binary format.
   940  func (v SEFlags) WriteTo(w io.Writer) (int64, error) {
   941  	return int64(v.TotalSize()), binary.Write(w, binary.LittleEndian, v)
   942  }
   943  
   944  // ReadFrom reads the SEFlags from 'r' in binary format.
   945  func (v SEFlags) ReadFrom(r io.Reader) (int64, error) {
   946  	return int64(v.TotalSize()), binary.Read(r, binary.LittleEndian, v)
   947  }