ExpiresAt returns the expiration time of the license. If the claim is missing or has an unexpected type, an error is returned.
()
| 37 | // ExpiresAt returns the expiration time of the license. |
| 38 | // If the claim is missing or has an unexpected type, an error is returned. |
| 39 | func (l *License) ExpiresAt() (time.Time, error) { |
| 40 | expClaim, ok := l.Claims[LicenseExpiryClaim] |
| 41 | if !ok { |
| 42 | return time.Time{}, xerrors.New("license_expires claim is missing") |
| 43 | } |
| 44 | |
| 45 | // This claim should be a unix timestamp. |
| 46 | // Everything is already an interface{}, so we need to do some type |
| 47 | // assertions to figure out what we're dealing with. |
| 48 | if unix, ok := expClaim.(json.Number); ok { |
| 49 | i64, err := unix.Int64() |
| 50 | if err != nil { |
| 51 | return time.Time{}, xerrors.Errorf("license_expires claim is not a valid unix timestamp: %w", err) |
| 52 | } |
| 53 | return time.Unix(i64, 0), nil |
| 54 | } |
| 55 | |
| 56 | return time.Time{}, xerrors.Errorf("license_expires claim has unexpected type %T", expClaim) |
| 57 | } |
| 58 | |
| 59 | func (l *License) Trial() bool { |
| 60 | if trail, ok := l.Claims["trail"].(bool); ok { |
no test coverage detected