// `boxB64` should be a stellar1.EncryptedRelaySecret
190497
func DecryptB64(mctx libkb.MetaContext, teamID keybase1.TeamID, boxB64 string) (res stellar1.RelayContents, err error) {
	pack, err := base64.StdEncoding.DecodeString(boxB64)
	if err != nil {
		return res, fmt.Errorf("error decoding relay box: %v", err)
	}
	var box stellar1.EncryptedRelaySecret
	err = libkb.MsgpackDecode(&box, pack)
	if err != nil {
		return res, err
	}
	appKey, err := getKeyForDecryption(mctx, teamID, box.Gen)
	if err != nil {
		return res, err
	}
	return decrypt(box, appKey)
}
587271
func unbox(encBundle stellar1.EncryptedAccountBundle, hash stellar1.Hash /* visB64 string, */, puk libkb.PerUserKeySeed) (*stellar1.AccountBundle, stellar1.AccountBundleVersion, error) {
	versioned, err := decrypt(encBundle, puk)
	if err != nil {
		return nil, 0, err
	}
	version, err := versioned.Version()
	if err != nil {
		return nil, 0, err
	}

	var bundleOut stellar1.AccountBundle
	switch version {
	case stellar1.AccountBundleVersion_V1:
		secretV1 := versioned.V1()
		bundleOut = stellar1.AccountBundle{
			AccountID: secretV1.AccountID,
			Signers:   secretV1.Signers,
		}
	case stellar1.AccountBundleVersion_V2,
		stellar1.AccountBundleVersion_V3,
		stellar1.AccountBundleVersion_V4,
		stellar1.AccountBundleVersion_V5,
		stellar1.AccountBundleVersion_V6,
		stellar1.AccountBundleVersion_V7,
		stellar1.AccountBundleVersion_V8,
		stellar1.AccountBundleVersion_V9,
		stellar1.AccountBundleVersion_V10:
		return nil, 0, errors.New("unsupported AccountBundleSecret version")
	default:
		return nil, 0, errors.New("invalid AccountBundle version")
	}

	bundleOut.OwnHash = hash
	if len(bundleOut.OwnHash) == 0 {
		return nil, 0, errors.New("stellar account bundle missing own hash")
	}

	return &bundleOut, version, nil
}
909293
func (s *storage) encryptBlob(ciphertext, plaintext []byte) []byte {
	if s.key == [32]byte{} {
		// Safety check, we really don't want this to happen.
		panic("no passphrase set")
	}
	var nonce [24]byte
	s.randNonce(&nonce)
	ciphertext = append(ciphertext, version)
	ciphertext = append(ciphertext, nonce[:]...)
	return secretbox.Seal(ciphertext, plaintext, &nonce, &s.key)
}
967342
func (k *Keyring) LookupBoxSecretKey(kids [][]byte) (int, saltpack.BoxSecretKey) {
	for i, kid := range kids {
		if sk, ok := k.encKeys[kidToPublicKey(kid)]; ok {
			return i, sk
		}
	}
	return -1, nil
}
317462
func (k *Keyring) GenerateBoxKey() (*SecretKey, error) {
	ret, err := generateBoxKey()
	if err != nil {
		return nil, err
	}
	k.encKeys[ret.pub] = *ret
	return ret, nil
}
608161
func (d *msgpackDecDriver) DecodeInt64() (i int64) {
	if !d.bdRead {
		d.readNextBd()
	}
	switch d.bd {
	case mpUint8:
		i = int64(uint64(d.r.readn1()))
	case mpUint16:
		i = int64(uint64(bigen.Uint16(d.r.readx(2))))
	case mpUint32:
		i = int64(uint64(bigen.Uint32(d.r.readx(4))))
	case mpUint64:
		i = int64(bigen.Uint64(d.r.readx(8)))
	case mpInt8:
		i = int64(int8(d.r.readn1()))
	case mpInt16:
		i = int64(int16(bigen.Uint16(d.r.readx(2))))
	case mpInt32:
		i = int64(int32(bigen.Uint32(d.r.readx(4))))
	case mpInt64:
		i = int64(bigen.Uint64(d.r.readx(8)))
	default:
		switch {
		case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax:
			i = int64(int8(d.bd))
		case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax:
			i = int64(int8(d.bd))
		default:
			d.d.errorf("cannot decode signed integer: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd))
			return
		}
	}
	d.bdRead = false
	return
}
249173
func (service *VboxPortType) ISystemPropertiesgetMaxPortCountForStorageBus(request *ISystemPropertiesgetMaxPortCountForStorageBus) (*ISystemPropertiesgetMaxPortCountForStorageBusResponse, error) {
	response := new(ISystemPropertiesgetMaxPortCountForStorageBusResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
919351
func (service *VboxPortType) IUSBDeviceFiltersgetDeviceFilters(request *IUSBDeviceFiltersgetDeviceFilters) (*IUSBDeviceFiltersgetDeviceFiltersResponse, error) {
	response := new(IUSBDeviceFiltersgetDeviceFiltersResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
613513
func geoBoundingBox(hash string) geoBox {
	bits := uint(5 * len(hash))
	inthash := base32encoding.decode(hash)
	return geoBoundingBoxIntWithPrecision(inthash, bits)
}
330396
func (service *VboxPortType) ISystemPropertiesgetMaxInstancesOfStorageBus(request *ISystemPropertiesgetMaxInstancesOfStorageBus) (*ISystemPropertiesgetMaxInstancesOfStorageBusResponse, error) {
	response := new(ISystemPropertiesgetMaxInstancesOfStorageBusResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
551392
func (bc BoxCorners) Box() Box {
	return Box{
		Top:    util.Math.MinInt(bc.TopLeft.Y, bc.TopRight.Y),
		Left:   util.Math.MinInt(bc.TopLeft.X, bc.BottomLeft.X),
		Right:  util.Math.MaxInt(bc.TopRight.X, bc.BottomRight.X),
		Bottom: util.Math.MaxInt(bc.BottomLeft.Y, bc.BottomRight.Y),
	}
}
1285132
func (service *VboxPortType) ISerialPortsetEnabled(request *ISerialPortsetEnabled) (*ISerialPortsetEnabledResponse, error) {
	response := new(ISerialPortsetEnabledResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
245623
func (service *VboxPortType) IMediumsetDescription(request *IMediumsetDescription) (*IMediumsetDescriptionResponse, error) {
	response := new(IMediumsetDescriptionResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
734047
func checkSigncryptReceivers(receiverBoxKeys []BoxPublicKey, receiverSymmetricKeys []ReceiverSymmetricKey) error {
	err := checkSigncryptReceiverCount(len(receiverBoxKeys), len(receiverSymmetricKeys))
	if err != nil {
		return err
	}

	// Make sure that each receiver only shows up in the set once.
	receiverSet := make(map[string]bool)

	// Make sure each key hasn't been used before.

	for _, receiver := range receiverBoxKeys {
		kid := receiver.ToKID()
		kidString := string(kid)
		if receiverSet[kidString] {
			return ErrRepeatedKey(kid)
		}
		receiverSet[kidString] = true
	}

	for _, receiver := range receiverSymmetricKeys {
		kid := receiver.Identifier
		kidString := string(kid)
		if receiverSet[kidString] {
			return ErrRepeatedKey(kid)
		}
		receiverSet[kidString] = true
	}

	return nil
}
500157
func (service *VboxPortType) ISystemPropertiesgetFreeDiskSpacePercentError(request *ISystemPropertiesgetFreeDiskSpacePercentError) (*ISystemPropertiesgetFreeDiskSpacePercentErrorResponse, error) {
	response := new(ISystemPropertiesgetFreeDiskSpacePercentErrorResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
1168985
func (service *VboxPortType) ISystemPropertiessetVRDEAuthLibrary(request *ISystemPropertiessetVRDEAuthLibrary) (*ISystemPropertiessetVRDEAuthLibraryResponse, error) {
	response := new(ISystemPropertiessetVRDEAuthLibraryResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
449700
func (service *VboxPortType) IUSBDeviceFiltersetSerialNumber(request *IUSBDeviceFiltersetSerialNumber) (*IUSBDeviceFiltersetSerialNumberResponse, error) {
	response := new(IUSBDeviceFiltersetSerialNumberResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}