// NewSalt returns a 20 character salt.
3574
func NewSalt() ([]byte, error) {
	salt := make([]byte, 20)
	if _, err := rand.Read(salt); err != nil {
		return nil, err
	}

	// Salt must be a legal UTF8 string.
	for i := 0; i < len(salt); i++ {
		salt[i] &= 0x7f
		if salt[i] == '\x00' || salt[i] == '$' {
			salt[i]++
		}
	}

	return salt, nil
}
232126
func ExtractSalt(ciphertext []byte) ([]byte, error) {
	if len(ciphertext) < SALT_SIZE+aes.BlockSize { //replace these with actual values
		return nil, errors.New("Ciphertext too short")
	}

	return ciphertext[:SALT_SIZE], nil
}
238211
func NewSaltpackDecrypt(arg *SaltpackDecryptArg, pnymResolver saltpack.SymmetricKeyResolver) *SaltpackDecrypt {
	return &SaltpackDecrypt{
		arg:          arg,
		pnymResolver: pnymResolver,
	}
}
320289
func (sim *simra) NewSprite() Spriter {
	return &sprite{
		simra:         sim,
		animationSets: map[string]*AnimationSet{},
	}
}
1370630
func NewShardInfo(keyspace, shard string, value *topodatapb.Shard, version Version) *ShardInfo {
	return &ShardInfo{
		keyspace:  keyspace,
		shardName: shard,
		version:   version,
		Shard:     value,
	}
}
715221
func NewStatter(statsdURL, statsPrefix string) (*LoggingStatter, error) {
	stats, err := statsd.NewClient(statsdURL, statsPrefix)
	if err != nil {
		return nil, err
	}
	return &LoggingStatter{Statter: stats}, nil
}
283155
func (s *sequenceDecs) updateAlt(br *bitReader) {
	// Update all 3 states at once. Approx 20% faster.
	a, b, c := s.litLengths.state.state, s.matchLengths.state.state, s.offsets.state.state

	nBits := a.nbBits + b.nbBits + c.nbBits
	if nBits == 0 {
		s.litLengths.state.state = s.litLengths.state.dt[a.newState]
		s.matchLengths.state.state = s.matchLengths.state.dt[b.newState]
		s.offsets.state.state = s.offsets.state.dt[c.newState]
		return
	}
	bits := br.getBitsFast(nBits)
	lowBits := uint16(bits >> ((c.nbBits + b.nbBits) & 31))
	s.litLengths.state.state = s.litLengths.state.dt[a.newState+lowBits]

	lowBits = uint16(bits >> (c.nbBits & 31))
	lowBits &= bitMask[b.nbBits&15]
	s.matchLengths.state.state = s.matchLengths.state.dt[b.newState+lowBits]

	lowBits = uint16(bits) & bitMask[c.nbBits&15]
	s.offsets.state.state = s.offsets.state.dt[c.newState+lowBits]
}
596151
func (s *Client) NewSubStatter(prefix string) SubStatter {
	var c *Client
	if s != nil {
		c = &Client{
			prefix:  joinPathComp(s.prefix, prefix),
			sender:  s.sender,
			sampler: s.sampler,
		}
	}
	return c
}
1339047
func NewString(key, val string) *api.GenericResource {
	return &api.GenericResource{
		Resource: &api.GenericResource_NamedResourceSpec{
			NamedResourceSpec: &api.NamedGenericResource{
				Kind:  key,
				Value: val,
			},
		},
	}
}
500750
func NewSaltedCipher(key, salt []byte) (*Cipher, error) {
	var result Cipher
	k := len(key)
	if k < 4 {
		return nil, KeySizeError(k)
	}
	initCipher(key, &result)
	expandKeyWithSalt(key, salt, &result)
	return &result, nil
}
861694
func (g Generator) GetSalt(size int) []byte {
	salt := make([]byte, size)
	if _, err := rand.Read(salt); err != nil {
		panic(err)
	}
	return salt
}
535839
func NewStringSet(vs ...string) StringSet {
	s := &stringSet{make(map[string]struct{})}
	s.Add(vs...)
	return s
}
1295617
func Salt(rounds ...int) (string, error) {
	rb, err := SaltBytes(rounds...)
	return string(rb), err
}
726124
func NewSearchFormat(source string) formatter.Format {
	switch source {
	case "":
		return defaultSearchTableFormat
	case formatter.TableFormatKey:
		return defaultSearchTableFormat
	}
	return formatter.Format(source)
}
1022762
func NewStatsd(addr, prefix string) (*Statsd, error) {
	c, err := statsd.NewClient(addr, prefix)
	if err != nil {
		return nil, err
	}
	return &Statsd{
		client: c,
	}, nil
}
980979
func loadSalt(id string) ([keySize]byte, error) {

	var salt [keySize]byte

	saltFile := fmt.Sprintf(saltSuffixFormat, id)
	if keyFileExists(saltFile) {
		return readKey(saltFile, keysFolderPrefixFormat)
	}

	// generate the random salt
	salt, err := generateSalt()
	if err != nil {
		return salt, err
	}

	// write the salt to the file with its prefix
	if err := writeKey(saltFile, keysFolderPrefixFormat, salt[:]); err != nil {
		return salt, err
	}

	// return the salt and no error
	return salt, nil
}
171376
func NewSetMediaTextArgs(styleSheetID StyleSheetID, rang SourceRange, text string) *SetMediaTextArgs {
	args := new(SetMediaTextArgs)
	args.StyleSheetID = styleSheetID
	args.Range = rang
	args.Text = text
	return args
}