本文整理汇总了Golang中github.com/ipfs/go-ipfs/p2p/crypto.PubKey.Verify方法的典型用法代码示例。如果您正苦于以下问题:Golang PubKey.Verify方法的具体用法?Golang PubKey.Verify怎么用?Golang PubKey.Verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ipfs/go-ipfs/p2p/crypto.PubKey
的用法示例。
在下文中一共展示了PubKey.Verify方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CheckRecordSig
func CheckRecordSig(r *pb.Record, pk ci.PubKey) error {
blob := RecordBlobForSig(r)
good, err := pk.Verify(blob, r.Signature)
if err != nil {
return nil
}
if !good {
return errors.New("invalid record signature")
}
return nil
}
示例2: resolveOnce
// resolveOnce implements resolver. Uses the IPFS routing system to
// resolve SFS-like names.
func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
log.Debugf("RoutingResolve: '%s'", name)
cached, ok := r.cacheGet(name)
if ok {
return cached, nil
}
hash, err := mh.FromB58String(name)
if err != nil {
// name should be a multihash. if it isn't, error out here.
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
return "", err
}
// use the routing system to get the name.
// /ipns/<name>
h := []byte("/ipns/" + string(hash))
var entry *pb.IpnsEntry
var pubkey ci.PubKey
resp := make(chan error, 2)
go func() {
ipnsKey := key.Key(h)
val, err := r.routing.GetValue(ctx, ipnsKey)
if err != nil {
log.Warning("RoutingResolve get failed.")
resp <- err
}
entry = new(pb.IpnsEntry)
err = proto.Unmarshal(val, entry)
if err != nil {
resp <- err
}
resp <- nil
}()
go func() {
// name should be a public key retrievable from ipfs
pubk, err := routing.GetPublicKey(r.routing, ctx, hash)
if err != nil {
resp <- err
}
pubkey = pubk
resp <- nil
}()
for i := 0; i < 2; i++ {
err = <-resp
if err != nil {
return "", err
}
}
hsh, _ := pubkey.Hash()
log.Debugf("pk hash = %s", key.Key(hsh))
// check sig with pk
if ok, err := pubkey.Verify(ipnsEntryDataForSig(entry), entry.GetSignature()); err != nil || !ok {
return "", fmt.Errorf("Invalid value. Not signed by PrivateKey corresponding to %v", pubkey)
}
// ok sig checks out. this is a valid name.
// check for old style record:
valh, err := mh.Cast(entry.GetValue())
if err != nil {
// Not a multihash, probably a new record
p, err := path.ParsePath(string(entry.GetValue()))
if err != nil {
return "", err
}
r.cacheSet(name, p, entry)
return p, nil
} else {
// Its an old style multihash record
log.Warning("Detected old style multihash record")
p := path.FromKey(key.Key(valh))
r.cacheSet(name, p, entry)
return p, nil
}
}