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

bernardladenthin / BitcoinAddressFinder / #246

08 Apr 2025 06:29AM UTC coverage: 59.356% (-6.0%) from 65.404%
#246

push

bernardladenthin
Add timeout. Extract interruptAfterDelay. Ignore testRoundtrip_configurationsGiven_lmdbCreatedExportedAndRunFindSecretsFile for now.

1050 of 1769 relevant lines covered (59.36%)

0.59 hits per line

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

65.0
/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
    
32
    /**
33
     * It is already thread local, no need for {@link java.util.concurrent.ThreadLocalRandom}.
34
     */
35
    private final Random random;
36
    private final BitHelper bitHelper;
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();
×
48
                } catch (NoSuchAlgorithmException e) {
×
49
                    throw new RuntimeException(e);
×
50
                }
×
51
                break;
52
            case RANDOM_SEED_CURRENT_TIME_MILLIS:
53
                random = new Random(System.currentTimeMillis());
×
54
                break;
×
55
            case RANDOM_CUSTOM_SEED:
56
                random = new Random(cKeyProducerJavaRandom.customSeed);
1✔
57
                break;
1✔
58
            default:
59
                throw new RuntimeException("Unknown keyProducerJavaRandomInstance: " + cKeyProducerJavaRandom.keyProducerJavaRandomInstance);
×
60
        }
61
    }
1✔
62
    
63
    @Override
64
    public BigInteger[] createSecrets(int batchSizeInBits, boolean returnStartSecretOnly) throws NoMoreSecretsAvailableException {
65
        int length = returnStartSecretOnly ? 1 : bitHelper.convertBitsToSize(batchSizeInBits);
1✔
66
        BigInteger[] secrets = new BigInteger[length];
1✔
67
        for (int i = 0; i < secrets.length; i++) {
1✔
68
            secrets[i] = keyUtility.createSecret(cKeyProducerJavaRandom.privateKeyMaxNumBits, random);
1✔
69
        }
70
        return secrets;
1✔
71
    }
72
}
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