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

bernardladenthin / BitcoinAddressFinder / #356

24 Jul 2025 04:12PM UTC coverage: 72.322%. Remained the same
#356

push

bernardladenthin
Move KeyProducer to package.

28 of 33 new or added lines in 5 files covered. (84.85%)

1654 of 2287 relevant lines covered (72.32%)

0.72 hits per line

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

79.17
/src/main/java/net/ladenthin/bitcoinaddressfinder/keyproducer/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.keyproducer;
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.BitHelper;
26
import net.ladenthin.bitcoinaddressfinder.KeyUtility;
27
import net.ladenthin.bitcoinaddressfinder.RandomSecretSupplier;
28
import net.ladenthin.bitcoinaddressfinder.SecretSupplier;
29
import net.ladenthin.bitcoinaddressfinder.configuration.CKeyProducerJavaRandom;
30

31
public class KeyProducerJavaRandom extends KeyProducerJava<CKeyProducerJavaRandom> {
32

33
    private final KeyUtility keyUtility;
34
    private final BitHelper bitHelper;
35
    private final SecretSupplier randomSupplier;
36
    
37
    /**
38
     * It is already thread local, no need for {@link java.util.concurrent.ThreadLocalRandom}.
39
     */
40
    private final Random random;
41
    
42
    public KeyProducerJavaRandom(CKeyProducerJavaRandom cKeyProducerJavaRandom, KeyUtility keyUtility, BitHelper bitHelper) {
43
        super(cKeyProducerJavaRandom);
1✔
44
        this.keyUtility = keyUtility;
1✔
45
        this.bitHelper = bitHelper;
1✔
46
        
47
        switch (cKeyProducerJavaRandom.keyProducerJavaRandomInstance) {
1✔
48
            case SECURE_RANDOM:
49
                try {
50
                    random = SecureRandom.getInstanceStrong();
1✔
NEW
51
                } catch (NoSuchAlgorithmException e) {
×
NEW
52
                    throw new RuntimeException(e);
×
53
                }
1✔
54
                break;
55
            case RANDOM_CURRENT_TIME_MILLIS_SEED:
56
                random = new Random(System.currentTimeMillis());
1✔
57
                break;
1✔
58
            case RANDOM_CUSTOM_SEED:
59
                random = new Random();
1✔
60
                if (cKeyProducerJavaRandom.customSeed != null) {
1✔
61
                    random.setSeed(cKeyProducerJavaRandom.customSeed); // only if explicitly configured
1✔
62
                }
63
                break;
64
            case SHA1_PRNG:
65
                try {
66
                    random = SecureRandom.getInstance("SHA1PRNG");
1✔
67
                    
68
                    // To simulate bug: do NOT set a seed at all
69
                    if (cKeyProducerJavaRandom.customSeed != null) {
1✔
70
                        random.setSeed(cKeyProducerJavaRandom.customSeed); // only if explicitly configured
1✔
71
                    }
NEW
72
                } catch (NoSuchAlgorithmException e) {
×
NEW
73
                    throw new RuntimeException(e);
×
74
                }
1✔
75
                break;
76
            default:
NEW
77
                throw new RuntimeException("Unknown keyProducerJavaRandomInstance: " + cKeyProducerJavaRandom.keyProducerJavaRandomInstance);
×
78
        }
79
        randomSupplier = new RandomSecretSupplier(random);
1✔
80
    }
1✔
81
    
82
    @Override
83
    public BigInteger[] createSecrets(int overallWorkSize, boolean returnStartSecretOnly) throws NoMoreSecretsAvailableException {
84
        return keyUtility.createSecrets(overallWorkSize, returnStartSecretOnly, this.cKeyProducerJava.privateKeyMaxNumBits, randomSupplier);
1✔
85
    }
86

87
    @Override
88
    public void interrupt() {
89
    }
1✔
90
}
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