diff options
author | Keith Zantow <kzantow@gmail.com> | 2022-10-07 15:36:32 -0400 |
---|---|---|
committer | Keith Zantow <kzantow@gmail.com> | 2022-10-07 15:36:32 -0400 |
commit | b57c493f0652477bf3764be7273eab6ff11d1eb1 (patch) | |
tree | 2ce0bc41c7f9b6c9a40715565c49c1cbf190716d /builder/builder2v3/build_file.go | |
parent | be2eb824595afe28c87c9a33c2da565480d1eb54 (diff) | |
download | spdx-tools-b57c493f0652477bf3764be7273eab6ff11d1eb1.tar.gz |
chore: add builder and verification functions for 2.3
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Diffstat (limited to 'builder/builder2v3/build_file.go')
-rw-r--r-- | builder/builder2v3/build_file.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/builder/builder2v3/build_file.go b/builder/builder2v3/build_file.go new file mode 100644 index 0000000..bce8e66 --- /dev/null +++ b/builder/builder2v3/build_file.go @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package builder2v3 + +import ( + "fmt" + "path/filepath" + + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_3" + "github.com/spdx/tools-golang/utils" +) + +// BuildFileSection2_3 creates an SPDX File (version 2.3), returning that +// file or error if any is encountered. Arguments: +// - filePath: path to file, relative to prefix +// - prefix: relative directory for filePath +// - fileNumber: integer index (unique within package) to use in identifier +func BuildFileSection2_3(filePath string, prefix string, fileNumber int) (*v2_3.File, error) { + // build the full file path + p := filepath.Join(prefix, filePath) + + // make sure we can get the file and its hashes + ssha1, ssha256, smd5, err := utils.GetHashesForFilePath(p) + if err != nil { + return nil, err + } + + // build the identifier + i := fmt.Sprintf("File%d", fileNumber) + + // now build the File section + f := &v2_3.File{ + FileName: filePath, + FileSPDXIdentifier: common.ElementID(i), + Checksums: []common.Checksum{ + { + Algorithm: common.SHA1, + Value: ssha1, + }, + { + Algorithm: common.SHA256, + Value: ssha256, + }, + { + Algorithm: common.MD5, + Value: smd5, + }, + }, + LicenseConcluded: "NOASSERTION", + LicenseInfoInFiles: []string{"NOASSERTION"}, + FileCopyrightText: "NOASSERTION", + } + + return f, nil +} |