streamline int overflow check for token timestamps
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package parse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/ucan-wg/go-ucan/did"
|
||||
"github.com/ucan-wg/go-ucan/pkg/policy/limits"
|
||||
)
|
||||
|
||||
func OptionalDID(s *string) (did.DID, error) {
|
||||
@@ -13,10 +15,15 @@ func OptionalDID(s *string) (did.DID, error) {
|
||||
return did.Parse(*s)
|
||||
}
|
||||
|
||||
func OptionalTimestamp(sec *int64) *time.Time {
|
||||
func OptionalTimestamp(sec *int64) (*time.Time, error) {
|
||||
if sec == nil {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if *sec > limits.MaxInt53 || *sec < limits.MinInt53 {
|
||||
return nil, fmt.Errorf("timestamp value %d exceeds safe integer bounds", *sec)
|
||||
}
|
||||
|
||||
t := time.Unix(*sec, 0)
|
||||
return &t
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user