// SubmitToSingleCTWithResult will submit the certificate represented by certDER to the CT
// log specified by log URL and public key (base64) and return the SCT to the caller
333472
func (pub *Impl) SubmitToSingleCTWithResult(ctx context.Context, req *pubpb.Request) (*pubpb.Result, error) {
	cert, err := x509.ParseCertificate(req.Der)
	if err != nil {
		pub.log.AuditErrf("Failed to parse certificate: %s", err)
		return nil, err
	}

	chain := append([]ct.ASN1Cert{ct.ASN1Cert{Data: req.Der}}, pub.issuerBundle...)

	// Add a log URL/pubkey to the cache, if already present the
	// existing *Log will be returned, otherwise one will be constructed, added
	// and returned.
	ctLog, err := pub.ctLogsCache.AddLog(*req.LogURL, *req.LogPublicKey, pub.log)
	if err != nil {
		pub.log.AuditErrf("Making Log: %s", err)
		return nil, err
	}

	isPrecert := false
	if req.Precert != nil {
		isPrecert = *req.Precert
	}

	sct, err := pub.singleLogSubmit(
		ctx,
		chain,
		isPrecert,
		core.SerialToString(cert.SerialNumber),
		ctLog)
	if err != nil {
		if canceled.Is(err) {
			return nil, err
		}
		var body string
		if respErr, ok := err.(jsonclient.RspError); ok && respErr.StatusCode < 500 {
			body = string(respErr.Body)
		}
		pub.log.AuditErrf("Failed to submit certificate to CT log at %s: %s Body=%q",
			ctLog.uri, err, body)
		return nil, err
	}

	sctBytes, err := tls.Marshal(*sct)
	if err != nil {
		return nil, err
	}
	return &pubpb.Result{Sct: sctBytes}, nil
}
538275
func (r *PlaceSearchResponse) ResultsWithScore(score int) []*Place {
	var res []*Place
	for _, v := range r.Places {
		if r.Scores[v] >= score {
			res = append(res, v)
		}
	}
	return res
}
70579
func (r *LabelSearchResponse) ResultsWithScore(score int) []*Label {
	var res []*Label
	for _, v := range r.Labels {
		if r.Scores[v] >= score {
			res = append(res, v)
		}
	}
	return res
}
706028
func (r *repository) InitializeWithCertificate(rootKeyIDs []string, rootCerts []data.PublicKey,
	serverManagedRoles ...data.RoleName) error {

	// If we explicitly pass in certificate(s) but not key, then look keys up using certificate
	if len(rootKeyIDs) == 0 && len(rootCerts) != 0 {
		rootKeyIDs = []string{}
		availableRootKeyIDs := make(map[string]bool)
		for _, k := range r.GetCryptoService().ListKeys(data.CanonicalRootRole) {
			availableRootKeyIDs[k] = true
		}

		for _, cert := range rootCerts {
			if err := keyExistsInList(cert, availableRootKeyIDs); err != nil {
				return fmt.Errorf("error initializing repository with certificate: %v", err)
			}
			keyID, _ := utils.CanonicalKeyID(cert)
			rootKeyIDs = append(rootKeyIDs, keyID)
		}
	}
	return r.initialize(rootKeyIDs, rootCerts, serverManagedRoles...)
}
332628
func (ra *RegistrationAuthorityImpl) RevokeCertificateWithReg(ctx context.Context, cert x509.Certificate, revocationCode revocation.Reason, regID int64) error {
	serialString := core.SerialToString(cert.SerialNumber)
	var err error
	if features.Enabled(features.RevokeAtRA) {
		err = ra.revokeCertificate(ctx, cert, revocationCode)
	} else {
		err = ra.SA.MarkCertificateRevoked(ctx, serialString, revocationCode)
	}

	state := "Failure"
	defer func() {
		// Needed:
		//   Serial
		//   CN
		//   DNS names
		//   Revocation reason
		//   Registration ID of requester
		//   Error (if there was one)
		ra.log.AuditInfof("%s, Request by registration ID: %d",
			revokeEvent(state, serialString, cert.Subject.CommonName, cert.DNSNames, revocationCode),
			regID)
	}()

	if err != nil {
		state = fmt.Sprintf("Failure -- %s", err)
		return err
	}

	state = "Success"
	ra.stats.Inc("RevokedCertificates", 1)
	return nil
}
62079
func (ff *firstRowFunction) GetPartialResult(evalCtx *AggEvaluateContext) []types.Datum {
	return []types.Datum{ff.GetResult(evalCtx)}
}
1111120
func (tn *TreeNode) processResult(client curator.CuratorFramework, evt curator.CuratorEvent) error {
	tn.tree.logger.Debugf("ProcessResult: %v", evt)
	newStat := evt.Stat()
	switch evt.Type() {
	case curator.EXISTS:
		if tn.parent != nil {
			tn.tree.handleException(errors.New("unexpected EXISTS on non-root node"))
		}
		if evt.Err() == nil {
			tn.state.CompareAndSwap(NodeStateDEAD, NodeStatePENDING)
			tn.wasCreated()
		}
	case curator.CHILDREN:
		switch evt.Err() {
		case zk.ErrNoNode:
			tn.wasDeleted()
		case nil:
			tn.Lock()
			oldChildData := tn.childData
			if oldChildData != nil && oldChildData.Stat().Mzxid == newStat.Mzxid {
				// Only update stat if mzxid is same, otherwise we might obscure
				// GET_DATA event updates.
				tn.childData.SetStat(newStat)
			}
			tn.Unlock()

			if len(evt.Children()) == 0 {
				break
			}
			// Present new children in sorted order for test determinism.
			children := sort.StringSlice(evt.Children())
			sort.Sort(children)
			for _, child := range children {
				if accepted := tn.tree.selector.AcceptChild(path.Join(tn.path, child)); !accepted {
					continue
				}
				tn.Lock()
				if _, exists := tn.children[child]; !exists {
					fullPath := path.Join(tn.path, child)
					node := NewTreeNode(tn.tree, fullPath, tn)
					tn.children[child] = node
					node.wasCreated()
				}
				tn.Unlock()
			}
		}
	case curator.GET_DATA:
		switch evt.Err() {
		case zk.ErrNoNode:
			tn.wasDeleted()
		case nil:
			newChildData := NewChildData(evt.Path(), newStat, evt.Data())
			oldChildData := tn.ChildData()
			if tn.tree.cacheData {
				tn.SwapChildData(newChildData)
			} else {
				tn.SwapChildData(NewChildData(evt.Path(), newStat, nil))
			}

			var added bool
			if tn.parent == nil {
				// We're the singleton root.
				added = tn.state.Swap(NodeStateLIVE) != NodeStateLIVE
			} else {
				added = tn.state.CompareAndSwap(NodeStatePENDING, NodeStateLIVE)
				if !added {
					// Ordinary nodes are not allowed to transition from dead -> live;
					// make sure this isn't a delayed response that came in after death.
					if tn.state.Load() != NodeStateLIVE {
						return nil
					}
				}
			}

			if added {
				tn.tree.publishEvent(TreeCacheEventNodeAdded, newChildData)
			} else {
				if oldChildData == nil || oldChildData.Stat().Mzxid != newStat.Mzxid {
					tn.tree.publishEvent(TreeCacheEventNodeUpdated, newChildData)
				}
			}
		default:
			tn.tree.logger.Printf("Unknown GET_DATA event[%v]: %s", evt.Path(), evt.Err())
		}
	default:
		// An unknown event, probably an error of some sort like connection loss.
		tn.tree.logger.Printf("Unknown event: %v", evt)
		// Don't produce an initialized event on error; reconnect can fix this.
		atomic.AddUint64(&tn.tree.outstandingOps, ^uint64(0))

		return nil
	}

	// Decrease by 1
	if atomic.AddUint64(&tn.tree.outstandingOps, ^uint64(0)) == 0 {
		if !tn.tree.isInitialized.IsSet() {
			tn.tree.isInitialized.Set()
			tn.tree.publishEvent(TreeCacheEventInitialized, nil)
		}
	}
	return nil
}
494855
func (s *Scheduler) SubmitWithOptions(ctx context.Context, app *twelvefactor.Manifest, ss twelvefactor.StatusStream, opts SubmitOptions) error {
	tx, err := s.db.Begin()
	if err != nil {
		return err
	}

	err = s.submit(ctx, tx, app, ss, opts)
	if err != nil {
		tx.Rollback()
		return err
	}
	return tx.Commit()
}
1220833
func (r User_Customer_External_Binding_Phone) CheckPhoneValidationResult(token *string) (resp bool, err error) {
	params := []interface{}{
		token,
	}
	err = r.Session.DoRequest("SoftLayer_User_Customer_External_Binding_Phone", "checkPhoneValidationResult", params, &r.Options, &resp)
	return
}
230895
func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, error) {
	r, s, v, err := signer.SignatureValues(tx, sig)
	if err != nil {
		return nil, err
	}
	cpy := &Transaction{data: tx.data}
	cpy.data.R, cpy.data.S, cpy.data.V = r, s, v
	return cpy, nil
}
1109258
func (v *Validation) ValidationResult(ok bool) *ValidationResult {
	if ok {
		return &ValidationResult{Ok: ok}
	} else {
		return &ValidationResult{Ok: ok, Error: &ValidationError{}, Locale: v.Request.Locale, Translator: v.Translator}
	}
}
239417
func (r *Result) appendResult(node interface{}, pos toml.Position) {
	r.items = append(r.items, node)
	r.positions = append(r.positions, pos)
}
1044608
func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response {
	stub.args = args
	stub.MockTransactionStart(uuid)
	stub.signedProposal = sp
	res := stub.cc.Invoke(stub)
	stub.MockTransactionEnd(uuid)
	return res
}
606951
func (ctp *CTPolicy) GetSCTs(ctx context.Context, cert core.CertDER, expiration time.Time) (core.SCTDERs, error) {
	results := make(chan result, len(ctp.groups))
	subCtx, cancel := context.WithCancel(ctx)
	defer cancel()
	for i, g := range ctp.groups {
		go func(i int, g cmd.CTGroup) {
			sct, err := ctp.race(subCtx, cert, g, expiration)
			// Only one of these will be non-nil
			if err != nil {
				results <- result{err: berrors.MissingSCTsError("CT log group %q: %s", g.Name, err)}
			}
			results <- result{sct: sct}
		}(i, g)
	}
	isPrecert := true
	for _, log := range ctp.informational {
		go func(l cmd.LogDescription) {
			// We use a context.Background() here instead of subCtx because these
			// submissions are running in a goroutine and we don't want them to be
			// cancelled when the caller of CTPolicy.GetSCTs returns and cancels
			// its RPC context.
			uri, key, err := l.Info(expiration)
			if err != nil {
				ctp.log.Errf("unable to get log info: %s", err)
				return
			}
			_, err = ctp.pub.SubmitToSingleCTWithResult(context.Background(), &pubpb.Request{
				LogURL:       &uri,
				LogPublicKey: &key,
				Der:          cert,
				Precert:      &isPrecert,
			})
			if err != nil {
				ctp.log.Warningf("ct submission to informational log %q failed: %s", uri, err)
			}
		}(log)
	}

	var ret core.SCTDERs
	for i := 0; i < len(ctp.groups); i++ {
		res := <-results
		// If any one group fails to get a SCT then we fail out immediately
		// cancel any other in progress work as we can't continue
		if res.err != nil {
			// Returning triggers the defer'd context cancellation method
			return nil, res.err
		}
		ret = append(ret, res.sct)
	}
	return ret, nil
}
738880
func (ps *PassState) WithResultPath(resultPath string) *PassState {
	ps.ResultPath = resultPath
	return ps
}
1146531
func (r *AnnotationSearchResponse) ResultsWithScore(score int) []*Annotation {
	var res []*Annotation
	for _, v := range r.Annotations {
		if r.Scores[v] >= score {
			res = append(res, v)
		}
	}
	return res
}
13783
func (ctp *CTPolicy) SubmitFinalCert(cert []byte, expiration time.Time) {
	falseVar := false
	for _, log := range ctp.finalLogs {
		go func(l cmd.LogDescription) {
			uri, key, err := l.Info(expiration)
			if err != nil {
				ctp.log.Errf("unable to get log info: %s", err)
				return
			}
			_, err = ctp.pub.SubmitToSingleCTWithResult(context.Background(), &pubpb.Request{
				LogURL:       &uri,
				LogPublicKey: &key,
				Der:          cert,
				Precert:      &falseVar,
				StoreSCT:     &falseVar,
			})
			if err != nil {
				ctp.log.Warningf("ct submission of final cert to log %q failed: %s", uri, err)
			}
		}(log)
	}
}