diff --git a/pkg/edit/cdx_edit.go b/pkg/edit/cdx_edit.go index bba1a61..03209a9 100644 --- a/pkg/edit/cdx_edit.go +++ b/pkg/edit/cdx_edit.go @@ -67,7 +67,21 @@ func (d *cdxEditDoc) update() { } func (d *cdxEditDoc) timeStamp() error { - d.bom.Metadata.Timestamp = utcNowTime() + if !d.c.shouldTimeStamp() { + return errNoConfiguration + } + + if d.c.search.subject != "document" { + return errNotSupported + } + + if d.c.onMissing() { + if d.bom.Metadata.Timestamp == "" { + d.bom.Metadata.Timestamp = utcNowTime() + } + } else { + d.bom.Metadata.Timestamp = utcNowTime() + } return nil } diff --git a/pkg/edit/spdx_edit.go b/pkg/edit/spdx_edit.go index 57144a9..9396e74 100644 --- a/pkg/edit/spdx_edit.go +++ b/pkg/edit/spdx_edit.go @@ -543,12 +543,29 @@ func (d *spdxEditDoc) typ() error { } func (d *spdxEditDoc) timeStamp() error { - if d.bom.CreationInfo == nil { - d.bom.CreationInfo = &spdx.CreationInfo{} + if !d.c.shouldTimeStamp() { + return errNoConfiguration } - d.bom.CreationInfo.Created = utcNowTime() + if d.c.search.subject != "document" { + return errNotSupported + } + + if d.c.onMissing() { + if d.bom.CreationInfo == nil { + d.bom.CreationInfo = &spdx.CreationInfo{} + } + + if d.bom.CreationInfo.Created == "" { + d.bom.CreationInfo.Created = utcNowTime() + } + } else { + if d.bom.CreationInfo == nil { + d.bom.CreationInfo = &spdx.CreationInfo{} + } + d.bom.CreationInfo.Created = utcNowTime() + } return nil }