github.com/anchore/syft@v1.38.2/syft/file/license.go (about) 1 package file 2 3 import ( 4 "github.com/anchore/syft/internal/log" 5 "github.com/anchore/syft/syft/license" 6 ) 7 8 // License represents license information discovered within a file. 9 type License struct { 10 // Value is the raw license string as found in the file. 11 Value string 12 13 // SPDXExpression is the parsed SPDX license expression if available. 14 SPDXExpression string 15 16 // Type categorizes how the license was determined (e.g., declared, concluded -- following the same semantics as SPDX). 17 Type license.Type 18 19 LicenseEvidence *LicenseEvidence 20 21 // Contents optionally stores the full license text. 22 Contents string `hash:"ignore"` 23 } 24 25 // LicenseEvidence contains details from license classifier analysis. 26 type LicenseEvidence struct { 27 // Confidence is a score indicating certainty of the license match. 28 Confidence int 29 30 // Offset is the byte position where the license text begins in the file. 31 Offset int 32 33 // Extent is the length in bytes of the matched license text. 34 Extent int 35 } 36 37 func NewLicense(value string) License { 38 spdxExpression, err := license.ParseExpression(value) 39 if err != nil { 40 log.WithFields("error", err, "value", value).Trace("unable to parse license expression") 41 } 42 43 return License{ 44 Value: value, 45 SPDXExpression: spdxExpression, 46 Type: license.Concluded, 47 } 48 }