Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b3f9e6

Browse files
committed
Refactor CryptoKey methods for clarity
1 parent 3d81388 commit 5b3f9e6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

enterprise/wsproxy/wsproxysdk/wsproxysdk.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,17 @@ type CryptoKey struct {
220220
StartsAt time.Time `json:"starts_at"`
221221
}
222222

223-
func (c CryptoKey) Active(now time.Time) bool {
223+
func (c CryptoKey) CanSign(now time.Time) bool {
224224
now = now.UTC()
225225
isAfterStartsAt := !c.StartsAt.IsZero() && !now.Before(c.StartsAt)
226-
return isAfterStartsAt && !c.Invalid(now)
226+
return isAfterStartsAt && c.CanVerify(now)
227227
}
228228

229-
func (c CryptoKey) Invalid(now time.Time) bool {
229+
func (c CryptoKey) CanVerify(now time.Time) bool {
230230
now = now.UTC()
231-
noSecret := c.Secret == ""
232-
afterDelete := !c.DeletesAt.IsZero() && !now.Before(c.DeletesAt.UTC())
233-
return noSecret || afterDelete
231+
hasSecret := c.Secret != ""
232+
beforeDelete := c.DeletesAt.IsZero() || now.Before(c.DeletesAt)
233+
return hasSecret && beforeDelete
234234
}
235235

236236
type RegisterWorkspaceProxyResponse struct {

0 commit comments

Comments
 (0)