remove node serdes, pretty sure it's redundant

This commit is contained in:
Tadge Dryja 2016-01-18 20:17:15 -08:00
parent a3f65bb4ad
commit 6f8cf3d75a

@ -14,68 +14,6 @@ with 41 bytes for each stored hash, up to a maximum of 64. Receivers are
prepended with the total number of hashes, so the total max size is 2625 bytes. prepended with the total number of hashes, so the total max size is 2625 bytes.
*/ */
// ToBytes turns an ElkremNode into a 41 byte long byte slice.
// 1 byte height, 8 byte index, 32 byte hash
func (e *ElkremNode) ToBytes() ([]byte, error) {
var buf bytes.Buffer
// write 1 byte height
err := binary.Write(&buf, binary.BigEndian, e.h)
if err != nil {
return nil, err
}
// write 8 byte index
err = binary.Write(&buf, binary.BigEndian, e.i)
if err != nil {
return nil, err
}
// write 32 byte sha hash
n, err := buf.Write(e.sha.Bytes())
if err != nil {
return nil, err
}
if n != 32 {
return nil, fmt.Errorf("%d byte hash, expect 32", n)
}
return buf.Bytes(), nil
}
// ElkremNodeFromBytes turns a 41 byte long byte slice into an ElkremNode.
// 1 byte height, 8 byte index, 32 byte hash.
func ElkremNodeFromBytes(b []byte) (ElkremNode, error) {
var e ElkremNode
buf := bytes.NewBuffer(b)
// read 1 byte height
err := binary.Read(buf, binary.BigEndian, &e.h)
if err != nil {
return e, err
}
// read 8 byte index
err = binary.Read(buf, binary.BigEndian, &e.i)
if err != nil {
return e, err
}
// read 32 byte sha hash
err = e.sha.SetBytes(buf.Next(32))
if err != nil {
return e, err
}
// sanity check. Node that this doesn't check that index and height
// match. Could add that but it's slow.
if e.h > 63 { // check for super high nodes
return e, fmt.Errorf("Read invalid node height %d", e.h)
}
var max uint64 // maximum possible given height
for j := uint8(0); j <= e.h; j++ {
max = max<<1 | 1
}
if e.i > max-1 { // check for index higher than height allows
return e, fmt.Errorf("Node claims index %d; %d max at height %d",
e.i, max-1, e.h)
}
return e, nil
}
// ToBytes turns the Elkrem Sender into a 41 byte slice: // ToBytes turns the Elkrem Sender into a 41 byte slice:
// first the tree height (1 byte), then 8 byte index of last sent, // first the tree height (1 byte), then 8 byte index of last sent,
// then the 32 byte root sha hash. // then the 32 byte root sha hash.