Skip to content

Commit

Permalink
addressed feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
  • Loading branch information
Pritesh Bandi committed Dec 1, 2022
1 parent a782858 commit 6b96103
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ type Signer interface {
func Sign(ctx context.Context, signer Signer, repo registry.Repository, opts SignOptions) (ocispec.Descriptor, error) {
// Input validation for expiry duration
if opts.ExpiryDuration != nil {
expDurInSec := opts.ExpiryDuration.Seconds()
if expDurInSec != float64(int64(expDurInSec)) {
if *opts.ExpiryDuration % time.Second != 0 {
return ocispec.Descriptor{}, fmt.Errorf("expiry duration supports minimum granularity of second")
}
if expDurInSec <= 0 {

if *opts.ExpiryDuration <= 0 {
return ocispec.Descriptor{}, fmt.Errorf("expiry duration cannot be zero or negative")
}
}
Expand Down
3 changes: 2 additions & 1 deletion signer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"time"

"github.com/notaryproject/notation-core-go/signature"
"github.com/notaryproject/notation-go"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (s *pluginSigner) generateSignatureEnvelope(ctx context.Context, desc ocisp

if opts.ExpiryDuration != nil {
// expiry duration will always be a positive value
req.ExpiryDurationInSeconds = uint64(opts.ExpiryDuration.Seconds())
req.ExpiryDurationInSeconds = uint64(*opts.ExpiryDuration / time.Second)
}

resp, err := s.plugin.GenerateEnvelope(ctx, req)
Expand Down

0 comments on commit 6b96103

Please sign in to comment.