@@ -8,39 +8,31 @@ import (
88 "github.com/sigstore/sigstore-go/pkg/bundle"
99)
1010
11- // ExtractSubjectFromBundle extracts subject information from a parsed bundle
1211func ExtractSubjectFromBundle (b * bundle.Bundle ) (repoPath string , err error ) {
13- // Get DSSE envelope
1412 envelope , err := GetDSSEEnvelope (b )
1513 if err != nil {
1614 return "" , err
1715 }
1816
19- // Extract subject from envelope
2017 return extractSubjectFromEnvelope (envelope )
2118}
2219
23- // extractSubjectFromEnvelope extracts subject information from a protobuf DSSE envelope
2420func extractSubjectFromEnvelope (envelope * protodsse.Envelope ) (repoPath string , err error ) {
2521 if envelope == nil {
2622 return "" , errorutils .CheckErrorf ("envelope is nil" )
2723 }
2824
29- // Parse the payload as In-toto statement
3025 var statement map [string ]interface {}
3126 if err := json .Unmarshal (envelope .Payload , & statement ); err != nil {
3227 return "" , errorutils .CheckErrorf ("failed to parse statement from DSSE payload: %s" , err .Error ())
3328 }
3429
35- // Try to extract repo path from the statement
3630 repoPath = extractRepoPathFromStatement (statement )
3731
3832 return repoPath , nil
3933}
4034
41- // extractRepoPathFromStatement attempts to extract repo path from various fields in the statement
4235func extractRepoPathFromStatement (statement map [string ]interface {}) string {
43- // Try to get from subject name first
4436 if subjects , ok := statement ["subject" ].([]interface {}); ok && len (subjects ) > 0 {
4537 if subject , ok := subjects [0 ].(map [string ]interface {}); ok {
4638 if name , ok := subject ["name" ].(string ); ok && name != "" {
@@ -49,9 +41,7 @@ func extractRepoPathFromStatement(statement map[string]interface{}) string {
4941 }
5042 }
5143
52- // Try to extract from predicate
5344 if predicate , ok := statement ["predicate" ].(map [string ]interface {}); ok {
54- // Check artifact field
5545 if artifact , ok := predicate ["artifact" ].(map [string ]interface {}); ok {
5646 if path , ok := artifact ["path" ].(string ); ok && path != "" {
5747 return path
@@ -61,7 +51,6 @@ func extractRepoPathFromStatement(statement map[string]interface{}) string {
6151 }
6252 }
6353
64- // Check subject field in predicate
6554 if subject , ok := predicate ["subject" ].(map [string ]interface {}); ok {
6655 if path , ok := subject ["path" ].(string ); ok && path != "" {
6756 return path
@@ -71,7 +60,6 @@ func extractRepoPathFromStatement(statement map[string]interface{}) string {
7160 }
7261 }
7362
74- // Check materials field (SLSA predicates)
7563 if materials , ok := predicate ["materials" ].([]interface {}); ok && len (materials ) > 0 {
7664 if material , ok := materials [0 ].(map [string ]interface {}); ok {
7765 if uri , ok := material ["uri" ].(string ); ok && uri != "" {
0 commit comments