@@ -24,7 +24,7 @@ import (
2424
2525 pb "github.com/google/go-sev-guest/proto/sevsnp"
2626 "github.com/google/logger"
27- "github.com/pborman /uuid"
27+ "github.com/google /uuid"
2828 "golang.org/x/crypto/cryptobyte"
2929 "golang.org/x/crypto/cryptobyte/asn1"
3030 "google.golang.org/protobuf/types/known/wrapperspb"
@@ -710,7 +710,7 @@ func (h *CertTableHeaderEntry) Unmarshal(data []byte) error {
710710 if len (data ) < CertTableEntrySize {
711711 return fmt .Errorf ("data too small: %v, want %v" , len (data ), CertTableEntrySize )
712712 }
713- h .GUID = clone ( data [0 :GUIDSize ])
713+ copy ( h .GUID [:], data [0 :GUIDSize ])
714714 uint32Size := 4
715715 h .Offset = binary .LittleEndian .Uint32 (data [GUIDSize : GUIDSize + uint32Size ])
716716 h .Length = binary .LittleEndian .Uint32 (data [GUIDSize + uint32Size : CertTableEntrySize ])
@@ -774,8 +774,7 @@ func (c *CertTable) Unmarshal(certs []byte) error {
774774 }
775775 for i , entry := range certTableHeader {
776776 var next CertTableEntry
777- next .GUID = make ([]byte , GUIDSize )
778- copy (next .GUID , entry .GUID )
777+ copy (next .GUID [:], entry .GUID [:])
779778 if entry .Offset + entry .Length > uint32 (len (certs )) {
780779 return fmt .Errorf ("cert table entry %d specifies a byte range outside the certificate data block (size %d): offset=%d, length%d" , i , len (certs ), entry .Offset , entry .Length )
781780 }
@@ -789,12 +788,12 @@ func (c *CertTable) Unmarshal(certs []byte) error {
789788// GetByGUIDString returns the raw bytes for a certificate that matches a key identified by the
790789// given GUID string.
791790func (c * CertTable ) GetByGUIDString (guid string ) ([]byte , error ) {
792- g := uuid .Parse (guid )
793- if g = = nil {
794- return nil , fmt . Errorf ( "GUID string format is XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXXX, got %s" , guid )
791+ g , err := uuid .Parse (guid )
792+ if err ! = nil {
793+ return nil , err
795794 }
796795 for _ , entry := range c .Entries {
797- if uuid . Equal ( entry .GUID , g ) {
796+ if entry .GUID == g {
798797 return entry .RawCert , nil
799798 }
800799 }
@@ -806,23 +805,23 @@ func CertsFromProto(chain *pb.CertificateChain) *CertTable {
806805 c := & CertTable {}
807806 if len (chain .GetArkCert ()) != 0 {
808807 c .Entries = append (c .Entries ,
809- CertTableEntry {GUID : uuid .Parse (ArkGUID ), RawCert : chain .GetArkCert ()})
808+ CertTableEntry {GUID : uuid .MustParse (ArkGUID ), RawCert : chain .GetArkCert ()})
810809 }
811810 if len (chain .GetAskCert ()) != 0 {
812811 c .Entries = append (c .Entries ,
813- CertTableEntry {GUID : uuid .Parse (AskGUID ), RawCert : chain .GetAskCert ()})
812+ CertTableEntry {GUID : uuid .MustParse (AskGUID ), RawCert : chain .GetAskCert ()})
814813 }
815814 if len (chain .GetVcekCert ()) != 0 {
816815 c .Entries = append (c .Entries ,
817- CertTableEntry {GUID : uuid .Parse (VcekGUID ), RawCert : chain .GetVcekCert ()})
816+ CertTableEntry {GUID : uuid .MustParse (VcekGUID ), RawCert : chain .GetVcekCert ()})
818817 }
819818 if len (chain .GetVlekCert ()) != 0 {
820819 c .Entries = append (c .Entries ,
821- CertTableEntry {GUID : uuid .Parse (VlekGUID ), RawCert : chain .GetVlekCert ()})
820+ CertTableEntry {GUID : uuid .MustParse (VlekGUID ), RawCert : chain .GetVlekCert ()})
822821 }
823822 for guid , cert := range chain .GetExtras () {
824823 c .Entries = append (c .Entries ,
825- CertTableEntry {GUID : uuid .Parse (guid ), RawCert : cert })
824+ CertTableEntry {GUID : uuid .MustParse (guid ), RawCert : cert })
826825 }
827826 return c
828827}
@@ -854,20 +853,20 @@ func (c *CertTable) Marshal() []byte {
854853// so missing certificates aren't an error. If certificates are missing, you can
855854// choose to fetch them yourself by calling verify.GetAttestationFromReport.
856855func (c * CertTable ) Proto () * pb.CertificateChain {
857- vcekGUID := uuid .Parse (VcekGUID )
858- vlekGUID := uuid .Parse (VlekGUID )
859- askGUID := uuid .Parse (AskGUID )
860- arkGUID := uuid .Parse (ArkGUID )
856+ vcekGUID := uuid .MustParse (VcekGUID )
857+ vlekGUID := uuid .MustParse (VlekGUID )
858+ askGUID := uuid .MustParse (AskGUID )
859+ arkGUID := uuid .MustParse (ArkGUID )
861860 result := & pb.CertificateChain {Extras : make (map [string ][]byte )}
862861 for _ , entry := range c .Entries {
863862 switch {
864- case uuid . Equal ( entry .GUID , vcekGUID ) :
863+ case entry .GUID == vcekGUID :
865864 result .VcekCert = entry .RawCert
866- case uuid . Equal ( entry .GUID , vlekGUID ) :
865+ case entry .GUID == vlekGUID :
867866 result .VlekCert = entry .RawCert
868- case uuid . Equal ( entry .GUID , askGUID ) :
867+ case entry .GUID == askGUID :
869868 result .AskCert = entry .RawCert
870- case uuid . Equal ( entry .GUID , arkGUID ) :
869+ case entry .GUID == arkGUID :
871870 result .ArkCert = entry .RawCert
872871 default :
873872 result .Extras [entry .GUID .String ()] = entry .RawCert
@@ -1026,7 +1025,7 @@ func ExtendPlatformCertTable(data []byte, info *ExtraPlatformInfo) ([]byte, erro
10261025 return nil , fmt .Errorf ("could not marshal ExtraPlatformInfo: %v" , err )
10271026 }
10281027 certs .Entries = append (certs .Entries , CertTableEntry {
1029- GUID : uuid .Parse (ExtraPlatformInfoGUID ),
1028+ GUID : uuid .MustParse (ExtraPlatformInfoGUID ),
10301029 RawCert : extra ,
10311030 })
10321031 return certs .Marshal (), nil
0 commit comments