// ParseHumanReadableKey returns a key as bytes from recognized serializations of
// said keys
556840
func ParseHumanReadableKey(key string) ([]byte, error) {
	if !strings.HasPrefix(key, humanReadablePrefix) {
		return nil, fmt.Errorf("invalid key string")
	}
	keyBytes, err := base64.RawStdEncoding.DecodeString(strings.TrimPrefix(key, humanReadablePrefix))
	if err != nil {
		return nil, fmt.Errorf("invalid key string")
	}
	return keyBytes, nil
}
1029454
func ParseAES128Key(input string) (key AES128Key, err error) {
	bytes, err := ParseHEX(input, 16)
	if err != nil {
		return
	}
	copy(key[:], bytes)
	return
}
1021909
func decodeRowKey(v string) (*rowKey, error) {
	keyParts := strings.SplitN(v, "~", 3)
	if len(keyParts) != 3 {
		return nil, errMalformedRowKey
	}

	hashEnc, idxEnc, countEnc := keyParts[0], keyParts[1], keyParts[2]
	if base64.URLEncoding.DecodedLen(len(hashEnc)) < sha256.Size {
		return nil, errMalformedRowKey
	}

	// Decode encoded project/path hash.
	var err error
	rk := rowKey{}
	rk.pathHash, err = base64.URLEncoding.DecodeString(hashEnc)
	if err != nil {
		return nil, errMalformedRowKey
	}

	// Decode index.
	rk.index, err = readHexInt64(idxEnc)
	if err != nil {
		return nil, err
	}

	// If a count is available, decode that as well.
	rk.count, err = readHexInt64(countEnc)
	if err != nil {
		return nil, err
	}

	return &rk, nil
}
193108
func normalizedKey(key string) string {
	addr, err := standardizeAddress(key)
	if err != nil {
		return key
	}
	return addr.Normalize().Key()
}
519446
func ParseJSONKey(jsonKeyFile io.Reader) (*Credentials, error) {
	jsonKey, err := ioutil.ReadAll(jsonKeyFile)
	if err != nil {
		return nil, errors.Trace(err)
	}
	values, err := parseJSONKey(jsonKey)
	if err != nil {
		return nil, errors.Trace(err)
	}
	creds, err := NewCredentials(values)
	if err != nil {
		return nil, errors.Trace(err)
	}
	creds.JSONKey = jsonKey
	return creds, nil
}
854868
func hashKey(key string) uint64 {
	hash := offset64

	for _, b := range bytesView(key) {
		hash ^= uint64(b)
		hash *= prime64
	}
	return hash
}
765271
func ParseKeys(data map[string]interface{}, pairs [][]string) error {
	for _, args := range pairs {
		key, t := args[0], args[1]
		if err := ParseKey(data, key, t); err != nil {
			return err
		}
	}
	return nil
}
465472
func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) error) error {
	d := encoding.NewDecbufAt(bs, int(off), castagnoliTable)
	cnt := d.Be32()

	for d.Err() == nil && d.Len() > 0 && cnt > 0 {
		keyCount := d.Uvarint()
		keys := make([]string, 0, keyCount)

		for i := 0; i < keyCount; i++ {
			keys = append(keys, d.UvarintStr())
		}
		o := d.Uvarint64()
		if d.Err() != nil {
			break
		}
		if err := f(keys, o); err != nil {
			return err
		}
		cnt--
	}
	return d.Err()
}
81756
func decodeMaxKey(rd *bufio.Reader) (string, MaxKey, error) {
	// name
	name, err := readCstring(rd)
	if err != nil {
		return "", MaxKey{}, err
	}
	return name, MaxKey{}, nil
}
1189288
func ParsePublicKey(in []byte) (out PublicKey, err error) {
	return gossh.ParsePublicKey(in)
}
1117132
func NewHumanReadablePrinter(noHeaders, withNamespace bool, wide bool, showAll bool, columnLabels []string) *HumanReadablePrinter {
	printer := &HumanReadablePrinter{
		handlerMap:    make(map[reflect.Type]*handlerEntry),
		noHeaders:     noHeaders,
		withNamespace: withNamespace,
		wide:          wide,
		showAll:       showAll,
		columnLabels:  columnLabels,
	}
	printer.addDefaultHandlers()
	return printer
}
1323330
func HumanReadable(blob []byte) (string, error) {
	reader := bytes.NewReader(blob)

	var buf bytes.Buffer
	writer := bufio.NewWriter(&buf)

	err := shared.TokenPump{
		TokenSource: cbor.NewDecoder(cbor.DecodeOptions{}, reader),
		TokenSink:   pretty.NewEncoder(writer),
	}.Run()

	if err != nil {
		return "", err
	}

	if err = writer.Flush(); err != nil {
		return "", err
	}

	return buf.String(), nil
}
1061559
func parsePartitionKey(pkStr string) []string {
	pkStr = strings.TrimSpace(pkStr)
	var pks []string
	partitionKeys := strings.Split(pkStr, ",")
	for _, pk := range partitionKeys {
		npk := strings.TrimSpace(pk)
		if len(pk) > 0 {
			pks = append(pks, npk)
		}
	}
	return pks
}
523404
func (c *VaultClient) ReadKey(path, key string) (string, error) {
	data, err := c.Read(path)
	if err != nil {
		return "", err
	}
	val, ok := data[key]
	if !ok {
		return "", errors.New("key not found")
	}
	return val.(string), nil
}
607451
func parseAuthorizedKeys(bytes []byte, allowedLogins []string) (services.CertAuthority, services.Role, error) {
	pubkey, comment, _, _, err := ssh.ParseAuthorizedKey(bytes)
	if err != nil {
		return nil, nil, trace.Wrap(err)
	}

	comments, err := url.ParseQuery(comment)
	if err != nil {
		return nil, nil, trace.Wrap(err)
	}
	clusterName := comments.Get("clustername")
	if clusterName == "" {
		return nil, nil, trace.BadParameter("no clustername provided")
	}

	// create a new certificate authority
	ca := services.NewCertAuthority(
		services.UserCA,
		clusterName,
		nil,
		[][]byte{ssh.MarshalAuthorizedKey(pubkey)},
		nil)

	// transform old allowed logins into roles
	role := services.RoleForCertAuthority(ca)
	role.SetLogins(services.Allow, allowedLogins)
	ca.AddRole(role.GetName())

	return ca, role, nil
}
637229
func (p *parser) readZipMap(key KeyObject, r io.Reader) error {
	data, err := p.readString(r)
	if err != nil {
		return err
	}

	dr := bufio.NewReader(bytes.NewReader(data.([]byte)))

	// Hash map length, valid only when < 254
	mapLen, err := dr.ReadByte()
	if err != nil {
		return err
	}

	b, err := dr.ReadByte()
	if err != nil {
		return err
	}

	// This is fugly
	// We need the length of the hashmap before we start sending hashmap entries
	// so that the metadata we send is before the data, and is also correct.
	// Users will rely on this to know when to end processing entries for a given hashmap.
	//
	// This is why we have to buffer the entries and then sending them once we processed the RDB data.
	var results []HashEntry
	if mapLen >= 254 {
		results = make([]HashEntry, 0)
	} else {
		if p.ctx.HashMetadataCh != nil {
			p.ctx.HashMetadataCh <- HashMetadata{Key: key, Len: int64(mapLen)}
		}
	}

	for b != 0xFF {
		// Entry key data
		l, err := readZipMapLength(dr, b)
		if err != nil {
			return err
		}

		entryKey, err := readBytes(dr, l)
		if err != nil {
			return err
		}

		// Entry value data
		b, err = dr.ReadByte()
		if err != nil {
			return err
		}

		l, err = readZipMapLength(dr, b)
		if err != nil {
			return err
		}

		// FYI, that free shit is weird
		free, err := dr.ReadByte()
		if err != nil {
			return err
		}

		entryValue, err := readBytes(dr, l)
		if err != nil {
			return err
		}

		// skip if necessary
		if free > 0 {
			if _, err = readBytes(dr, int64(free)); err != nil {
				return err
			}
		}

		if mapLen >= 254 {
			results = append(results, HashEntry{Key: entryKey, Value: entryValue})
		} else {
			if p.ctx.HashDataCh != nil {
				p.ctx.HashDataCh <- HashEntry{Key: entryKey, Value: entryValue}
			}
		}

		b, err = dr.ReadByte()
		if err != nil {
			return err
		}
	}

	if mapLen >= 254 {
		if p.ctx.HashMetadataCh != nil {
			p.ctx.HashMetadataCh <- HashMetadata{Key: key, Len: int64(len(results))}
		}
		if p.ctx.HashDataCh != nil {
			for _, e := range results {
				p.ctx.HashDataCh <- e
			}
		}
	}

	return nil
}
672003
func parsePubKey(in []byte, algo string) (pubKey PublicKey, rest []byte, err error) {
	switch algo {
	case KeyAlgoRSA:
		return parseRSA(in)
	case KeyAlgoDSA:
		return parseDSA(in)
	case KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521:
		return parseECDSA(in)
	case CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01, CertAlgoECDSA384v01, CertAlgoECDSA521v01:
		cert, err := parseCert(in, certToPrivAlgo(algo))
		if err != nil {
			return nil, nil, err
		}
		return cert, nil, nil
	}
	return nil, nil, fmt.Errorf("ssh: unknown key algorithm: %v", err)
}