• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bernardladenthin / BitcoinAddressFinder / #349

17 Jul 2025 09:52PM UTC coverage: 69.883% (+0.3%) from 69.604%
#349

push

bernardladenthin
refactor: move BIP39 key producer to dedicated class, add coverage tests, update README with usage examples

70 of 76 new or added lines in 10 files covered. (92.11%)

1 existing line in 1 file now uncovered.

1434 of 2052 relevant lines covered (69.88%)

0.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.26
/src/main/java/net/ladenthin/bitcoinaddressfinder/KeyProducerJavaRandom.java
1
// @formatter:off
2
/**
3
 * Copyright 2024 Bernard Ladenthin bernard.ladenthin@gmail.com
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *    http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
// @formatter:on
19
package net.ladenthin.bitcoinaddressfinder;
20

21
import java.math.BigInteger;
22
import java.security.NoSuchAlgorithmException;
23
import java.security.SecureRandom;
24
import java.util.Random;
25
import net.ladenthin.bitcoinaddressfinder.configuration.CKeyProducerJavaRandom;
26

27
public class KeyProducerJavaRandom extends KeyProducerJava {
28

29
    private final CKeyProducerJavaRandom cKeyProducerJavaRandom;
30
    private final KeyUtility keyUtility;
31
    private final BitHelper bitHelper;
32
    
33
    /**
34
     * It is already thread local, no need for {@link java.util.concurrent.ThreadLocalRandom}.
35
     */
36
    private final Random random;
37
    
38
    public KeyProducerJavaRandom(CKeyProducerJavaRandom cKeyProducerJavaRandom, KeyUtility keyUtility, BitHelper bitHelper) {
39
        super(cKeyProducerJavaRandom);
1✔
40
        this.cKeyProducerJavaRandom = cKeyProducerJavaRandom;
1✔
41
        this.keyUtility = keyUtility;
1✔
42
        this.bitHelper = bitHelper;
1✔
43
        
44
        switch (cKeyProducerJavaRandom.keyProducerJavaRandomInstance) {
1✔
45
            case SECURE_RANDOM:
46
                try {
47
                    random = SecureRandom.getInstanceStrong();
1✔
48
                } catch (NoSuchAlgorithmException e) {
×
49
                    throw new RuntimeException(e);
×
50
                }
1✔
51
                break;
52
            case RANDOM_CURRENT_TIME_MILLIS_SEED:
53
                random = new Random(System.currentTimeMillis());
1✔
54
                break;
1✔
55
            case RANDOM_CUSTOM_SEED:
56
                random = new Random();
1✔
57
                if (cKeyProducerJavaRandom.customSeed != null) {
1✔
58
                    random.setSeed(cKeyProducerJavaRandom.customSeed); // only if explicitly configured
1✔
59
                }
60
                break;
61
            case SHA1_PRNG:
62
                try {
63
                    random = SecureRandom.getInstance("SHA1PRNG");
1✔
64
                    
65
                    // To simulate bug: do NOT set a seed at all
66
                    if (cKeyProducerJavaRandom.customSeed != null) {
1✔
67
                        random.setSeed(cKeyProducerJavaRandom.customSeed); // only if explicitly configured
1✔
68
                    }
69
                } catch (NoSuchAlgorithmException e) {
×
70
                    throw new RuntimeException(e);
×
71
                }
1✔
72
                break;
73
            default:
UNCOV
74
                throw new RuntimeException("Unknown keyProducerJavaRandomInstance: " + cKeyProducerJavaRandom.keyProducerJavaRandomInstance);
×
75
        }
76
    }
1✔
77
    
78
    @Override
79
    public BigInteger[] createSecrets(int overallWorkSize, boolean returnStartSecretOnly) throws NoMoreSecretsAvailableException {
80
        return keyUtility.createSecrets(overallWorkSize, returnStartSecretOnly, cKeyProducerJavaRandom.privateKeyMaxNumBits, random);
1✔
81
    }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc