當前位置: 首頁>>代碼示例>>Golang>>正文


Golang PGPKeyBundle.VerboseDescription方法代碼示例

本文整理匯總了Golang中github.com/keybase/client/go/libkb.PGPKeyBundle.VerboseDescription方法的典型用法代碼示例。如果您正苦於以下問題:Golang PGPKeyBundle.VerboseDescription方法的具體用法?Golang PGPKeyBundle.VerboseDescription怎麽用?Golang PGPKeyBundle.VerboseDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/keybase/client/go/libkb.PGPKeyBundle的用法示例。


在下文中一共展示了PGPKeyBundle.VerboseDescription方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: deviceSignPGP

func (d *Locksmith) deviceSignPGP(ctx *Context) (err error) {
	d.G().Log.Debug("+ deviceSignPGP")
	defer func() {
		d.G().Log.Debug("- deviceSignPGP -> %s", libkb.ErrToOk(err))
	}()
	pgpKeys := d.arg.User.GetActivePGPKeys(false)
	if len(pgpKeys) == 0 {
		err = errors.New("no active PGP keys unexpectedly")
		return err
	}
	var selected *libkb.PGPKeyBundle
	if len(pgpKeys) > 1 {
		// show a list of pgp keys and let them select which one to use
		selected, err = d.selectPGPKey(ctx, pgpKeys)
		if err != nil {
			return err
		}
		if selected == nil {
			err = fmt.Errorf("no key selected")
			return err
		}
	} else {
		selected = pgpKeys[0]
	}

	ctx.LogUI.Debug("selected pgp key: %s", selected.VerboseDescription())
	ctx.LogUI.Debug("selected pgp key kid: %s", selected.GetKID())

	var pk libkb.ServerPrivateKey
	var ok bool
	if ctx.LoginContext != nil {
		pk, ok = ctx.LoginContext.SecretSyncer().FindPrivateKey(selected.GetKID().String())
	} else {
		err = d.G().LoginState().SecretSyncer(func(ss *libkb.SecretSyncer) {
			pk, ok = ss.FindPrivateKey(selected.GetKID().String())
		}, "Locksmith - deviceSignPGP - FindPrivateKey")
		if err != nil {
			return err
		}
	}
	if ok {
		d.G().Log.Debug("| found synced secret key, unlocking it")
		skb, serr := pk.ToSKB(d.G())
		if serr != nil {
			err = serr
			return err
		}

		pgpk, perr := skb.PromptAndUnlock(ctx.LoginContext, "sign new device", "keybase", nil, ctx.SecretUI, nil, d.arg.User)
		if perr != nil {
			err = perr
			return err
		}
		return d.deviceSignPGPNext(ctx, pgpk)
	}

	// use gpg to unlock it
	gpg := d.G().GetGpgClient()
	if err = gpg.Configure(); err != nil {
		return err
	}

	bundle, ierr := gpg.ImportKey(true, selected.GetFingerprint())
	if ierr != nil {
		err = ierr
		return err
	}

	if err = bundle.Unlock("adding this device to your account", ctx.SecretUI); err != nil {
		err = fmt.Errorf("bundle Unlock error: %s", err)
		return err
	}

	return d.deviceSignPGPNext(ctx, bundle)
}
開發者ID:paul-pearce,項目名稱:client-beta,代碼行數:75,代碼來源:locksmith.go


注:本文中的github.com/keybase/client/go/libkb.PGPKeyBundle.VerboseDescription方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。