1 Star 0 Fork 0

mysnapcore/mygo-tpm2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
qn.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2021 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
package util
import (
"errors"
"gitee.com/mysnapcore/mygo-tpm2"
"gitee.com/mysnapcore/mygo-tpm2/mu"
)
// ComputeQualifiedName can compute the qualified name of an object with
// the specified name that is protected by a parent with the specified
// qualified name.
func ComputeQualifiedName(name, parentQn tpm2.Name) (tpm2.Name, error) {
if name.Algorithm() == tpm2.HashAlgorithmNull {
return nil, errors.New("invalid name")
}
if !name.Algorithm().Available() {
return nil, errors.New("name algorithm is not available")
}
h := name.Algorithm().NewHash()
h.Write(parentQn)
h.Write(name)
return mu.MarshalToBytes(name.Algorithm(), mu.RawBytes(h.Sum(nil)))
}
// ComputeQualifiedNameFull can compute the qualified name of an object with
// the specified name that is protected in the specified hierarchy by the chain
// of parent objects with the specified names. The ancestor names are ordered
// from the primary key towards the immediate parent.
func ComputeQualifiedNameFull(name tpm2.Name, hierarchy tpm2.Handle, ancestors ...tpm2.Name) (tpm2.Name, error) {
lastQn := tpm2.Name(mu.MustMarshalToBytes(hierarchy))
for len(ancestors) > 0 {
current := ancestors[0]
ancestors = ancestors[1:]
var err error
lastQn, err = ComputeQualifiedName(current, lastQn)
if err != nil {
return nil, err
}
}
return ComputeQualifiedName(name, lastQn)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mysnapcore/mygo-tpm2.git
git@gitee.com:mysnapcore/mygo-tpm2.git
mysnapcore
mygo-tpm2
mygo-tpm2
v0.0.6

搜索帮助