Files
ucan/token/internal/parse/parse.go

30 lines
518 B
Go
Raw Normal View History

2024-11-05 17:39:39 +01:00
package parse
import (
"fmt"
2024-11-05 17:39:39 +01:00
"time"
"github.com/ucan-wg/go-ucan/did"
"github.com/ucan-wg/go-ucan/pkg/policy/limits"
2024-11-05 17:39:39 +01:00
)
func OptionalDID(s *string) (did.DID, error) {
if s == nil {
return did.Undef, nil
}
return did.Parse(*s)
}
func OptionalTimestamp(sec *int64) (*time.Time, error) {
2024-11-05 17:39:39 +01:00
if sec == nil {
return nil, nil
2024-11-05 17:39:39 +01:00
}
if *sec > limits.MaxInt53 || *sec < limits.MinInt53 {
return nil, fmt.Errorf("timestamp value %d exceeds safe integer bounds", *sec)
}
2024-11-05 17:39:39 +01:00
t := time.Unix(*sec, 0)
return &t, nil
2024-11-05 17:39:39 +01:00
}