// NewFakeFailer creates a ethash consensus engine with a fake PoW scheme that
// accepts all blocks as valid apart from the single one specified, though they
// still have to conform to the Ethereum consensus rules.
331259
func NewFakeFailer(fail uint64) *Ethash {
	return &Ethash{
		config: Config{
			PowMode: ModeFake,
		},
		fakeFail: fail,
	}
}
851938
func NewFakeBackupContext(target string, env map[string]string, storageProvider cfbackup.StorageProvider) (backupContext cfbackup.BackupContext) {
	backupContext = cfbackup.NewBackupContext(target, env, "")
	backupContext.StorageProvider = storageProvider
	return
}
383811
func doCopyFake(cpURLs URLs, pg Progress) URLs {
	if progressReader, ok := pg.(*progressBar); ok {
		progressReader.ProgressBar.Add64(cpURLs.SourceContent.Size)
	}
	return cpURLs
}
534683
func newNodeVerifier(name string) (server.Verifier, error) {
	switch name {
	case "aws":
		return aws.NewVerifier()
	case "alwaysallow":
		return alwaysallow.NewVerifier()
	}

	return nil, errors.New("unsupported authorizer")
}
91081
func NewMockPeer(name, url string, blockHeight uint64) *MockPeer {
	return &MockPeer{
		MockPeer:    fabmocks.NewMockPeer(name, url),
		blockHeight: blockHeight,
	}
}
1102845
func NewPBKDF2SHA256Hasher() *PBKDF2Hasher {
	return &PBKDF2Hasher{
		Algorithm:  "pbkdf2_sha256",
		Iterations: 180000,
		Size:       sha256.Size,
		Digest:     sha256.New,
	}
}
192557
func NewFeeEstimator(maxRollback, minRegisteredBlocks uint32) *FeeEstimator {
	return &FeeEstimator{
		maxRollback:         maxRollback,
		minRegisteredBlocks: minRegisteredBlocks,
		lastKnownHeight:     mining.UnminedHeight,
		binSize:             estimateFeeBinSize,
		maxReplacements:     estimateFeeMaxReplacements,
		observed:            make(map[chainhash.Hash]*observedTransaction),
		dropped:             make([]*registeredBlock, 0, maxRollback),
	}
}
1364688
func NewFakeDater(month int32, day int32, year int32) FakeDater {
	return newFakeDater(month, day, year)
}
295573
func GetFakeContainerID(name string) string {
	hash := fnv.New64a()
	hash.Write([]byte(name))
	return strconv.FormatUint(hash.Sum64(), 16)
}
431789
func NewHashProducer(p Producer, numPartitions int32) DistributingProducer {
	return &hashProducer{
		producer:   p,
		partitions: numPartitions,
	}
}
1214664
func NewVoteTracker(params *chaincfg.Params, node VoteDataSource, counter voteCounter,
	activeVersions map[uint32][]chaincfg.ConsensusDeployment) (*VoteTracker, error) {
	var latestStakeVersion uint32
	var starttime uint64

	// Consensus deployments that share a stake version as the key should also
	// have matching starttime.
	for stakeVersion, val := range activeVersions {
		if latestStakeVersion == 0 {
			latestStakeVersion = stakeVersion
			starttime = val[0].StartTime
		} else if val[0].StartTime >= starttime {
			latestStakeVersion = stakeVersion
			starttime = val[0].StartTime
		}
	}

	tracker := &VoteTracker{
		mtx:            sync.RWMutex{},
		node:           node,
		voteCounter:    counter,
		countCache:     make(map[string]*voteCount),
		params:         params,
		version:        latestStakeVersion,
		ringIndex:      -1,
		blockRing:      make([]int32, params.BlockUpgradeNumToCheck),
		minerThreshold: float32(params.BlockRejectNumRequired) / float32(params.BlockUpgradeNumToCheck),
		voterThreshold: float32(params.RuleChangeActivationMultiplier) / float32(params.RuleChangeActivationDivisor),
		sviBlocks:      uint32(params.StakeVersionInterval),
		rciBlocks:      params.RuleChangeActivationInterval,
		blockTime:      int64(params.TargetTimePerBlock.Seconds()),
		passThreshold:  float32(params.RuleChangeActivationMultiplier) / float32(params.RuleChangeActivationDivisor),
		rciVotes:       uint32(params.TicketsPerBlock) * params.RuleChangeActivationInterval,
	}

	// first sync has different error handling than Refresh.
	voteInfo, err := tracker.refreshRCI()
	if err != nil {
		return nil, err
	}
	blocksToAdd, stakeVersion, err := tracker.fetchBlocks(voteInfo)
	if err != nil {
		return nil, err
	}
	stakeInfo, err := tracker.refreshSVIs(voteInfo)
	if err != nil {
		return nil, err
	}
	tracker.update(voteInfo, blocksToAdd, stakeInfo, stakeVersion)

	return tracker, nil
}
1187282
func NewVerifier(s secrets.Secrets, globalCertificate *x509.Certificate) *Verifier {
	return &Verifier{
		secrets:    s,
		globalCert: globalCertificate,
		// tokenCache will cache the token results to accelerate performance
		tokenCache: gcache.New(2048).LRU().Expiration(20 * time.Second).Build(),
	}
}
1214555
func NewMockPeer(lpk, rpk *btcec.PublicKey, addr net.Addr,
	bufferSize int) *MockPeer {

	return &MockPeer{
		remotePub:  rpk,
		remoteAddr: addr,
		localAddr: &net.TCPAddr{
			IP:   net.IP{0x32, 0x31, 0x30, 0x29},
			Port: 36723,
		},
		localPub:     lpk,
		IncomingMsgs: make(chan []byte, bufferSize),
		OutgoingMsgs: make(chan []byte, bufferSize),
		Quit:         make(chan struct{}),
	}
}
1343698
func NewFakeMutableID(body Mutable, source string) (ID, error) {
	h, err := blake2b.New(&blake2b.Config{Size: 16})
	if err != nil {
		return ID{}, err
	}
	h.Write([]byte(source))
	preamble := body.Type()
	id := ID{idVersion<<4 | preamble.Upper(), preamble.Lower()}

	copy(id[2:], h.Sum(nil))

	return id, nil
}
1170114
func newFakeFlagSet(fs *pflag.FlagSet) *pflag.FlagSet {
	ret := pflag.NewFlagSet("", pflag.ExitOnError)
	ret.SetNormalizeFunc(fs.GetNormalizeFunc())
	fs.VisitAll(func(f *pflag.Flag) {
		ret.VarP(cliflag.NoOp{}, f.Name, f.Shorthand, f.Usage)
	})
	return ret
}
1012291
func NewVerificationEngine(context string) (VerificationEngine, error) {

	engine := VerificationEngine{}

	if context == "" {
		return engine, errors.New("Context cannot be empty when initializing the Verification Engine")
	}

	// try to load the public key and if it succeed, then return both the keys
	publicFile := fmt.Sprintf(publicKeySuffixFormat, sanitizeIdentifier(context))
	// if the key exists
	if keyFileExists(publicFile) {
		// try to read it
		public, err := readKey(publicFile, keysFolderPrefixFormat)
		if err != nil {
			// in case of error return it
			return engine, err
		}

		// if we reached here, it means that both the public key
		// existed and was loaded successfull
		engine.publicKey = public
	}

	return engine, nil

}
250519
func NewUsesWeakCryptography(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
	calls := make(map[string][]string)
	calls["crypto/des"] = []string{"NewCipher", "NewTripleDESCipher"}
	calls["crypto/md5"] = []string{"New", "Sum"}
	calls["crypto/sha1"] = []string{"New", "Sum"}
	calls["crypto/rc4"] = []string{"NewCipher"}
	rule := &usesWeakCryptography{
		blacklist: calls,
		MetaData: gosec.MetaData{
			ID:         id,
			Severity:   gosec.Medium,
			Confidence: gosec.High,
			What:       "Use of weak cryptographic primitive",
		},
	}
	return rule, []ast.Node{(*ast.CallExpr)(nil)}
}