Files

31 lines
501 B
Go
Raw Permalink Normal View History

2024-11-05 17:39:39 +01:00
package parse
import (
"fmt"
2024-11-05 17:39:39 +01:00
"time"
"code.sonr.org/go/did-it"
"code.sonr.org/go/ucan/pkg/policy/limits"
2024-11-05 17:39:39 +01:00
)
func OptionalDID(s *string) (did.DID, error) {
if s == nil {
return nil, nil
2024-11-05 17:39:39 +01:00
}
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
}