DeterministicKeyChain, MarriedKeyChain: Simplify build().

This commit is contained in:
Andreas Schildbach
2019-01-26 19:53:49 +01:00
parent 04433862cd
commit 716cf93716
2 changed files with 20 additions and 20 deletions

View File

@@ -245,25 +245,24 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
} }
public DeterministicKeyChain build() { public DeterministicKeyChain build() {
checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey");
checkState(passphrase == null || seed == null, "Passphrase must not be specified with seed"); checkState(passphrase == null || seed == null, "Passphrase must not be specified with seed");
if (accountPath == null) if (accountPath == null)
accountPath = ACCOUNT_ZERO_PATH; accountPath = ACCOUNT_ZERO_PATH;
DeterministicKeyChain chain; if (random != null)
if (random != null) {
// Default passphrase to "" if not specified // Default passphrase to "" if not specified
chain = new DeterministicKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, accountPath); return new DeterministicKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null,
} else if (entropy != null) { accountPath);
chain = new DeterministicKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null, accountPath); else if (entropy != null)
} else if (seed != null) { return new DeterministicKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs),
chain = new DeterministicKeyChain(seed, null, accountPath); null, accountPath);
} else { else if (seed != null)
chain = new DeterministicKeyChain(watchingKey); return new DeterministicKeyChain(seed, null, accountPath);
} else if (watchingKey != null)
return new DeterministicKeyChain(watchingKey);
return chain; else
throw new IllegalStateException();
} }
protected String getPassphrase() { protected String getPassphrase() {

View File

@@ -94,7 +94,6 @@ public class MarriedKeyChain extends DeterministicKeyChain {
@Override @Override
public MarriedKeyChain build() { public MarriedKeyChain build() {
checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey");
checkNotNull(followingKeys, "followingKeys must be provided"); checkNotNull(followingKeys, "followingKeys must be provided");
if (threshold == 0) if (threshold == 0)
@@ -103,15 +102,17 @@ public class MarriedKeyChain extends DeterministicKeyChain {
accountPath = ACCOUNT_ZERO_PATH; accountPath = ACCOUNT_ZERO_PATH;
MarriedKeyChain chain; MarriedKeyChain chain;
if (random != null) { if (random != null)
chain = new MarriedKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, accountPath); chain = new MarriedKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, accountPath);
} else if (entropy != null) { else if (entropy != null)
chain = new MarriedKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null, accountPath); chain = new MarriedKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null,
} else if (seed != null) { accountPath);
else if (seed != null)
chain = new MarriedKeyChain(seed, null, accountPath); chain = new MarriedKeyChain(seed, null, accountPath);
} else { else if (watchingKey != null)
chain = new MarriedKeyChain(watchingKey); chain = new MarriedKeyChain(watchingKey);
} else
throw new IllegalStateException();
chain.addFollowingAccountKeys(followingKeys, threshold); chain.addFollowingAccountKeys(followingKeys, threshold);
return chain; return chain;
} }