本文整理汇总了Golang中github.com/docker/notary/tuf/data.NewTargets函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTargets函数的具体用法?Golang NewTargets怎么用?Golang NewTargets使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTargets函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: InitTargets
// InitTargets initializes an empty targets, and returns the new empty target
func (tr *Repo) InitTargets(role string) (*data.SignedTargets, error) {
if !data.IsDelegation(role) && role != data.CanonicalTargetsRole {
return nil, data.ErrInvalidRole{
Role: role,
Reason: fmt.Sprintf("role is not a valid targets role name: %s", role),
}
}
targets := data.NewTargets()
tr.Targets[role] = targets
return targets, nil
}
开发者ID:beerbubble,项目名称:docker,代码行数:12,代码来源:tuf.go
示例2: TestChecksumMatch
func TestChecksumMatch(t *testing.T) {
repo := tuf.NewRepo(nil, nil)
localStorage := store.NewMemoryStore(nil, nil)
remoteStorage := store.NewMemoryStore(nil, nil)
client := NewClient(repo, remoteStorage, nil, localStorage)
sampleTargets := data.NewTargets()
orig, err := json.Marshal(sampleTargets)
origSha256 := sha256.Sum256(orig)
assert.NoError(t, err)
remoteStorage.SetMeta("targets", orig)
_, _, err = client.downloadSigned("targets", int64(len(orig)), origSha256[:])
assert.NoError(t, err)
}
开发者ID:rogaha,项目名称:notary,代码行数:16,代码来源:client_test.go
示例3: TestRemoveUnusedKeys
func TestRemoveUnusedKeys(t *testing.T) {
targets := data.NewTargets()
role, err := data.NewRole("targets/test", 1, []string{"123"}, []string{""})
require.NoError(t, err)
targets.Signed.Delegations.Keys["123"] = nil
RemoveUnusedKeys(targets)
require.Len(t, targets.Signed.Delegations.Keys, 0)
// when role is present that uses key, it shouldn't get removed
targets.Signed.Delegations.Roles = []*data.Role{role}
targets.Signed.Delegations.Keys["123"] = nil
RemoveUnusedKeys(targets)
require.Len(t, targets.Signed.Delegations.Keys, 1)
}
开发者ID:jfrazelle,项目名称:notary,代码行数:18,代码来源:utils_test.go
示例4: TestSizeMismatchShort
func TestSizeMismatchShort(t *testing.T) {
repo := tuf.NewRepo(nil)
localStorage := store.NewMemoryStore(nil)
remoteStorage := testutils.NewShortMemoryStore(nil)
client := NewClient(repo, remoteStorage, localStorage)
sampleTargets := data.NewTargets()
orig, err := json.Marshal(sampleTargets)
origSha256 := sha256.Sum256(orig)
assert.NoError(t, err)
l := int64(len(orig))
remoteStorage.SetMeta("targets", orig)
_, _, err = client.downloadSigned("targets", l, origSha256[:])
// size just limits the data received, the error is caught
// either during checksum verification or during json deserialization
assert.IsType(t, ErrChecksumMismatch{}, err)
}
开发者ID:moxiegirl,项目名称:notary,代码行数:19,代码来源:client_test.go
示例5: TestUnusedDelegationKeys
func TestUnusedDelegationKeys(t *testing.T) {
targets := data.NewTargets()
role, err := data.NewRole("targets/test", 1, []string{}, []string{""})
require.NoError(t, err)
discard := UnusedDelegationKeys(*targets)
require.Len(t, discard, 0)
targets.Signed.Delegations.Roles = []*data.Role{role}
targets.Signed.Delegations.Keys["123"] = nil
discard = UnusedDelegationKeys(*targets)
require.Len(t, discard, 1)
role.KeyIDs = []string{"123"}
discard = UnusedDelegationKeys(*targets)
require.Len(t, discard, 0)
}
开发者ID:jfrazelle,项目名称:notary,代码行数:20,代码来源:utils_test.go
示例6: UpdateDelegations
// UpdateDelegations updates the appropriate delegations, either adding
// a new delegation or updating an existing one. If keys are
// provided, the IDs will be added to the role (if they do not exist
// there already), and the keys will be added to the targets file.
// The "before" argument specifies another role which this new role
// will be added in front of (i.e. higher priority) in the delegation list.
// An empty before string indicates to add the role to the end of the
// delegation list.
// A new, empty, targets file will be created for the new role.
func (tr *Repo) UpdateDelegations(role *data.Role, keys []data.PublicKey, before string) error {
if !role.IsDelegation() || !role.IsValid() {
return data.ErrInvalidRole{Role: role.Name}
}
parent := filepath.Dir(role.Name)
p, ok := tr.Targets[parent]
if !ok {
return data.ErrInvalidRole{Role: role.Name}
}
for _, k := range keys {
if !utils.StrSliceContains(role.KeyIDs, k.ID()) {
role.KeyIDs = append(role.KeyIDs, k.ID())
}
p.Signed.Delegations.Keys[k.ID()] = k
tr.keysDB.AddKey(k)
}
i := -1
var r *data.Role
for i, r = range p.Signed.Delegations.Roles {
if r.Name == role.Name {
break
}
}
if i >= 0 {
p.Signed.Delegations.Roles[i] = role
} else {
p.Signed.Delegations.Roles = append(p.Signed.Delegations.Roles, role)
}
p.Dirty = true
roleTargets := data.NewTargets() // NewTargets always marked Dirty
tr.Targets[role.Name] = roleTargets
tr.keysDB.AddRole(role)
return nil
}
开发者ID:DaveDaCoda,项目名称:docker,代码行数:47,代码来源:tuf.go
示例7: InitTargets
// InitTargets initializes an empty targets
func (tr *Repo) InitTargets() error {
targets := data.NewTargets()
tr.Targets[data.ValidRoles["targets"]] = targets
return nil
}
开发者ID:DaveDaCoda,项目名称:docker,代码行数:6,代码来源:tuf.go
注:本文中的github.com/docker/notary/tuf/data.NewTargets函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论