// WithMaxSessionDuration wraps an Authenticator to ensure that sessions always
// have a maximum lifetime. If the Session already has an expiration that will
// expire before d, the existing expiration is left in tact.
188995
func WithMaxSessionDuration(auth Authenticator, exp func() time.Time) Authenticator {
	return AuthenticatorFunc(func(username, password, otp string) (*Session, error) {
		session, err := auth.Authenticate(username, password, otp)
		if err != nil {
			return session, err
		}

		t := exp()
		if exp := session.ExpiresAt; exp != nil {
			if exp.Before(t) {
				// Re-setting ExpiresAt to t would increase the
				// expiration of this session, instead we want
				// to keep it in tact.
				return session, err
			}
		}
		session.ExpiresAt = &t
		return session, err
	})
}
745245
func (o *RevokeOAuth2TokenParams) WithTimeout(timeout time.Duration) *RevokeOAuth2TokenParams {
	o.SetTimeout(timeout)
	return o
}
736951
func (a *Account) SetMaxAutoExpireResponseMaps(max int) {
	a.mu.Lock()
	defer a.mu.Unlock()
	a.maxnae = int32(max)
}
1105676
func (s *Identify3State) getSessionToExpire(mctx MetaContext, now time.Time) (*Identify3Session, time.Duration) {
	sess := s.expirationQueue[0]
	sess.Lock()
	defer sess.Unlock()
	expireAt := sess.created.Add(s.expireTime)
	diff := expireAt.Sub(now)
	if diff > 0 {
		return nil, diff
	}
	s.expirationQueue = s.expirationQueue[1:]

	// Only send the expiration if the session is still in the cache table.
	// If not, that means it was already acted upon
	if _, found := s.cache[sess.id]; !found {
		return nil, diff
	}
	mctx.Debug("Identify3State#getSessionToExpire: removing %s", sess.id)
	s.removeFromTableLocked(sess.id)
	return sess, diff
}
39634
func WithMaxResults(maxResults int) userSearchF {
	return func(s userSearch) userSearch {
		s = append(s, userSearchParam{name: "maxResults", value: fmt.Sprintf("%d", maxResults)})
		return s
	}
}
459306
func (c *MemoryStore) SetWithExpiration(key string, value interface{}, expiration time.Duration) error {
	c.cache.Set(key, value, expiration)
	return nil
}
1260479
func DjangoSessionsByExpireDate(db XODB, expireDate *time.Time) ([]*DjangoSession, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`session_key, session_data, expire_date ` +
		`FROM django.django_session ` +
		`WHERE expire_date = ?`

	// run query
	XOLog(sqlstr, expireDate)
	q, err := db.Query(sqlstr, expireDate)
	if err != nil {
		return nil, err
	}
	defer q.Close()

	// load results
	res := []*DjangoSession{}
	for q.Next() {
		ds := DjangoSession{
			_exists: true,
		}

		// scan
		err = q.Scan(&ds.SessionKey, &ds.SessionData, &ds.ExpireDate)
		if err != nil {
			return nil, err
		}

		res = append(res, &ds)
	}

	return res, nil
}
180397
func (o *RevokeAuthenticationSessionParams) WithContext(ctx context.Context) *RevokeAuthenticationSessionParams {
	o.SetContext(ctx)
	return o
}
526604
func (s Session) SessionTimeoutExpiredOrMissing() bool {
	if exp, present := s[TimestampKey]; !present {
		return true
	} else if exp == SessionValueName {
		return false
	} else if expInt, _ := strconv.Atoi(exp.(string)); int64(expInt) < time.Now().Unix() {
		return true
	}
	return false
}
258036
func (db *PGStore) MaxAge(age int) {
	db.Options.MaxAge = age

	// Set the maxAge for each securecookie instance.
	for _, codec := range db.Codecs {
		if sc, ok := codec.(*securecookie.SecureCookie); ok {
			sc.MaxAge(age)
		}
	}
}
438465
func (options PoolOptions) WithMaxActive(maxActive int) PoolOptions {
	options.MaxActive = maxActive
	return options
}
580086
func Max(values ...time.Duration) time.Duration {
	var (
		max time.Duration
	)

	for _, v := range values {
		if v > max {
			max = v
		}
	}

	return max
}
134004
func (s *Signer) SignWithDuration(uri string, interval time.Duration) (signature, expiry string) {
	expiry = signatureExpiry(time.Now().UTC(), interval)
	return s.SignWithExpiry(uri, expiry), expiry
}
452763
func (s *CampaignLimits) SetMaximumDuration(v int64) *CampaignLimits {
	s.MaximumDuration = &v
	return s
}
639384
func (s *Server) WithAuthentication(scheme AuthenticationScheme) *Server {
	s.authentication = scheme
	return s
}
869729
func MaxUnitForDuration(d time.Duration) (int64, Unit) {
	var (
		currMultiple int64
		currUnit     = Nanosecond
		dUnixNanos   = d.Nanoseconds()
		isNegative   bool
	)
	if dUnixNanos < 0 {
		dUnixNanos = -dUnixNanos
		isNegative = true
	}
	for _, u := range unitsByDurationDesc {
		// The unit is guaranteed to be valid so it's safe to ignore error here.
		duration, _ := u.Value()
		if dUnixNanos < duration.Nanoseconds() {
			continue
		}
		durationUnixNanos := int64(duration)
		quotient := dUnixNanos / durationUnixNanos
		remainder := dUnixNanos - quotient*durationUnixNanos
		if remainder != 0 {
			continue
		}
		currMultiple = quotient
		currUnit = u
		break
	}
	if isNegative {
		currMultiple = -currMultiple
	}
	return currMultiple, currUnit
}
741651
func WithTimeout(timeout string) ClientOptionFunc {
	return func(c *Client) error {
		if timeout == "" {
			c.sessionTimeout = DefaultSessionTimeout
			return nil
		}

		t, err := time.ParseDuration(timeout)
		if err != nil {
			return client.InvalidTimeoutError{Timeout: timeout}
		}
		c.sessionTimeout = t
		return nil
	}
}