// saveValidatorsInfo persists the validator set.
//
// `height` is the effective height for which the validator is responsible for
// signing. It should be called from s.Save(), right before the state itself is
// persisted.
347413
func saveValidatorsInfo(db dbm.DB, height, lastHeightChanged int64, valSet *types.ValidatorSet) {
	if lastHeightChanged > height {
		panic("LastHeightChanged cannot be greater than ValidatorsInfo height")
	}
	valInfo := &ValidatorsInfo{
		LastHeightChanged: lastHeightChanged,
	}
	// Only persist validator set if it was updated or checkpoint height (see
	// valSetCheckpointInterval) is reached.
	if height == lastHeightChanged || height%valSetCheckpointInterval == 0 {
		valInfo.ValidatorSet = valSet
	}
	db.Set(calcValidatorsKey(height), valInfo.Bytes())
}
114700
func (manager *Manager) SaveEmailAddressValidationInformation(info *EmailAddressValidationInformation) (err error) {
	mgoCollection := db.GetCollection(manager.session, mongoOngoingEmailAddressValidationCollectionName)
	_, err = mgoCollection.Upsert(bson.M{"emailaddress": info.EmailAddress}, info)
	return
}
1345852
func (h PfssoHandler) validateInfo(ctx context.Context, info map[string]string) error {
	required := []string{"ip", "mac", "username", "role"}
	for _, k := range required {
		if _, ok := info[k]; !ok {
			return errors.New(fmt.Sprintf("Missing %s in request", k))
		}
	}
	return nil
}
801099
func (c Cap) IsValid() bool {
	return c.center.Vector.IsUnit() && c.height <= fullHeight
}
1092894
func (m *ThriftFilter) Validate() error {
	if m == nil {
		return nil
	}

	if len(m.GetName()) < 1 {
		return ThriftFilterValidationError{
			field:  "Name",
			reason: "value length must be at least 1 bytes",
		}
	}

	switch m.ConfigType.(type) {

	case *ThriftFilter_Config:

		{
			tmp := m.GetConfig()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return ThriftFilterValidationError{
						field:  "Config",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	case *ThriftFilter_TypedConfig:

		{
			tmp := m.GetTypedConfig()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return ThriftFilterValidationError{
						field:  "TypedConfig",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	}

	return nil
}
410986
func (tm2pb) ValidatorUpdates(vals *ValidatorSet) []abci.ValidatorUpdate {
	validators := make([]abci.ValidatorUpdate, vals.Size())
	for i, val := range vals.Validators {
		validators[i] = TM2PB.ValidatorUpdate(val)
	}
	return validators
}
53017
func (service *Service) ValidateInfo(w http.ResponseWriter, r *http.Request) {
	registrationSession, err := service.GetSession(r, SessionForRegistration, "registrationdetails")
	if err != nil {
		log.Error("Failed to retrieve registration session: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	rMgr := registration.NewManager(r)

	logMgr := persistentlog.NewManager(r)

	var registeringUser *registration.InProgressRegistration
	sessionKey, existingSession := registrationSession.Values["sessionkey"].(string)
	if existingSession {
		registeringUser, err = rMgr.GetRegisteringUserBySessionKey(sessionKey)
		if err != nil {
			log.Error("Failed to get registration object: ", err)
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User updated his info"))
	} else {
		sessionKey, err = tools.GenerateRandomString()
		if err != nil {
			log.Error("Failed to generate session key: ", err)
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		registeringUser = registration.New(sessionKey)
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, fmt.Sprintf("User started registration flow. State: %s", r.URL.Query().Get("state"))))
	}

	registrationSession.Values["sessionkey"] = sessionKey

	data := struct {
		Firstname string `json:"firstname"`
		Lastname  string `json:"lastname"`
		Email     string `json:"email"`
		Phone     string `json:"phone"`
		Password  string `json:"password"`
		LangKey   string `json:"langkey"`
	}{}

	if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
		log.Debug("Failed to decode validate info body: ", err)
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	// Check the users first name
	if !user.ValidateName(strings.ToLower(data.Firstname)) {
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User first name invalid"))
		writeErrorResponse(w, "invalid_first_name", http.StatusUnprocessableEntity)
		return
	}
	registeringUser.Firstname = data.Firstname

	// Check the users last name
	if !user.ValidateName(strings.ToLower(data.Lastname)) {
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User last name invalid"))
		writeErrorResponse(w, "invalid_last_name", http.StatusUnprocessableEntity)
		return
	}
	registeringUser.Lastname = data.Lastname

	// Convert the email address to all lowercase
	// Email addresses are limited to printable ASCII characters
	// See https://tools.ietf.org/html/rfc5322#section-3.4.1 for details
	data.Email = strings.ToLower(data.Email)
	if !user.ValidateEmailAddress(data.Email) {
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User email invalid"))
		writeErrorResponse(w, "invalid_email_format", http.StatusUnprocessableEntity)
		return
	}

	// Check if the email is already known
	valMgr := validationdb.NewManager(r)
	if _, err = valMgr.GetByEmailAddress(data.Email); !db.IsNotFound(err) {
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User email already confirmed by someone else"))
		writeErrorResponse(w, "email_already_used", http.StatusUnprocessableEntity)
		return
	}
	newEmail := data.Email != registeringUser.Email
	registeringUser.Email = data.Email

	if !user.ValidatePhoneNumber(data.Phone) {
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User phone number invalid"))
		writeErrorResponse(w, "invalid_phonenumber", http.StatusUnprocessableEntity)
		return
	}

	// Check if the phone number is already known
	if _, err = valMgr.GetByPhoneNumber(data.Phone); !db.IsNotFound(err) {
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User phone number already confirmed by someone else"))
		writeErrorResponse(w, "phone_already_used", http.StatusUnprocessableEntity)
		return
	}
	newPhone := data.Phone != registeringUser.Phonenumber
	registeringUser.Phonenumber = data.Phone

	// Check the password
	if err = password.Check(data.Password); err != nil {
		if err != password.ErrInvalidPassword {
			log.Error("Failed to verify password: ", err)
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User password invalid"))
		log.Debug("User password is invalid")
		writeErrorResponse(w, "invalid_password", http.StatusUnprocessableEntity)
		return
	}
	// Storing password in plaintext is probably not such a great idea
	// Therefore, just do a check now, and do the password thing when we actually
	// create the user

	phoneConfirmed, err := service.phonenumberValidationService.IsConfirmed(r, registeringUser.PhoneValidationKey)
	if err != nil && err != validation.ErrInvalidOrExpiredKey {
		log.Error("Failed to check if phone number is already confirmed: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	// phone number validation
	if newPhone && !phoneConfirmed {
		// invalidate old phone number validation
		_ = service.phonenumberValidationService.ExpireValidation(r, registeringUser.PhoneValidationKey)

		phonenumber := user.Phonenumber{Phonenumber: data.Phone}
		validationkey, err := service.phonenumberValidationService.RequestValidation(r, registeringUser.SessionKey, phonenumber, fmt.Sprintf("https://%s/phoneregistrationvalidation", r.Host), data.LangKey)
		if err != nil {
			log.Error("Failed to send phonenumber verification in registration flow: ", err)
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		registeringUser.PhoneValidationKey = validationkey

		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User started phone validation for new phone"))
	}

	// Email validation
	// So the logic here: only send an email if the email address is changed,
	// also only send it if the phone number is confirmed already (defer sending email until this is done)
	if newEmail && phoneConfirmed {
		// invalidated old email validation
		_ = service.emailaddressValidationService.ExpireValidation(r, registeringUser.EmailValidationKey)

		mailvalidationkey, err := service.emailaddressValidationService.RequestValidation(r, registeringUser.SessionKey, data.Email, fmt.Sprintf("https://%s/emailregistrationvalidation", r.Host), data.LangKey)
		if err != nil {
			log.Error("Failed to send email verification in registration flow: ", err)
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		registeringUser.EmailValidationKey = mailvalidationkey

		logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User started email validation for new email"))
	}

	// Save the info we have so far about the user registering
	if err = rMgr.UpsertRegisteringUser(registeringUser); err != nil {
		log.Error("Failed to save registering user to database: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	logMgr.SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "User info processed, moving to validations"))

	sessions.Save(r, w)
	// validations created
	w.WriteHeader(http.StatusCreated)

}
408491
func (mc *multiProvider) ValidatorSet(chainID string, height int64) (valset *types.ValidatorSet, err error) {
	for _, p := range mc.providers {
		valset, err = p.ValidatorSet(chainID, height)
		if err == nil {
			// TODO Log unexpected types of errors.
			return valset, nil
		}
	}
	return nil, lerr.ErrUnknownValidators(chainID, height)
}
447419
func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool {
	if r.Cmp(common.Big1) < 0 || s.Cmp(common.Big1) < 0 {
		return false
	}
	// reject upper range of s values (ECDSA malleability)
	// see discussion in secp256k1/libsecp256k1/include/secp256k1.h
	if homestead && s.Cmp(secp256k1halfN) > 0 {
		return false
	}
	// Frontier: allow s to be in full N range
	return r.Cmp(secp256k1N) < 0 && s.Cmp(secp256k1N) < 0 && (v == 0 || v == 1)
}
1036349
func (jfo *JobFindOptions) IsValid() bool {
	s := structs.New(jfo)
	f := s.Fields()

	nonZeroValues := 0

	for _, field := range f {
		if !field.IsZero() {
			nonZeroValues += 1
		}
	}

	return nonZeroValues == 0 || nonZeroValues == 1
}
89281
func IsInvalidAction(err error) bool {
	if err == ErrInvalidAction {
		return true
	}
	de, ok := err.(*DeltaError)
	return ok && de.Err == ErrInvalidAction
}
34497
func (v *Validator) CheckRlimits() (errs error) {
	if v.platform != "linux" && v.platform != "solaris" {
		errs = multierror.Append(errs, fmt.Errorf("For %q platform, the configuration structure does not support process.rlimits", v.platform))
		return
	}

	process := v.spec.Process
	for index, rlimit := range process.Rlimits {
		for i := index + 1; i < len(process.Rlimits); i++ {
			if process.Rlimits[index].Type == process.Rlimits[i].Type {
				errs = multierror.Append(errs,
					specerror.NewError(
						specerror.PosixProcRlimitsErrorOnDup,
						fmt.Errorf("rlimit can not contain the same type %q",
							process.Rlimits[index].Type),
						rspec.Version))
			}
		}
		errs = multierror.Append(errs, v.rlimitValid(rlimit))
	}

	return
}
286394
func LoadValidators(db dbm.DB, height int64) (*types.ValidatorSet, error) {
	valInfo := loadValidatorsInfo(db, height)
	if valInfo == nil {
		return nil, ErrNoValSetForHeight{height}
	}
	if valInfo.ValidatorSet == nil {
		lastStoredHeight := lastStoredHeightFor(height, valInfo.LastHeightChanged)
		valInfo2 := loadValidatorsInfo(db, lastStoredHeight)
		if valInfo2 == nil || valInfo2.ValidatorSet == nil {
			// TODO (melekes): remove the below if condition in the 0.33 major
			// release and just panic. Old chains might panic otherwise if they
			// haven't saved validators at intermediate (%valSetCheckpointInterval)
			// height yet.
			// https://github.com/tendermint/tendermint/issues/3543
			valInfo2 = loadValidatorsInfo(db, valInfo.LastHeightChanged)
			lastStoredHeight = valInfo.LastHeightChanged
			if valInfo2 == nil || valInfo2.ValidatorSet == nil {
				panic(
					fmt.Sprintf("Couldn't find validators at height %d (height %d was originally requested)",
						lastStoredHeight,
						height,
					),
				)
			}
		}
		valInfo2.ValidatorSet.IncrementProposerPriority(int(height - lastStoredHeight)) // mutate
		valInfo = valInfo2
	}

	return valInfo.ValidatorSet, nil
}
535193
func (m *MultiResolver) getResolveValidator(name string) ([]ResolveValidator, error) {
	rs := m.resolvers[""]
	tld := path.Ext(name)
	if tld != "" {
		tld = tld[1:]
		rstld, ok := m.resolvers[tld]
		if ok {
			return rstld, nil
		}
	}
	if len(rs) == 0 {
		return rs, NewNoResolverError(tld)
	}
	return rs, nil
}
1220351
func (env *environ) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) {
	validator := constraints.NewValidator()
	validator.RegisterUnsupported(unsupportedConstraints)
	validator.RegisterVocabulary(constraints.Arch, []string{
		arch.AMD64, arch.I386,
	})
	return validator, nil
}
1346127
func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	var totalSize int64
	for k, v := range annotations {
		if !validation.IsQualifiedName(strings.ToLower(k)) {
			allErrs = append(allErrs, field.Invalid(fldPath, k, qualifiedNameErrorMsg))
		}
		totalSize += (int64)(len(k)) + (int64)(len(v))
	}
	if totalSize > (int64)(totalAnnotationSizeLimitB) {
		allErrs = append(allErrs, field.TooLong(fldPath, "", totalAnnotationSizeLimitB))
	}

	if annotations[api.AffinityAnnotationKey] != "" {
		allErrs = append(allErrs, ValidateAffinityInPodAnnotations(annotations, fldPath)...)
	}
	return allErrs
}
426014
func (s *ValidateSecurityProfileBehaviorsOutput) SetValidationErrors(v []*ValidationError) *ValidateSecurityProfileBehaviorsOutput {
	s.ValidationErrors = v
	return s
}