github.com/linuxboot/fiano@v1.2.0/pkg/intel/metadata/cbnt/cbntbootpolicy/Reserved_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 github.com/linuxboot/fiano/pkg/intel/metadata/cbnt/cbntbootpolicy 10 11 package cbntbootpolicy 12 13 import ( 14 "encoding/binary" 15 "fmt" 16 "io" 17 "strings" 18 19 "github.com/linuxboot/fiano/pkg/intel/metadata/cbnt" 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 _ = cbnt.StructInfo{} 31 ) 32 33 // NewReserved returns a new instance of Reserved with 34 // all default values set. 35 func NewReserved() *Reserved { 36 s := &Reserved{} 37 copy(s.StructInfo.ID[:], []byte(StructureIDReserved)) 38 s.StructInfo.Version = 0x21 39 s.Rehash() 40 return s 41 } 42 43 // Validate (recursively) checks the structure if there are any unexpected 44 // values. It returns an error if so. 45 func (s *Reserved) Validate() error { 46 47 return nil 48 } 49 50 // StructureIDReserved is the StructureID (in terms of 51 // the document #575623) of element 'Reserved'. 52 const StructureIDReserved = "__PFRS__" 53 54 // GetStructInfo returns current value of StructInfo of the structure. 55 // 56 // StructInfo is a set of standard fields with presented in any element 57 // ("element" in terms of document #575623). 58 func (s *Reserved) GetStructInfo() cbnt.StructInfo { 59 return s.StructInfo 60 } 61 62 // SetStructInfo sets new value of StructInfo to the structure. 63 // 64 // StructInfo is a set of standard fields with presented in any element 65 // ("element" in terms of document #575623). 66 func (s *Reserved) SetStructInfo(newStructInfo cbnt.StructInfo) { 67 s.StructInfo = newStructInfo 68 } 69 70 // ReadFrom reads the Reserved from 'r' in format defined in the document #575623. 71 func (s *Reserved) ReadFrom(r io.Reader) (int64, error) { 72 var totalN int64 73 74 err := binary.Read(r, binary.LittleEndian, &s.StructInfo) 75 if err != nil { 76 return totalN, fmt.Errorf("unable to read structure info at %d: %w", totalN, err) 77 } 78 totalN += int64(binary.Size(s.StructInfo)) 79 80 n, err := s.ReadDataFrom(r) 81 if err != nil { 82 return totalN, fmt.Errorf("unable to read data: %w", err) 83 } 84 totalN += n 85 86 return totalN, nil 87 } 88 89 // ReadDataFrom reads the Reserved from 'r' excluding StructInfo, 90 // in format defined in the document #575623. 91 func (s *Reserved) ReadDataFrom(r io.Reader) (int64, error) { 92 totalN := int64(0) 93 94 // StructInfo (ManifestFieldType: structInfo) 95 { 96 // ReadDataFrom does not read Struct, use ReadFrom for that. 97 } 98 99 // ReservedData (ManifestFieldType: arrayStatic) 100 { 101 n, err := 32, binary.Read(r, binary.LittleEndian, s.ReservedData[:]) 102 if err != nil { 103 return totalN, fmt.Errorf("unable to read field 'ReservedData': %w", err) 104 } 105 totalN += int64(n) 106 } 107 108 return totalN, nil 109 } 110 111 // RehashRecursive calls Rehash (see below) recursively. 112 func (s *Reserved) RehashRecursive() { 113 s.StructInfo.Rehash() 114 s.Rehash() 115 } 116 117 // Rehash sets values which are calculated automatically depending on the rest 118 // data. It is usually about the total size field of an element. 119 func (s *Reserved) Rehash() { 120 s.Variable0 = 0 121 s.ElementSize = uint16(s.TotalSize()) 122 } 123 124 // WriteTo writes the Reserved into 'w' in format defined in 125 // the document #575623. 126 func (s *Reserved) WriteTo(w io.Writer) (int64, error) { 127 totalN := int64(0) 128 s.Rehash() 129 130 // StructInfo (ManifestFieldType: structInfo) 131 { 132 n, err := s.StructInfo.WriteTo(w) 133 if err != nil { 134 return totalN, fmt.Errorf("unable to write field 'StructInfo': %w", err) 135 } 136 totalN += int64(n) 137 } 138 139 // ReservedData (ManifestFieldType: arrayStatic) 140 { 141 n, err := 32, binary.Write(w, binary.LittleEndian, s.ReservedData[:]) 142 if err != nil { 143 return totalN, fmt.Errorf("unable to write field 'ReservedData': %w", err) 144 } 145 totalN += int64(n) 146 } 147 148 return totalN, nil 149 } 150 151 // StructInfoSize returns the size in bytes of the value of field StructInfo 152 func (s *Reserved) StructInfoTotalSize() uint64 { 153 return s.StructInfo.TotalSize() 154 } 155 156 // ReservedDataSize returns the size in bytes of the value of field ReservedData 157 func (s *Reserved) ReservedDataTotalSize() uint64 { 158 return 32 159 } 160 161 // StructInfoOffset returns the offset in bytes of field StructInfo 162 func (s *Reserved) StructInfoOffset() uint64 { 163 return 0 164 } 165 166 // ReservedDataOffset returns the offset in bytes of field ReservedData 167 func (s *Reserved) ReservedDataOffset() uint64 { 168 return s.StructInfoOffset() + s.StructInfoTotalSize() 169 } 170 171 // Size returns the total size of the Reserved. 172 func (s *Reserved) TotalSize() uint64 { 173 if s == nil { 174 return 0 175 } 176 177 var size uint64 178 size += s.StructInfoTotalSize() 179 size += s.ReservedDataTotalSize() 180 return size 181 } 182 183 // PrettyString returns the content of the structure in an easy-to-read format. 184 func (s *Reserved) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string { 185 var lines []string 186 if withHeader { 187 lines = append(lines, pretty.Header(depth, "Reserved", s)) 188 } 189 if s == nil { 190 return strings.Join(lines, "\n") 191 } 192 // ManifestFieldType is structInfo 193 lines = append(lines, pretty.SubValue(depth+1, "Struct Info", "", &s.StructInfo, opts...)...) 194 // ManifestFieldType is arrayStatic 195 lines = append(lines, pretty.SubValue(depth+1, "Reserved Data", "", &s.ReservedData, opts...)...) 196 if depth < 2 { 197 lines = append(lines, "") 198 } 199 return strings.Join(lines, "\n") 200 }