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() {
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");
if (accountPath == null)
accountPath = ACCOUNT_ZERO_PATH;
DeterministicKeyChain chain;
if (random != null) {
if (random != null)
// Default passphrase to "" if not specified
chain = new DeterministicKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, accountPath);
} else if (entropy != null) {
chain = new DeterministicKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null, accountPath);
} else if (seed != null) {
chain = new DeterministicKeyChain(seed, null, accountPath);
} else {
chain = new DeterministicKeyChain(watchingKey);
}
return chain;
return new DeterministicKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null,
accountPath);
else if (entropy != null)
return new DeterministicKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs),
null, accountPath);
else if (seed != null)
return new DeterministicKeyChain(seed, null, accountPath);
else if (watchingKey != null)
return new DeterministicKeyChain(watchingKey);
else
throw new IllegalStateException();
}
protected String getPassphrase() {

View File

@@ -94,7 +94,6 @@ public class MarriedKeyChain extends DeterministicKeyChain {
@Override
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");
if (threshold == 0)
@@ -103,15 +102,17 @@ public class MarriedKeyChain extends DeterministicKeyChain {
accountPath = ACCOUNT_ZERO_PATH;
MarriedKeyChain chain;
if (random != null) {
if (random != null)
chain = new MarriedKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, accountPath);
} else if (entropy != null) {
chain = new MarriedKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null, accountPath);
} else if (seed != null) {
else if (entropy != null)
chain = new MarriedKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null,
accountPath);
else if (seed != null)
chain = new MarriedKeyChain(seed, null, accountPath);
} else {
else if (watchingKey != null)
chain = new MarriedKeyChain(watchingKey);
}
else
throw new IllegalStateException();
chain.addFollowingAccountKeys(followingKeys, threshold);
return chain;
}