本文整理汇总了Golang中github.com/docker/notary/tuf/keys.KeyDB.AddKey方法的典型用法代码示例。如果您正苦于以下问题:Golang KeyDB.AddKey方法的具体用法?Golang KeyDB.AddKey怎么用?Golang KeyDB.AddKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/notary/tuf/keys.KeyDB
的用法示例。
在下文中一共展示了KeyDB.AddKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addKeyForRole
// add a key to a KeyDB, and create a role for the key and add it.
func addKeyForRole(kdb *keys.KeyDB, role string, key data.PublicKey) error {
theRole, err := data.NewRole(role, 1, []string{key.ID()}, nil, nil)
if err != nil {
return err
}
kdb.AddKey(key)
if err := kdb.AddRole(theRole); err != nil {
return err
}
return nil
}
示例2: initRepo
func initRepo(t *testing.T, cryptoService signed.CryptoService, keyDB *keys.KeyDB) *Repo {
rootKey, err := cryptoService.Create("root", data.ED25519Key)
assert.NoError(t, err)
targetsKey, err := cryptoService.Create("targets", data.ED25519Key)
assert.NoError(t, err)
snapshotKey, err := cryptoService.Create("snapshot", data.ED25519Key)
assert.NoError(t, err)
timestampKey, err := cryptoService.Create("timestamp", data.ED25519Key)
assert.NoError(t, err)
keyDB.AddKey(rootKey)
keyDB.AddKey(targetsKey)
keyDB.AddKey(snapshotKey)
keyDB.AddKey(timestampKey)
rootRole := &data.Role{
Name: "root",
RootRole: data.RootRole{
KeyIDs: []string{rootKey.ID()},
Threshold: 1,
},
}
targetsRole := &data.Role{
Name: "targets",
RootRole: data.RootRole{
KeyIDs: []string{targetsKey.ID()},
Threshold: 1,
},
}
snapshotRole := &data.Role{
Name: "snapshot",
RootRole: data.RootRole{
KeyIDs: []string{snapshotKey.ID()},
Threshold: 1,
},
}
timestampRole := &data.Role{
Name: "timestamp",
RootRole: data.RootRole{
KeyIDs: []string{timestampKey.ID()},
Threshold: 1,
},
}
keyDB.AddRole(rootRole)
keyDB.AddRole(targetsRole)
keyDB.AddRole(snapshotRole)
keyDB.AddRole(timestampRole)
repo := NewRepo(keyDB, cryptoService)
err = repo.InitRepo(false)
assert.NoError(t, err)
return repo
}