revocation: fix nil pointer panic in shachain constructor

This commit is contained in:
Olaoluwa Osuntokun
2015-12-21 15:41:23 -06:00
parent b9a6155021
commit d7fba0e89d

View File

@@ -44,7 +44,7 @@ func NewHyperShaChain() *HyperShaChain {
// NewHyperShaChainFromSeed... // NewHyperShaChainFromSeed...
// * used to derive your own pre-images // * used to derive your own pre-images
func NewHyperShaChainFromSeed(seed *[32]byte, deriveTo uint64) (*HyperShaChain, error) { func NewHyperShaChainFromSeed(seed *[32]byte, deriveTo uint64) (*HyperShaChain, error) {
var shaSeed *[32]byte var shaSeed [32]byte
// If no seed is specified, generate a new one. // If no seed is specified, generate a new one.
if seed == nil { if seed == nil {
@@ -52,13 +52,15 @@ func NewHyperShaChainFromSeed(seed *[32]byte, deriveTo uint64) (*HyperShaChain,
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else {
shaSeed = *seed
} }
// The last possible value in the chain is our starting index. // The last possible value in the chain is our starting index.
start := uint64(maxIndex) start := uint64(maxIndex)
stop := deriveTo stop := deriveTo
curHash := derive(start, stop, *shaSeed) curHash := derive(start, stop, shaSeed)
// TODO(roasbeef): from/to or static size? // TODO(roasbeef): from/to or static size?
return &HyperShaChain{lastChainIndex: deriveTo, lastHash: curHash}, nil return &HyperShaChain{lastChainIndex: deriveTo, lastHash: curHash}, nil