// luhn check is used for checking if credit card is valid
432692
func luhn(s string) bool {
	var t = [...]int{0, 2, 4, 6, 8, 1, 3, 5, 7, 9}
	odd := len(s) & 1
	var sum int
	for i, c := range s {
		if c < '0' || c > '9' {
			return false
		}
		if i&1 == odd {
			sum += t[c-'0']
		} else {
			sum += int(c - '0')
		}
	}
	return sum%10 == 0
}
654980
func (val *Validation) Check() error {
	if val == nil || len(val.Errors) <= 0 {
		return nil
	}

	return val.constructErrorMessage()
}
1231250
func (b *permBiz) Check(user web.User, scope string, resType, resID string) (err error) {
	au := user.(*model.AuthUser)
	if au.Admin() {
		return
	}

	do(func(d dao.Interface) {
		var perm *model.Perm
		perm, err = d.PermGet(resType, resID)
		if err != nil {
			return
		}

		if perm == nil || perm.Scope == model.PermNone || (scope == "read" && perm.Scope == model.PermWrite) {
			return
		}

		for _, u := range perm.Users {
			if user.ID() == u {
				return
			}
		}

		for _, r := range perm.Roles {
			if au.IsInRole(r) {
				return
			}
		}
		err = ErrForbidden
	})
	return
}
1364556
func (o *Options) Check(r io.Reader, h1 mh.Multihash) error {
	h2, err := o.Multihash(r)
	if err != nil {
		return err
	}

	if !bytes.Equal(h1, h2) {
		return fmt.Errorf("computed checksum did not match")
	}

	return nil
}
1120876
func Check(err *error, cond bool, text string) {
	// do nothing if error has raised early
	if *err != nil {
		return
	}

	if !cond {
		*err = Error(text)
	}
}
1275524
func (c *constraint) check(v *Version) bool {
	return c.function(v, c)
}
32313
func (p *ExclusivePool) CheckIn(identity string) {
	p.lock.Lock()

	lock, has := p.pool[identity]
	if !has {
		lock = &sync.Mutex{}
		p.pool[identity] = lock
	}
	p.count[identity]++

	p.lock.Unlock()
	lock.Lock()
}
259259
func (c *sendOptions) Check() error {
	if strings.TrimSpace(c.Recipient) == "" {
		return ErrRecipientMissing
	}
	if strings.TrimSpace(c.Amount) == "" {
		return ErrAmountMissing
	}
	namt, err := stellarnet.ParseStellarAmount(c.Amount)
	if err != nil {
		return ErrInvalidAmount
	}
	if namt < 0 {
		return ErrInvalidAmount
	}

	if c.FromAccountID != "" {
		_, err := strkey.Decode(strkey.VersionByteAccountID, c.FromAccountID)
		if err != nil {
			return ErrInvalidAccountID
		}
	}
	if len(c.Message) > libkb.MaxStellarPaymentNoteLength {
		return ErrMessageTooLong
	}

	return nil
}
176825
func (d *Descriptor) Check() error {
	if d.Pack < 1 || d.Pack > 4 {
		return fmt.Errorf("invalid pack value %v", d.Pack)
	}
	for i := 0; i < d.Planes; i++ {
		h := d.GetHeight(i)
		if d.Interlaced && h%2 != 0 && h != d.Height {
			return fmt.Errorf("invalid interlaced input height %v", d.Height)
		}
	}
	return nil
}
691452
func (ch *Ch) CheckingListen(ctx context.Context, cancelAll context.CancelFunc, totalActiveProcs int) (size uint, e error) {
	ContentLens := uint(0)
	for i := 0; i < totalActiveProcs; i++ {
		select {
		case <-ctx.Done():
			i--
		case err := <-ch.Err:
			if e != nil {
				cancelAll()
			}
			e = err
		case size = <-ch.Size:
			if ContentLens == 0 {
				ContentLens = size
			} else {
				if ContentLens != size {
					if e != nil {
						cancelAll()
					}
					e = errors.New("Not match the file on each mirrors")
				}
			}
		}
	}

	return
}
1020501
func (t leadershipToken) Check(attempt int, out interface{}) error {
	err := t.token.Check(attempt, out)
	if errors.Cause(err) == lease.ErrNotHeld {
		return errors.Errorf("%q is not leader of %q", t.unitName, t.applicationName)
	}
	return errors.Trace(err)
}
173465
func CreditCardExp() string {
	month := strconv.Itoa(randIntRange(1, 12))
	if len(month) == 1 {
		month = "0" + month
	}
	return month + "/" + strconv.Itoa(randIntRange(currentYear+1, currentYear+10))
}
798666
func (c *batchOptions) Check() error {
	for i, p := range c.Payments {
		if strings.TrimSpace(p.Recipient) == "" {
			return fmt.Errorf("payment %d: %s", i, ErrRecipientMissing)
		}
		if strings.TrimSpace(p.Amount) == "" {
			return fmt.Errorf("payment %d: %s", i, ErrAmountMissing)
		}
		namt, err := stellarnet.ParseStellarAmount(p.Amount)
		if err != nil {
			return fmt.Errorf("payment %d: %s", i, ErrInvalidAmount)
		}
		if namt < 0 {
			return fmt.Errorf("payment %d: %s", i, ErrInvalidAmount)
		}
		if len(p.Message) > libkb.MaxStellarPaymentNoteLength {
			return fmt.Errorf("payment %d: %s", i, ErrMessageTooLong)
		}
	}

	if c.Timeout <= 0 {
		c.Timeout = 15 * len(c.Payments)
	}

	return nil
}
713929
func (e *ScanProofsEngine) CheckOne(m libkb.MetaContext, rec map[string]string, tickers ScanProofsTickers) (libkb.ProofError, bool, error) {
	uid := keybase1.UID(rec["uid"])
	sigid := keybase1.SigID(rec["sig_id"])

	foundhint := false
	hint, err := e.GetSigHint(m, uid, sigid)
	if err != nil {
		return nil, foundhint, err
	}
	if hint == nil {
		return nil, foundhint, nil
	}
	foundhint = true

	link, err := e.GetRemoteProofChainLink(m, uid, sigid)
	if err != nil {
		return nil, foundhint, err
	}

	pc, err := libkb.MakeProofChecker(m.G().GetProofServices(), link)
	if err != nil {
		return nil, foundhint, err
	}

	// Beyond this point, external requests will occur, and rate limiting is used
	ptype := link.GetProofType()
	if tickers[ptype] != nil {
		m.Info("Waiting for ticker: %v (%v)", keybase1.ProofTypeRevMap[ptype], ptype)
		<-tickers[ptype].C
	}

	pvlSource := m.G().GetPvlSource()
	if pvlSource == nil {
		return nil, foundhint, fmt.Errorf("no pvl source for proof verification")
	}
	pvlU, err := pvlSource.GetLatestEntry(m)
	if err != nil {
		return nil, foundhint, fmt.Errorf("error getting pvl: %s", err)
	}

	if _, perr := pc.CheckStatus(m, *hint, libkb.ProofCheckerModeActive, pvlU); perr != nil {
		return perr, foundhint, nil
	}

	return nil, foundhint, nil
}
1198275
func (s State) CheckValid() error {
	switch s {
	case StateNew, StateStart, StateClose:
		return nil
	default:
		return errors.NewBadParameterError("iteration state", s).Expected(StateNew + "|" + StateStart + "|" + StateClose)
	}
}
139933
func (ca *CertAuthorityV2) Check() error {
	err := ca.ID().Check()
	if err != nil {
		return trace.Wrap(err)
	}
	_, err = ca.Checkers()
	if err != nil {
		return trace.Wrap(err)
	}
	_, err = ca.Signers()
	if err != nil {
		return trace.Wrap(err)
	}
	// This is to force users to migrate
	if len(ca.Spec.Roles) != 0 && len(ca.Spec.RoleMap) != 0 {
		return trace.BadParameter("should set either 'roles' or 'role_map', not both")
	}
	if err := RoleMap(ca.Spec.RoleMap).Check(); err != nil {
		return trace.Wrap(err)
	}
	return nil
}
931340
func (s ScryptAuth) Check(pw_cost uint, hash_ref, user_password, salt []byte) (chk bool, err error) {
	result_hash, err := s.Hash(pw_cost, user_password, salt)
	if err != nil {
		return false, err
	}
	if subtle.ConstantTimeCompare(result_hash, hash_ref) != 1 {
		return false, errors.New("Error: Hash verification failed")
	}
	return true, nil
}