This commit is contained in:
mossid 2018-07-16 19:25:04 -07:00
parent b16ce7e0c2
commit f31a6f043f
2 changed files with 18 additions and 9 deletions

View File

@ -46,6 +46,9 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er
if !bytes.Equal(root, args[0]) {
return cmn.NewError("Calculated root hash is invalid: expected %+v but %+v", root, args[0])
}
if len(keys) != 0 {
return cmn.NewError("Keypath not consumed all")
}
return nil
}
@ -92,22 +95,16 @@ func (prt *ProofRuntime) DecodeProof(proof *Proof) (poz ProofOperators, err erro
return
}
// XXX Reorder value/keys.
// XXX Replace keys with keyString (the result of KeyPath.String()).
func (prt *ProofRuntime) VerifyValue(proof *Proof, root []byte, keypath string, value []byte) (err error) {
return prt.Verify(proof, root, keypath, [][]byte{value})
}
// XXX Reorder value/keys.
// XXX Replace keys with keyString (the result of KeyPath.String()).
// TODO In the long run we'll need a method of classifcation of ops,
// whether existence or absence or perhaps a third?
func (prt *ProofRuntime) VerifyAbsence(proof *Proof, keypath string, root []byte) (err error) {
return prt.Verify(proof, root, keypath, nil)
}
// XXX Reorder value/keys.
// XXX Replace keys with keyString (the result of KeyPath.String()).
func (prt *ProofRuntime) Verify(proof *Proof, root []byte, keypath string, args [][]byte) (err error) {
poz, err := prt.DecodeProof(proof)
if err != nil {

View File

@ -10,12 +10,24 @@ import (
func TestKeyPath(t *testing.T) {
var path KeyPath
keys := make([][]byte, 10)
alphanum := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for d := 0; d < 1e4; d++ {
path = nil
for d := 0; d < 20; d++ {
for i := range keys {
keys[i] = make([]byte, rand.Uint32()%20)
rand.Read(keys[i])
enc := keyEncoding(rand.Intn(int(KeyEncodingMax)))
keys[i] = make([]byte, rand.Uint32()%20)
switch enc {
case KeyEncodingURL:
for j := range keys[i] {
keys[i][j] = alphanum[rand.Intn(len(alphanum))]
}
case KeyEncodingHex:
rand.Read(keys[i])
default:
panic("Unexpected encoding")
}
path = path.AppendKey(keys[i], enc)
}