From 8bc6eee32c07567e8e5ff8ff6a5ef0552736edb0 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 6 Aug 2014 08:44:20 -0500 Subject: [PATCH] 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. --- keystore/keystore.go | 1 + 1 file changed, 1 insertion(+) diff --git a/keystore/keystore.go b/keystore/keystore.go index e76136b..c558054 100644 --- a/keystore/keystore.go +++ b/keystore/keystore.go @@ -706,6 +706,7 @@ func (s *Store) ReadFrom(r io.Reader) (n int64, err error) { rootAddr := s.keyGenerator.Address() s.addrMap[getAddressKey(rootAddr)] = &s.keyGenerator s.chainIdxMap[rootKeyChainIdx] = rootAddr + s.lastChainIdx = rootKeyChainIdx // Fill unserializied fields. wts := appendedEntries.entries