// identifyAndAddRecipients adds the KID corresponding to each recipient to the recipientMap
427429
func (e *SaltpackRecipientKeyfinderEngine) identifyAndAddRecipients(m libkb.MetaContext) error {
	// TODO make these lookups in parallel (maybe using sync.WaitGroup)
	for _, u := range e.Arg.Recipients {
		err := e.identifyAndAddUserRecipient(m, u)
		if err != nil {
			return err
		}
	}
	for _, u := range e.Arg.TeamRecipients {
		err := e.lookupAndAddTeam(m, u)
		if err != nil {
			return err
		}
	}
	return nil
}
1199764
func identifyUsers(
	ctx context.Context, nug idutil.NormalizedUsernameGetter,
	identifier idutil.Identifier,
	names map[keybase1.UserOrTeamID]kbname.NormalizedUsername,
	t tlf.Type, offline keybase1.OfflineAvailability) error {
	eg, ctx := errgroup.WithContext(ctx)

	// TODO: limit the number of concurrent identifies?
	// TODO: implement a version of errgroup with limited concurrency.
	for id, name := range names {
		// Capture range variables.
		id, name := id, name
		eg.Go(func() error {
			return identifyUser(ctx, nug, identifier, name, id, t, offline)
		})
	}

	return eg.Wait()
}
162162
func IsCheckRecipients(ctx context.Context) bool {
	bv, ok := ctx.Value(ctxKeyCheckRecipients).(bool)
	if !ok {
		return false
	}
	return bv
}
205685
func (s *Server) readRecipients(c *Connection) {
	text := c.read()
	s.addMessageLine(text)

	c.write("250 Recipient")
	text = c.read()
	for strings.Contains(text, "RCPT") {
		s.addMessageLine(text)
		c.write("250 Recipient")
		text = c.read()
	}
}
814390
func identifyUser(ctx context.Context, nug idutil.NormalizedUsernameGetter,
	identifier idutil.Identifier, name kbname.NormalizedUsername,
	id keybase1.UserOrTeamID, t tlf.Type,
	offline keybase1.OfflineAvailability) error {
	// Check to see if identify should be skipped altogether.
	ei := GetExtendedIdentify(ctx)
	if ei.Behavior == keybase1.TLFIdentifyBehavior_CHAT_SKIP {
		return nil
	}

	var reason string
	nameAssertion := name.String()
	isImplicit := false
	switch t {
	case tlf.Public:
		if id.IsTeam() {
			isImplicit = true
		}
		reason = "You accessed a public folder."
	case tlf.Private:
		if id.IsTeam() {
			isImplicit = true
			reason = fmt.Sprintf(
				"You accessed a folder for private team %s.", nameAssertion)
		} else {
			reason = fmt.Sprintf(
				"You accessed a private folder with %s.", nameAssertion)
		}
	case tlf.SingleTeam:
		reason = fmt.Sprintf(
			"You accessed a folder for private team %s.", nameAssertion)
		nameAssertion = "team:" + nameAssertion
	}
	var resultName kbname.NormalizedUsername
	var resultID keybase1.UserOrTeamID
	if isImplicit {
		assertions, extensionSuffix, err := tlf.SplitExtension(name.String())
		if err != nil {
			return err
		}
		iteamInfo, err := identifier.IdentifyImplicitTeam(
			ctx, assertions, extensionSuffix, t, reason, offline)
		if err != nil {
			return err
		}
		resultName = iteamInfo.Name
		resultID = iteamInfo.TID.AsUserOrTeam()
	} else {
		var err error
		resultName, resultID, err =
			identifier.Identify(ctx, nameAssertion, reason, offline)
		if err != nil {
			// Convert libkb.NoSigChainError into one we can report.  (See
			// KBFS-1252).
			if _, ok := err.(libkb.NoSigChainError); ok {
				return idutil.NoSigChainError{User: name}
			}
			return err
		}
	}
	// The names of implicit teams can change out from under us,
	// unlike for regular users, so don't require that they remain the
	// same.
	if resultName != name && !isImplicit {
		return fmt.Errorf("Identify returned name=%s, expected %s",
			resultName, name)
	}
	if resultID != id {
		return fmt.Errorf("Identify returned uid=%s, expected %s", resultID, id)
	}
	return nil
}
844184
func GetPrefixesFromCIDRSet(rules api.CIDRRuleSlice) []*net.IPNet {
	cidrs := api.ComputeResultantCIDRSet(rules)
	return getPrefixesFromCIDR(cidrs)
}
55994
func (s *ReceiptRule) SetRecipients(v []*string) *ReceiptRule {
	s.Recipients = v
	return s
}
1311380
func marshalRecipients(r []string) []byte {
	if len(r) == 0 {
		return []byte("\n")
	}

	// deduplicate
	m := make(map[string]struct{}, len(r))
	for _, k := range r {
		m[k] = struct{}{}
	}
	// sort
	keys := make([]string, 0, len(m))
	for k := range m {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	out := bytes.Buffer{}
	for _, k := range keys {
		_, _ = out.WriteString(k)
		_, _ = out.WriteString("\n")
	}

	return out.Bytes()
}
895865
func (c *fabricCAAdapter) GetAllIdentities(key core.Key, cert []byte, caname string) ([]*api.IdentityResponse, error) {

	logger.Debug("Retrieving all identities")

	registrar, err := c.newIdentity(key, cert)
	if err != nil {
		return nil, errors.Wrap(err, "failed to create CA signing identity")
	}

	var identities []caapi.IdentityInfo

	err = registrar.GetAllIdentities(caname, func(decoder *json.Decoder) error {
		var identity caapi.IdentityInfo
		decodeErr := decoder.Decode(&identity)
		if decodeErr != nil {
			return decodeErr
		}

		identities = append(identities, identity)
		return nil
	})

	if err != nil {
		return nil, errors.Wrap(err, "failed to get identities")
	}

	return getIdentityResponses(c.caClient.Config.CAName, identities), nil
}
157146
func (kl KeyList) Recipients() []string {
	l := make([]string, 0, len(kl))
	for _, k := range kl {
		l = append(l, k.ID())
	}
	sort.Strings(l)
	return l
}
6730
func (i IdentifierSet) AddIdentifiers(idents Identifiers) {
	for _, ident := range idents {
		i.Add(ident)
	}
}
331854
func (s *BouncedRecipientInfo) SetRecipientDsnFields(v *RecipientDsnFields) *BouncedRecipientInfo {
	s.RecipientDsnFields = v
	return s
}
514431
func WithRecipientFunc(ctx context.Context, imf store.RecipientCallback) context.Context {
	return context.WithValue(ctx, ctxKeyRecipientFunc, imf)
}
223992
func (s *Store) RemoveRecipient(ctx context.Context, id string) error {
	keys, err := s.crypto.FindPublicKeys(ctx, id)
	if err != nil {
		out.Cyan(ctx, "Warning: Failed to get GPG Key Info for %s: %s", id, err)
	}

	rs, err := s.GetRecipients(ctx, "")
	if err != nil {
		return errors.Wrapf(err, "failed to read recipient list")
	}

	nk := make([]string, 0, len(rs)-1)
RECIPIENTS:
	for _, k := range rs {
		if k == id {
			continue RECIPIENTS
		}
		// if the key is available locally we can also match the id against
		// the fingerprint
		for _, key := range keys {
			if strings.HasSuffix(key, k) {
				continue RECIPIENTS
			}
		}
		nk = append(nk, k)
	}

	if len(rs) == len(nk) {
		return errors.Errorf("recipient not in store")
	}

	if err := s.saveRecipients(ctx, nk, "Removed Recipient "+id, true); err != nil {
		return errors.Wrapf(err, "failed to save recipients")
	}

	return s.reencrypt(WithReason(ctx, "Removed Recipient "+id))
}
979599
func packageIdentityName(f *descriptor.FileDescriptorProto) string {
	if f.Options != nil && f.Options.GoPackage != nil {
		gopkg := f.Options.GetGoPackage()
		idx := strings.LastIndex(gopkg, "/")
		if idx < 0 {
			return gopkg
		}

		return gopkg[idx+1:]
	}

	if f.Package == nil {
		base := filepath.Base(f.GetName())
		ext := filepath.Ext(base)
		return strings.TrimSuffix(base, ext)
	}
	return f.GetPackage()
}
89249
func (dl *DaemonLocal) Identify(
	ctx context.Context, assertion, _ string,
	offline keybase1.OfflineAvailability) (
	kbname.NormalizedUsername, keybase1.UserOrTeamID, error) {
	// The local daemon doesn't need to distinguish resolves from
	// identifies.
	return dl.Resolve(ctx, assertion, offline)
}
139402
func WithEditRecipients(ctx context.Context, bv bool) context.Context {
	return context.WithValue(ctx, ctxKeyEditRecipients, bv)
}