// VReadKey - cf Read but for versioned secret - return the value of the key and the version
354027
func (c *VaultClient) VReadKey(path, key string) (string, int64, error) {
	data, ver, err := c.VRead(path)
	if err != nil {
		return "", -1, err
	}
	val, ok := data[key]
	if !ok {
		return "", -1, ErrKeyNotFound
	}
	return val.(string), ver, nil
}
386164
func (v *KeyValue_SetValue_Args) GetKey() (o string) {
	if v != nil && v.Key != nil {
		return *v.Key
	}

	return
}
1286422
func (kp *KeyPair) ReadFromFile(privateKeyPath string, publicKeyPath string) error {
	b, err := ioutil.ReadFile(privateKeyPath)
	if err != nil {
		return err
	}
	kp.PrivateKey = b

	b, err = ioutil.ReadFile(publicKeyPath)
	if err != nil {
		return err
	}
	kp.PublicKey = b

	return nil
}
454304
func (ks *fileBasedKeyStore) GetKey(ski []byte) (bccsp.Key, error) {
	// Validate arguments
	if len(ski) == 0 {
		return nil, errors.New("Invalid SKI. Cannot be of zero length.")
	}

	suffix := ks.getSuffix(hex.EncodeToString(ski))

	switch suffix {
	case "key":
		// Load the key
		key, err := ks.loadKey(hex.EncodeToString(ski))
		if err != nil {
			return nil, fmt.Errorf("Failed loading key [%x] [%s]", ski, err)
		}

		return &aesPrivateKey{key, false}, nil
	case "sk":
		// Load the private key
		key, err := ks.loadPrivateKey(hex.EncodeToString(ski))
		if err != nil {
			return nil, fmt.Errorf("Failed loading secret key [%x] [%s]", ski, err)
		}

		switch key.(type) {
		case *ecdsa.PrivateKey:
			return &ecdsaPrivateKey{key.(*ecdsa.PrivateKey)}, nil
		case *rsa.PrivateKey:
			return &rsaPrivateKey{key.(*rsa.PrivateKey)}, nil
		default:
			return nil, errors.New("Secret key type not recognized")
		}
	case "pk":
		// Load the public key
		key, err := ks.loadPublicKey(hex.EncodeToString(ski))
		if err != nil {
			return nil, fmt.Errorf("Failed loading public key [%x] [%s]", ski, err)
		}

		switch key.(type) {
		case *ecdsa.PublicKey:
			return &ecdsaPublicKey{key.(*ecdsa.PublicKey)}, nil
		case *rsa.PublicKey:
			return &rsaPublicKey{key.(*rsa.PublicKey)}, nil
		default:
			return nil, errors.New("Public key type not recognized")
		}
	default:
		return ks.searchKeystoreForSKI(ski)
	}
}
861878
func (k *KdfParameters) readKdfParameters(data []byte) error {
	dict := new(VariantDictionary)
	if err := dict.readVariantDictionary(data); err != nil {
		return err
	}

	k.RawData = dict
	for _, item := range dict.Items {
		switch string(item.Name) {
		case "$UUID":
			k.UUID = item.Value
		case "R":
			k.Rounds = binary.LittleEndian.Uint64(item.Value)
		case "S":
			copy(k.Salt[:], item.Value[:32])
		case "P":
			k.Parallelism = binary.LittleEndian.Uint32(item.Value)
		case "M":
			k.Memory = binary.LittleEndian.Uint64(item.Value)
		case "I":
			k.Iterations = binary.LittleEndian.Uint64(item.Value)
		case "V":
			k.Version = binary.LittleEndian.Uint32(item.Value)
		case "K":
			k.SecretKey = item.Value
		case "A":
			k.AssocData = item.Value
		default:
			return ErrUnknownParameterID(string(item.Name))
		}
	}
	return nil
}
759414
func SharedKey(secretKey [32]byte, publicKey [32]byte) ([32]byte, error) {
	var sharedKey [32]byte
	curve25519.ScalarMult(&sharedKey, &secretKey, &publicKey)
	c := byte(0)
	for i := 0; i < 32; i++ {
		c |= sharedKey[i]
	}
	if c == 0 {
		return sharedKey, errors.New("weak public key")
	}
	var nonce [16]byte
	chacha.HChaCha20(&sharedKey, &nonce, &sharedKey)
	return sharedKey, nil
}
1077442
func (vd *VariantDictionary) readVariantDictionary(data []byte) error {
	r := bytes.NewReader(data)

	if err := binary.Read(r, binary.LittleEndian, &vd.Version); err != nil {
		return err
	}

	for {
		vdi := new(VariantDictionaryItem)
		if err := binary.Read(r, binary.LittleEndian, &vdi.Type); err != nil {
			return err
		}

		if vdi.Type != 0x00 {
			if err := binary.Read(r, binary.LittleEndian, &vdi.NameLength); err != nil {
				return err
			}
			vdi.Name = make([]byte, vdi.NameLength)
			if err := binary.Read(r, binary.LittleEndian, &vdi.Name); err != nil {
				return err
			}

			if err := binary.Read(r, binary.LittleEndian, &vdi.ValueLength); err != nil {
				return err
			}
			vdi.Value = make([]byte, vdi.ValueLength)
			if err := binary.Read(r, binary.LittleEndian, &vdi.Value); err != nil {
				return err
			}

			vd.Items = append(vd.Items, vdi)
		} else {
			break
		}
	}
	return nil
}
316082
func (c *agency) ReadKey(ctx context.Context, key []string, value interface{}) error {
	conn := c.conn
	req, err := conn.NewRequest("POST", "_api/agency/read")
	if err != nil {
		return driver.WithStack(err)
	}
	fullKey := createFullKey(key)
	input := [][]string{{fullKey}}
	req, err = req.SetBody(input)
	if err != nil {
		return driver.WithStack(err)
	}
	//var raw []byte
	//ctx = driver.WithRawResponse(ctx, &raw)
	resp, err := conn.Do(ctx, req)
	if err != nil {
		return driver.WithStack(err)
	}
	if err := resp.CheckStatus(200, 201, 202); err != nil {
		return driver.WithStack(err)
	}
	//fmt.Printf("Agent response: %s\n", string(raw))
	elems, err := resp.ParseArrayBody()
	if err != nil {
		return driver.WithStack(err)
	}
	if len(elems) != 1 {
		return driver.WithStack(fmt.Errorf("Expected 1 element, got %d", len(elems)))
	}
	// If empty key parse directly
	if len(key) == 0 {
		if err := elems[0].ParseBody("", &value); err != nil {
			return driver.WithStack(err)
		}
	} else {
		// Now remove all wrapping objects for each key element
		var rawObject map[string]interface{}
		if err := elems[0].ParseBody("", &rawObject); err != nil {
			return driver.WithStack(err)
		}
		var rawMsg interface{}
		for keyIndex := 0; keyIndex < len(key); keyIndex++ {
			if keyIndex > 0 {
				var ok bool
				rawObject, ok = rawMsg.(map[string]interface{})
				if !ok {
					return driver.WithStack(fmt.Errorf("Data is not an object at key %s", key[:keyIndex+1]))
				}
			}
			var found bool
			rawMsg, found = rawObject[key[keyIndex]]
			if !found {
				return driver.WithStack(KeyNotFoundError{Key: key[:keyIndex+1]})
			}
		}
		// Encode to json ...
		encoded, err := json.Marshal(rawMsg)
		if err != nil {
			return driver.WithStack(err)
		}
		// and decode back into result
		if err := json.Unmarshal(encoded, &value); err != nil {
			return driver.WithStack(err)
		}
	}

	//	fmt.Printf("result as JSON: %s\n", rawResult)
	return nil
}
126735
func (ks *inmemoryKeyStore) StoreKey(k bccsp.Key) error {
	if k == nil {
		return errors.New("key is nil")
	}

	ski := hex.EncodeToString(k.SKI())

	ks.m.Lock()
	defer ks.m.Unlock()

	if _, found := ks.keys[ski]; found {
		return errors.Errorf("ski %x already exists in the keystore", k.SKI())
	}
	ks.keys[ski] = k

	return nil
}
1353616
func DecodeRecordKey(key kv.Key) (tableID int64, handle int64, err error) {
	if len(key) <= prefixLen {
		return 0, 0, errInvalidRecordKey.GenWithStack("invalid record key - %q", key)
	}

	k := key
	if !hasTablePrefix(key) {
		return 0, 0, errInvalidRecordKey.GenWithStack("invalid record key - %q", k)
	}

	key = key[tablePrefixLength:]
	key, tableID, err = codec.DecodeInt(key)
	if err != nil {
		return 0, 0, errors.Trace(err)
	}

	if !hasRecordPrefixSep(key) {
		return 0, 0, errInvalidRecordKey.GenWithStack("invalid record key - %q", k)
	}

	key = key[recordPrefixSepLength:]
	key, handle, err = codec.DecodeInt(key)
	if err != nil {
		return 0, 0, errors.Trace(err)
	}
	return
}
1191234
func (c *Config) ReadKiteKey() error {
	key, err := kitekey.Parse()
	if err != nil {
		return err
	}

	return c.ReadToken(key)
}
43901
func (c *ClusterManager) SecretSetDefaultSecretKey(secretKey string, override bool) error {
	return c.secretsManager.SecretSetDefaultSecretKey(secretKey, override)
}
701031
func (d *Descriptor) HandleReadFunc(f func(rsp ResponseWriter, req *ReadRequest)) {
	d.HandleRead(ReadHandlerFunc(f))
}
799915
func (c SimpleFSClient) SimpleFSRead(ctx context.Context, __arg SimpleFSReadArg) (res FileContent, err error) {
	err = c.Cli.Call(ctx, "keybase.1.SimpleFS.simpleFSRead", []interface{}{__arg}, &res)
	return
}
539708
func (k *KeyCacheStandard) GetTLFCryptKey(tlf tlf.ID, keyGen kbfsmd.KeyGen) (
	kbfscrypto.TLFCryptKey, error) {
	cacheKey := keyCacheKey{tlf, keyGen}
	if entry, ok := k.lru.Get(cacheKey); ok {
		if key, ok := entry.(kbfscrypto.TLFCryptKey); ok {
			return key, nil
		}
		// shouldn't really be possible
		return kbfscrypto.TLFCryptKey{}, KeyCacheHitError{tlf, keyGen}
	}
	return kbfscrypto.TLFCryptKey{}, KeyCacheMissError{tlf, keyGen}
}
339668
func StoreKey(dir, auth string, scryptN, scryptP int) (common.Address, error) {
	_, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP, false}, rand.Reader, auth)
	return a.Address, err
}
453085
func (m *Mocker) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) {
	return []string{"unsupported"}, nil
}