// ExportKeysToFile will create the named file (or truncate it) and write all the accounts to that file in libotr format.
194377
func ExportKeysToFile(acs []*Account, fname string) error {
	f, err := os.Create(fname)
	if err != nil {
		return err
	}
	defer f.Close()
	exportAccounts(acs, f)
	return nil
}
354728
func (ckf ComputedKeyFamily) ExportDeviceKeys() (exportedKeys []keybase1.PublicKey, pgpKeyCount int) {
	for _, key := range ckf.GetAllActiveSibkeys() {
		if _, isPGP := key.(*PGPKeyBundle); isPGP {
			pgpKeyCount++
			continue
		}
		exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
	}
	for _, key := range ckf.GetAllActiveSubkeys() {
		if _, isPGP := key.(*PGPKeyBundle); isPGP {
			pgpKeyCount++
			continue
		}
		exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
	}
	sort.Sort(PublicKeyList(exportedKeys))
	return exportedKeys, pgpKeyCount
}
582767
func (ckf ComputedKeyFamily) Export() []keybase1.PublicKey {
	var exportedKeys []keybase1.PublicKey
	for _, key := range ckf.GetAllActiveSibkeys() {
		exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
	}
	for _, key := range ckf.GetAllActiveSubkeys() {
		exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
	}
	sort.Sort(PublicKeyList(exportedKeys))
	return exportedKeys
}
1234537
func keyFileExists(filename string) bool {
	_, err := os.Stat(fmt.Sprintf(keysFolderPrefixFormat, filename))
	return err == nil
}
329885
func (d *Datastore) KeyFilename(key ds.Key) string {
	return filepath.Join(d.path, key.String(), ObjectKeySuffix)
}
1336603
func (b *BadgeState) Export() (keybase1.BadgeState, error) {
	b.Lock()
	defer b.Unlock()

	b.state.Conversations = []keybase1.BadgeConversationInfo{}
	for _, info := range b.chatUnreadMap {
		b.state.Conversations = append(b.state.Conversations, info)
	}
	b.state.InboxVers = int(b.inboxVers)

	b.state.UnreadWalletAccounts = []keybase1.WalletAccountInfo{}
	for accountID, count := range b.walletUnreadMap {
		info := keybase1.WalletAccountInfo{AccountID: string(accountID), NumUnread: count}
		b.state.UnreadWalletAccounts = append(b.state.UnreadWalletAccounts, info)
	}

	return b.state, nil
}
435323
func (v *DeviceMapperVolume) Export(label, parent string, writer io.Writer, excludes []string) error {
	glog.V(2).Infof("Export() (%s) START", v.name)
	defer glog.V(2).Infof("Export() (%s) END", v.name)
	if !v.snapshotExists(label) {
		return volume.ErrSnapshotDoesNotExist
	}
	label = v.rawSnapshotLabel(label)
	mountpoint, err := ioutil.TempDir("", "serviced-export-volume-")
	if err != nil {
		return err
	}
	defer os.RemoveAll(mountpoint)
	deviceHash, err := v.Metadata.LookupSnapshotDevice(label)
	if err != nil {
		return err
	}
	glog.V(2).Infof("Mounting temporary export device %s", deviceHash)
	if err := v.driver.DeviceSet.MountDevice(deviceHash, mountpoint, label); err != nil {
		return err
	}
	defer func(d *DeviceMapperDriver, deviceHash, mountpoint string) {
		// We use the provided UnmountDevice func here, rather than our own
		// unmount(), because we DO care about Docker's internal bookkeeping
		// here. Without this, DeviceSet.DeleteDevice will fail.
		if err := d.DeviceSet.UnmountDevice(deviceHash, mountpoint); err != nil {
			glog.V(2).Infof("Error unmounting %s (device: %s): %s", mountpoint, deviceHash, err)
		}
		d.DeviceSet.Lock()
		if err := d.DeactivateDevice(deviceHash); err != nil {
			glog.V(2).Infof("Error deactivating device %s: %s", deviceHash, err)
		}
		d.DeviceSet.Unlock()
	}(v.driver, deviceHash, mountpoint)

	tarOut := tar.NewWriter(writer)

	// Set the driver type
	drivertype := []byte(v.Driver().DriverType())
	header := &tar.Header{Name: fmt.Sprintf("%s-driver", label), Size: int64(len(drivertype))}
	if err := tarOut.WriteHeader(header); err != nil {
		glog.Errorf("Could not export driver type header for snapshot %s: %s", label, err)
		return err
	}
	if _, err := tarOut.Write(drivertype); err != nil {
		glog.Errorf("Could not export driver type for snapshot %s: %s", label, err)
		return err
	}

	// Set the device metadata
	size, err := v.SizeOf()
	if err != nil {
		glog.Errorf("Could not get the size of the device for snapshot %s: %s", label, err)
		return err
	}
	volInfo, err := json.Marshal(volumeInfo{Size: size})
	if err != nil {
		glog.Errorf("Could not marshal device info for snapshot %s: %s", label, err)
		return err
	}
	header = &tar.Header{Name: fmt.Sprintf("%s-device", label), Size: int64(len(volInfo))}
	if err := tarOut.WriteHeader(header); err != nil {
		glog.Errorf("Could not export device info header for snapshot %s: %s", label, err)
		return err
	}
	if _, err := tarOut.Write(volInfo); err != nil {
		glog.Errorf("Could not export device info for snapshot %s: %s", label, err)
		return err
	}

	// Write metadata
	mdpath := filepath.Join(v.driver.MetadataDir(), label)

	if err := exportDirectoryAsTar(mdpath, fmt.Sprintf("%s-metadata", label), tarOut, []string{}); err != nil {
		return err
	}
	if err := exportDirectoryAsTar(mountpoint, fmt.Sprintf("%s-volume", label), tarOut, excludes); err != nil {
		return err
	}

	return tarOut.Close()
}
18296
func (p *iscsiProvisioner) exportCreate(vol string, lun int32, pool string, initiator string) error {
	client, err := p.getConnection()
	defer client.Close()
	if err != nil {
		log.Warnln(err)
		return err
	}
	args := exportCreateArgs{
		Pool:         pool,
		Vol:          vol,
		InitiatorWwn: initiator,
		Lun:          lun,
	}
	err = client.Call("export_create", args, nil)
	return err
}
57500
func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.RawMessage, error) {
	// Look up the wallet containing the requested signer
	wallet, err := s.am.Find(accounts.Account{Address: addr})
	if err != nil {
		return nil, err
	}
	if wallet.URL().Scheme != keystore.KeyStoreScheme {
		return nil, fmt.Errorf("Account is not a keystore-account")
	}
	return ioutil.ReadFile(wallet.URL().Path)
}
976886
func (k *SKBKeyringFile) WriteTo(w io.Writer) (n int64, err error) {
	k.G().Log.Debug("+ SKBKeyringFile WriteTo")
	defer k.G().Log.Debug("- SKBKeyringFile WriteTo")
	b64 := base64.NewEncoder(base64.StdEncoding, w)
	defer func() {
		// explicitly check for error on Close:
		if closeErr := b64.Close(); closeErr != nil {
			k.G().Log.Warning("SKBKeyringFile: WriteTo b64.Close() error: %s", closeErr)
			if err == nil {
				n = 0
				err = closeErr
				return
			}
		}
		k.G().Log.Debug("SKBKeyringFile: b64 stream closed successfully")
	}()

	if err := encodeSKBPacketList(k.Blocks, b64); err != nil {
		k.G().Log.Warning("Encoding problem: %s", err)
		return 0, err
	}

	return 0, nil
}
986831
func LoadMasterKeyFile(filename string) error {
	publicKey, privateKey, err := LoadKeyPairFromFile(filename)
	if err != nil {
		return err
	}

	LoadMasterKeys(publicKey, privateKey)

	return nil
}
1231146
func ExportCreate(
	ctx context.Context,
	client api.Client,
	export *Export) (int, error) {

	if export.Paths != nil && len(*export.Paths) == 0 {
		return 0, errors.New("no path set")
	}

	var resp Export

	if err := client.Post(
		ctx,
		exportsPath,
		"",
		nil,
		nil,
		export,
		&resp); err != nil {

		return 0, err
	}

	return resp.ID, nil
}
1124280
func (d *driver) getKeyFileJSON() ([]byte, error) {
	serviceAccountJSON, err := ioutil.ReadFile(d.keyFile)
	if err != nil {
		log.Errorf(
			"Could not read credentials file: %s, %s",
			d.keyFile, err)
		return nil, err
	}
	return serviceAccountJSON, nil
}
874385
func (e *Identify2WithUID) exportToResult(m libkb.MetaContext) (*keybase1.Identify2ResUPK2, error) {
	if e.them == nil {
		// this should never happen
		return nil, libkb.UserNotFoundError{Msg: "failed to get a them user in Identify2WithUID#exportToResult"}
	}
	upk, err := e.toUserPlusKeysv2AllIncarnations()
	if err != nil {
		return nil, err
	}
	if upk == nil {
		// this should never happen
		return nil, libkb.UserNotFoundError{Msg: "failed export a them user in Identify2WithUID#exportToResult"}
	}
	return &keybase1.Identify2ResUPK2{
		Upk:          *upk,
		TrackBreaks:  e.trackBreaks,
		IdentifiedAt: keybase1.ToTime(e.getNow(m)),
	}, nil
}
383256
func (key *PrivateKey) WriteToFile(filename string) (err error) {
	keyOut, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return fmt.Errorf("Failed to open %s for writing: %s", filename, err)
	}
	if err := pem.Encode(keyOut, key.pemBlock()); err != nil {
		return fmt.Errorf("Unable to PEM encode private key: %s", err)
	}
	if err := keyOut.Close(); err != nil {
		log.Debugf("Unable to close file: %v", err)
	}
	return
}
292266
func (c *Cert) writeKeyToFile(path string) error {
	pemfile, err := os.Create(path)
	if err != nil {
		return fmt.Errorf("failed to create pem key file for writting: %v", err)
	}

	if err := pem.Encode(pemfile, c.Data()); err != nil {
		return fmt.Errorf("failed to encode key to pem file at'%s': %v", path, err)
	}

	if err := pemfile.Close(); err != nil {
		return fmt.Errorf("error closing pem file at '%s': %v", path, err)
	}

	return nil
}
996979
func IsValidServiceAccountKeyFile(file string) bool {
	_, err := keyutil.PublicKeysFromFile(file)
	return err == nil
}