Begin with root key index when reading keystores.

Instead of using the zero value, explicitly set the last chain index
to -1, which represents the root key.  If no additional keys are read
from the io.Reader, this could result in panics when looking up keys
at index 0, when no additional keys have been created yet.

Fixes #119.
This commit is contained in:
Josh Rickmar 2014-08-06 08:44:20 -05:00
parent 9b14cd99f1
commit 8bc6eee32c

View file

@ -706,6 +706,7 @@ func (s *Store) ReadFrom(r io.Reader) (n int64, err error) {
rootAddr := s.keyGenerator.Address() rootAddr := s.keyGenerator.Address()
s.addrMap[getAddressKey(rootAddr)] = &s.keyGenerator s.addrMap[getAddressKey(rootAddr)] = &s.keyGenerator
s.chainIdxMap[rootKeyChainIdx] = rootAddr s.chainIdxMap[rootKeyChainIdx] = rootAddr
s.lastChainIdx = rootKeyChainIdx
// Fill unserializied fields. // Fill unserializied fields.
wts := appendedEntries.entries wts := appendedEntries.entries