// NewUserId returns a UserId or nil if any of the arguments contain invalid
// characters. The invalid characters are '\x00', '(', ')', '<' and '>'
336524
func NewUserId(name, comment, email string) *UserId {
	// RFC 4880 doesn't deal with the structure of userid strings; the
	// name, comment and email form is just a convention. However, there's
	// no convention about escaping the metacharacters and GPG just refuses
	// to create user ids where, say, the name contains a '('. We mirror
	// this behaviour.

	if hasInvalidCharacters(name) || hasInvalidCharacters(comment) || hasInvalidCharacters(email) {
		return nil
	}

	uid := new(UserId)
	uid.Name, uid.Comment, uid.Email = name, comment, email
	uid.Id = name
	if len(comment) > 0 {
		if len(uid.Id) > 0 {
			uid.Id += " "
		}
		uid.Id += "("
		uid.Id += comment
		uid.Id += ")"
	}
	if len(email) > 0 {
		if len(uid.Id) > 0 {
			uid.Id += " "
		}
		uid.Id += "<"
		uid.Id += email
		uid.Id += ">"
	}
	return uid
}
278160
func NewUUID(s string) (*UUID, error) {
	s = strings.Replace(s, "-", "", -1)
	if len(s) != 32 {
		return nil, errors.New("bad UUID length != 32")
	}
	dec, err := hex.DecodeString(s)
	if err != nil {
		return nil, err
	}
	var u UUID
	for i, b := range dec {
		u[i] = b
	}
	return &u, nil
}
97970
func lookupUserid(id int) string {
	u, err := user.LookupId(strconv.Itoa(id))
	if err == nil {
		return u.Username
	}
	if _, ok := err.(user.UnknownUserIdError); ok {
		return ""
	}
	if parsedPasswd {
		return ""
	}
	parsedPasswd = true
	populateMap(uidName, nil, "/etc/passwd")
	return uidName[id]
}
149786
func NewUserDic(path string) (UserDic, error) {
	f, err := os.Open(path)
	if err != nil {
		return UserDic{}, err
	}
	defer f.Close()

	r, err := NewUserDicRecords(f)
	if err != nil {
		return UserDic{}, err
	}
	return r.NewUserDic()
}
683797
func (s *ActivateUserInput) SetUserId(v string) *ActivateUserInput {
	s.UserId = &v
	return s
}
1138798
func (f *contextFactory) newId(name string) string {
	return fmt.Sprintf("%s-%s-%d", f.unit.Name(), name, f.rand.Int63())
}
555647
func (s *ResetPasswordInput) SetUserId(v string) *ResetPasswordInput {
	s.UserId = &v
	return s
}
427238
func (s *DescribeActivitiesInput) SetUserId(v string) *DescribeActivitiesInput {
	s.UserId = &v
	return s
}
1163110
func (s *GetUserEndpointsInput) SetUserId(v string) *GetUserEndpointsInput {
	s.UserId = &v
	return s
}
1339089
func (s *UpdateUserPoolInput) SetUserPoolId(v string) *UpdateUserPoolInput {
	s.UserPoolId = &v
	return s
}
197380
func (u UAA) UserByID(id string) (User, error) {
	return u.UserByIDCommand(u, id)
}
81089
func RandomID(prefix string) (string, error) {
	buf, err := RandBytes(32)
	if err != nil {
		return "", err
	}
	str := base32.StdEncoding.EncodeToString(buf)
	str = strings.Replace(str, "=", "", -1)
	str = prefix + str
	return str, nil
}
931988
func (s *EnvironmentMember) SetUserId(v string) *EnvironmentMember {
	s.UserId = &v
	return s
}
1327746
func NewID() string {
	b := make([]byte, 8)
	rand.Read(b)
	return fmt.Sprintf("%x", b)
}
97585
func (s *GetUserInput) SetUserId(v string) *GetUserInput {
	s.UserId = &v
	return s
}
1046012
func parseUserId(id string) (name, comment, email string) {
	var n, c, e struct {
		start, end int
	}
	var state int

	for offset, rune := range id {
		switch state {
		case 0:
			// Entering name
			n.start = offset
			state = 1
			fallthrough
		case 1:
			// In name
			if rune == '(' {
				state = 2
				n.end = offset
			} else if rune == '<' {
				state = 5
				n.end = offset
			}
		case 2:
			// Entering comment
			c.start = offset
			state = 3
			fallthrough
		case 3:
			// In comment
			if rune == ')' {
				state = 4
				c.end = offset
			}
		case 4:
			// Between comment and email
			if rune == '<' {
				state = 5
			}
		case 5:
			// Entering email
			e.start = offset
			state = 6
			fallthrough
		case 6:
			// In email
			if rune == '>' {
				state = 7
				e.end = offset
			}
		default:
			// After email
		}
	}
	switch state {
	case 1:
		// ended in the name
		n.end = len(id)
	case 3:
		// ended in comment
		c.end = len(id)
	case 6:
		// ended in email
		e.end = len(id)
	}

	name = strings.TrimSpace(id[n.start:n.end])
	comment = strings.TrimSpace(id[c.start:c.end])
	email = strings.TrimSpace(id[e.start:e.end])
	return
}
1211028
func (s *UpdateUserHierarchyInput) SetUserId(v string) *UpdateUserHierarchyInput {
	s.UserId = &v
	return s
}