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


Golang data.NewFileMeta函數代碼示例

本文整理匯總了Golang中github.com/endophage/gotuf/data.NewFileMeta函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFileMeta函數的具體用法?Golang NewFileMeta怎麽用?Golang NewFileMeta使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: WalkStagedTargets

func (m *memoryStore) WalkStagedTargets(paths []string, targetsFn targetsWalkFunc) error {
	if len(paths) == 0 {
		for path, dat := range m.files {
			meta, err := data.NewFileMeta(bytes.NewReader(dat), "sha256")
			if err != nil {
				return err
			}
			if err = targetsFn(path, meta); err != nil {
				return err
			}
		}
		return nil
	}

	for _, path := range paths {
		dat, ok := m.files[path]
		if !ok {
			return errors.ErrFileNotFound{Path: path}
		}
		meta, err := data.NewFileMeta(bytes.NewReader(dat), "sha256")
		if err != nil {
			return err
		}
		if err = targetsFn(path, meta); err != nil {
			return err
		}
	}
	return nil
}
開發者ID:diogomonica,項目名稱:gotuf,代碼行數:29,代碼來源:memorystore.go

示例2: tufAdd

func tufAdd(cmd *cobra.Command, args []string) {
	if len(args) < 3 {
		cmd.Usage()
		fatalf("must specify a GUN, target, and path to target data")
	}

	gun := args[0]
	targetName := args[1]
	targetPath := args[2]
	kdb := keys.NewDB()
	signer := signed.NewSigner(NewCryptoService(gun))
	repo := tuf.NewTufRepo(kdb, signer)

	b, err := ioutil.ReadFile(targetPath)
	if err != nil {
		fatalf(err.Error())
	}

	filestore := bootstrapRepo(gun, repo)

	fmt.Println("Generating metadata for target")
	meta, err := data.NewFileMeta(bytes.NewBuffer(b))
	if err != nil {
		fatalf(err.Error())
	}

	fmt.Printf("Adding target \"%s\" with sha256 \"%s\" and size %d bytes.\n", targetName, meta.Hashes["sha256"], meta.Length)
	_, err = repo.AddTargets("targets", data.Files{targetName: meta})
	if err != nil {
		fatalf(err.Error())
	}

	saveRepo(repo, filestore)
}
開發者ID:progrium,項目名稱:notary,代碼行數:34,代碼來源:tuf.go

示例3: snapshotExpired

func snapshotExpired(ts *data.SignedTimestamp, snapshot []byte) bool {
	meta, err := data.NewFileMeta(bytes.NewReader(snapshot), "sha256")
	if err != nil {
		// if we can't generate FileMeta from the current snapshot, we should
		// continue to serve the old timestamp if it isn't time expired
		// because we won't be able to generate a new one.
		return false
	}
	hash := meta.Hashes["sha256"]
	return !bytes.Equal(hash, ts.Signed.Meta["snapshot"].Hashes["sha256"])
}
開發者ID:hellonicky,項目名稱:notary,代碼行數:11,代碼來源:timestamp.go

示例4: UpdateTimestamp

func (tr *TufRepo) UpdateTimestamp(s *data.Signed) error {
	jsonData, err := json.Marshal(s)
	if err != nil {
		return err
	}
	meta, err := data.NewFileMeta(bytes.NewReader(jsonData), "sha256")
	if err != nil {
		return err
	}
	tr.Timestamp.Signed.Meta["snapshot"] = meta
	tr.Timestamp.Dirty = true
	return nil
}
開發者ID:souravbh,項目名稱:lattice-release,代碼行數:13,代碼來源:tuf.go

示例5: UpdateSnapshot

func (tr *TufRepo) UpdateSnapshot(role string, s *data.Signed) error {
	jsonData, err := json.Marshal(s)
	if err != nil {
		return err
	}
	meta, err := data.NewFileMeta(bytes.NewReader(jsonData), "sha256")
	if err != nil {
		return err
	}
	tr.Snapshot.Signed.Meta[role] = meta
	tr.Snapshot.Dirty = true
	return nil
}
開發者ID:souravbh,項目名稱:lattice-release,代碼行數:13,代碼來源:tuf.go

示例6: NewTarget

// NewTarget is a helper method that returns a Target
func NewTarget(targetName string, targetPath string) (*Target, error) {
	b, err := ioutil.ReadFile(targetPath)
	if err != nil {
		return nil, err
	}

	meta, err := data.NewFileMeta(bytes.NewBuffer(b))
	if err != nil {
		return nil, err
	}

	return &Target{Name: targetName, Hashes: meta.Hashes, Length: meta.Length}, nil
}
開發者ID:ChanderG,項目名稱:docker,代碼行數:14,代碼來源:client.go

示例7: cmdMeta

func cmdMeta(args *docopt.Args, repo *tuf.Repo) error {
	paths := args.All["<path>"].([]string)
	for _, file := range paths {
		reader, _ := os.Open(file)
		meta, _ := data.NewFileMeta(reader, "sha256")
		jsonBytes, err := json.Marshal(meta)
		if err != nil {
			return err
		}
		filename := fmt.Sprintf("%s.meta.json", file)
		err = ioutil.WriteFile(filename, jsonBytes, 0644)
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:progrium,項目名稱:notary,代碼行數:17,代碼來源:meta.go


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