wip API exploration

This commit is contained in:
Michael Muré
2024-10-18 10:48:47 +02:00
parent 9057cbcba6
commit 89e4d5d419
4 changed files with 69 additions and 6 deletions

View File

@@ -153,6 +153,24 @@ func (t *Token) Expiration() *time.Time {
return t.expiration
}
// IsValidNow verifies that the token can be used at the current time, based on expiration or "not before" fields.
// This does NOT do any other kind of verifications.
func (t *Token) IsValidNow() bool {
return t.IsValidAt(time.Now())
}
// IsValidNow verifies that the token can be used at the given time, based on expiration or "not before" fields.
// This does NOT do any other kind of verifications.
func (t *Token) IsValidAt(ti time.Time) bool {
if t.expiration == nil && ti.After(*t.expiration) {
return false
}
if t.notBefore != nil && ti.Before(*t.notBefore) {
return false
}
return true
}
func (t *Token) validate() error {
var errs error