// NewValidator instantiates a validate code generator.
556379
func NewValidator() *Validator {
	var (
		v   = &Validator{seen: make(map[string]*bytes.Buffer)}
		err error
	)
	fm := template.FuncMap{
		"tabs":             Tabs,
		"slice":            toSlice,
		"oneof":            oneof,
		"constant":         constant,
		"goifyAtt":         GoifyAtt,
		"add":              Add,
		"recurseAttribute": v.recurseAttribute,
	}
	v.arrayValT, err = template.New("array").Funcs(fm).Parse(arrayValTmpl)
	if err != nil {
		panic(err)
	}
	v.hashValT, err = template.New("hash").Funcs(fm).Parse(hashValTmpl)
	if err != nil {
		panic(err)
	}
	v.userValT, err = template.New("user").Funcs(fm).Parse(userValTmpl)
	if err != nil {
		panic(err)
	}
	return v
}
349125
func newCtor(constructor reflect.Type, v reflect.Value) *ctor {
	if constructor.Kind() != reflect.Func || constructor.IsVariadic() {
		return nil
	}
	numOut := constructor.NumOut()
	if numOut == 0 || numOut > 2 || (numOut == 2 && constructor.Out(1) != terror) {
		return nil
	}
	outType := constructor.Out(0)
	numIn := constructor.NumIn()
	inTypes := make([]reflect.Type, numIn)
	for i := range inTypes {
		inTypes[i] = constructor.In(i)
	}
	construct := func(in []reflect.Value) (reflect.Value, error) {
		for i, arg := range in {
			if arg.IsValid() {
				continue
			}
			const format = "unable to create arg %d (%s) of %s constructor"
			return reflect.Value{}, fmt.Errorf(format, i, inTypes[i], outType)
		}
		out := v.Call(in)
		var err error
		if len(out) == 2 && !out[1].IsNil() {
			err = out[1].Interface().(error)
		}
		return out[0], err
	}

	return &ctor{
		funcType:     constructor,
		outType:      outType,
		inTypes:      inTypes,
		construct:    construct,
		errChan:      make(chan error),
		onceManifest: &sync.Once{},
		onceResult:   &sync.Once{},
	}
}
632656
func GetValidator(name string, args interface{}) (FieldValidatorFunc, error) {
	switch name {
	case `one-of`:
		if typeutil.IsArray(args) {
			return ValidateIsOneOf(sliceutil.Sliceify(args)...), nil
		} else {
			return nil, fmt.Errorf("Must specify an array of values for validator 'one-of'")
		}

	case `not-zero`:
		return ValidateNonZero, nil

	case `not-empty`:
		return ValidateNotEmpty, nil

	case `positive-integer`:
		return ValidatePositiveInteger, nil

	case `positive-or-zero-integer`:
		return ValidatePositiveOrZeroInteger, nil

	case `url`:
		return ValidateIsURL, nil

	case `match`, `match-all`:
		if typeutil.IsArray(args) {
			return ValidateMatchAll(sliceutil.Stringify(args)...), nil
		} else {
			return nil, fmt.Errorf("Must specify an array of values for validator 'match'")
		}

	case `match-any`:
		if typeutil.IsArray(args) {
			return ValidateMatchAny(sliceutil.Stringify(args)...), nil
		} else {
			return nil, fmt.Errorf("Must specify an array of values for validator 'match-any'")
		}

	default:
		return nil, fmt.Errorf("Unknown validator %q", name)
	}
}
968671
func NewRSAVerifier() Verifier {
	return verifyFn(func(checksum, signature []byte, hash crypto.Hash, publicKey crypto.PublicKey) error {
		key, ok := publicKey.(*rsa.PublicKey)
		if !ok {
			return errors.New("not a valid RSA public key")
		}
		return rsa.VerifyPKCS1v15(key, hash, checksum, signature)
	})
}
167827
func NewValidationResponse(validation ValidationModel, warnings ...string) ValidateResponseModel {
	return ValidateResponseModel{
		Data:     &validation,
		Warnings: warnings,
	}
}
1045949
func New(code, message string, origErr error) Error {
	var errs []error
	if origErr != nil {
		errs = append(errs, origErr)
	}
	return newBaseError(code, message, errs)
}
898900
func NewValidationError(err string, warnings ...string) ValidateResponseModel {
	return ValidateResponseModel{
		Error:    err,
		Warnings: warnings,
	}
}
663236
func EnumValidator(param string, v reflect.Value) (ValidationResult, error) {
	if param == "" {
		return 0, ErrInvalidConfigValue
	}

	params := strings.Split(param, "|")

	var enum func(v reflect.Value) (ValidationResult, error)
	enum = func(v reflect.Value) (ValidationResult, error) {
		if v.Kind() == reflect.Ptr {
			v = v.Elem()
		}
		switch v.Kind() {
		case reflect.String:
			val := v.String()
			if val == "" {
				// need empty checking? use req :)
				return ValidationOK, nil
			}
			for _, value := range params {
				if val == value {
					return ValidationOK, nil
				}
			}
			return ValidationNG, nil
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			val := v.Int()
			for _, value := range params {
				value2, err := strconv.ParseInt(value, 10, 0)
				if err != nil {
					return 0, ErrInvalidConfigValue
				}
				if val == value2 {
					return ValidationOK, nil
				}
			}
			return ValidationNG, nil
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
			val := v.Uint()
			for _, value := range params {
				value2, err := strconv.ParseUint(value, 10, 0)
				if err != nil {
					return 0, ErrInvalidConfigValue
				}
				if val == value2 {
					return ValidationOK, nil
				}
			}
			return ValidationNG, nil
		case reflect.Array, reflect.Slice:
			for i := 0; i < v.Len(); i++ {
				e := v.Index(i)
				return enum(e)
			}
		default:
			return 0, ErrValidateUnsupportedType
		}

		return ValidationOK, nil
	}

	return enum(v)
}
321046
func NewHandler(validator Validator) (http.Handler, error) {
	log.Info("setting up key / CSR generator")
	return &api.HTTPHandler{
		Handler: &Handler{
			generator: &csr.Generator{Validator: validator},
		},
		Methods: []string{"POST"},
	}, nil
}
1027105
func NewValidatorWithOpts(options Options) *Validator {
	if options.MinLength <= 0 {
		options.MinLength = 8
	}
	if options.MinDiff <= 0 {
		options.MinDiff = 5
	}
	if options.MinDist < 0 {
		options.MinDist = 3
	}

	return &Validator{
		options:     options,
		words:       make(map[string]struct{}),
		hashedWords: make(map[string]string),
	}
}
261767
func NewGenerator(options *Options) *Generator {
	var g = &Generator{}
	// first we validate the flags
	if err := options.Validate(); err != nil {
		panic(err)
	}
	g.options = options
	// we initiate the values on the generator
	g.init()
	return g
}
257327
func (e *manualEnviron) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) {
	validator := constraints.NewValidator()
	validator.RegisterUnsupported(unsupportedConstraints)
	if isRunningController() {
		validator.UpdateVocabulary(constraints.Arch, []string{arch.HostArch()})
	} else {
		// We're running outside of the Juju controller, so we must
		// SSH to the machine and detect its architecture.
		hw, _, err := e.seriesAndHardwareCharacteristics()
		if err != nil {
			return nil, errors.Trace(err)
		}
		validator.UpdateVocabulary(constraints.Arch, []string{*hw.Arch})
	}
	return validator, nil
}
1236508
func RegisterValidator(name string, v Validator) {
	if _, ok := validators[name]; ok {
		log.Fatalf("Registering duplicate Validator with name %v", name)
	}
	validators[name] = v
}
664719
func New() *DefaultLoader {
	loader := MultiLoader(
		&TagLoader{},
		&EnvironmentLoader{},
		&FlagLoader{},
	)

	d := &DefaultLoader{}
	d.Loader = loader
	d.Validator = MultiValidator(&RequiredValidator{})
	return d
}
1075489
func NewValidator(method *structs.ACLAuthMethod) (Validator, error) {
	typesMu.RLock()
	factory, ok := types[method.Type]
	typesMu.RUnlock()

	if !ok {
		return nil, fmt.Errorf("no auth method registered with type: %s", method.Type)
	}

	return factory(method)
}
1007764
func Validator(preValidators []PreValidator, postValidators []PostValidator) Rule {
	return &validatorRule{
		preValidators:  preValidators,
		postValidators: postValidators,
	}
}
99363
func NewEmailValidator(apiKey string) *EmailValidatorImpl {
	isPublicKey := false

	// Did the user pass in a public key?
	if strings.HasPrefix(apiKey, "pubkey-") {
		isPublicKey = true
	}

	return &EmailValidatorImpl{
		client:      http.DefaultClient,
		isPublicKey: isPublicKey,
		apiBase:     APIBase,
		apiKey:      apiKey,
	}
}