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


Golang KeyStore.Has方法代碼示例

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


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

示例1: removeKey

func removeKey(ks *store.KeyStore, cfg *config) error {
	cfg.Label = cfg.Args[0]

	if cfg.Label == "self" {
		return errors.New("cannot remove own key")
	} else if !ks.Has(cfg.Label) {
		return fmt.Errorf("no key was found under label %s", cfg.Label)
	}

	fmt.Println("Removing key ", cfg.Label)
	delete(ks.Keys, cfg.Label)
	return nil
}
開發者ID:kisom,項目名稱:cryptutils,代碼行數:13,代碼來源:fcrypt.go

示例2: process

func process(ks *store.KeyStore, cmd command) *response {
	var resp response

	switch cmd.op {
	case "public":
		log.Printf("public key lookup")
		if cmd.data["label"] == "" {
			log.Printf("public key request with no label")
			resp.err = errors.New("missing label")
		}
		ok := ks.Has(cmd.data["label"])
		if !ok {
			log.Printf("keystore doesn't have key with label %s", cmd.data["label"])
			resp.err = errors.New("export failed")
		}

		if cmd.data["label"] == "self" {
			resp.out = ks.ExportKey[:]
		} else {
			rec := ks.Keys[cmd.data["label"]]
			if rec == nil {
				log.Printf("keystore lookup failed")
				resp.err = errors.New("export failed")
				break
			}
			vkey := &store.VerifiedKey{
				Public:    rec.Keys,
				Signer:    rec.KeySigner,
				Timestamp: rec.SignatureTime,
				Signature: rec.KeySignature,
			}
			resp.out, resp.err = vkey.Serialise()
		}
	case "fingerprint":
		log.Printf("fingerprint lookup")
		if cmd.data["label"] == "" {
			log.Printf("fingerprint request with no label")
			resp.err = errors.New("missing label")
		}
		ok := ks.Has(cmd.data["label"])
		if !ok {
			log.Printf("keystore doesn't have key with label %s",
				cmd.data["label"])
			resp.err = errors.New("export failed")
		}

		var pub []byte

		if cmd.data["label"] == "self" {
			pub = ks.PublicKey[:]
		} else {
			rec := ks.Keys[cmd.data["label"]]
			if rec == nil {
				log.Printf("keystore lookup failed")
				resp.err = errors.New("fingerprint failed")
				break
			}
			pub = rec.Keys[:]
		}
		h := sha256.New()
		h.Write(pub)
		resp.out = []byte(fmt.Sprintf("%x", h.Sum(nil)))
	case "upload":
		log.Printf("upload request")
		resp = checkUpload(ks, cmd)
	case "audit":
		log.Printf("audit request")
		ok := ks.KeyAudit()
		if !ok {
			resp.err = errors.New("audit failure")
		}
	default:
		resp.err = errors.New("invalid command")
	}
	return &resp
}
開發者ID:kisom,項目名稱:cryptutils,代碼行數:76,代碼來源:keysrv.go


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