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

bernardladenthin / BitcoinAddressFinder / #305

19 Apr 2025 11:43PM UTC coverage: 68.442% (+0.9%) from 67.58%
#305

push

bernardladenthin
Refactor private key validation and serialization; extract logic to KeyUtility and ByteBufferUtility, improve tests

51 of 65 new or added lines in 9 files covered. (78.46%)

2 existing lines in 2 files now uncovered.

1195 of 1746 relevant lines covered (68.44%)

0.68 hits per line

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

72.73
/src/main/java/net/ladenthin/bitcoinaddressfinder/PrivateKeyTooLargeException.java
1
// @formatter:off
2
/**
3
 * Copyright 2025 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

23
/**
24
 * Exception thrown when a given private key exceeds the safe upper bound
25
 * for use in grid-based key chunking (incrementing the base key).
26
 * <p>
27
 * The maximum allowed private key is {@link PublicKeyBytes#MAX_PRIVATE_KEY}.
28
 * This exception is typically thrown if the base key plus the chunk range (2^bits) exceeds this bound.
29
 */
30
public class PrivateKeyTooLargeException extends IllegalArgumentException {
31

32
    private final BigInteger providedKey;
33
    private final BigInteger maxAllowedKey;
34
    private final int batchSizeInBits;
35

36
    public PrivateKeyTooLargeException(BigInteger providedKey, BigInteger maxAllowedKey, int batchSizeInBits) {
37
        super(buildMessage(providedKey, maxAllowedKey, batchSizeInBits));
1✔
38
        this.providedKey = providedKey;
1✔
39
        this.maxAllowedKey = maxAllowedKey;
1✔
40
        this.batchSizeInBits = batchSizeInBits;
1✔
41
    }
1✔
42

43
    private static String buildMessage(BigInteger providedKey, BigInteger maxAllowedKey, int batchSizeInBits) {
44
        return "Private key exceeds maximum allowed range for chunked grid mode: " +
1✔
45
               "\nProvided key:        0x" + providedKey.toString(16) +
1✔
46
               "\nMaximum allowed key: 0x" + maxAllowedKey.toString(16) +
1✔
47
               "\n(batchSizeInBits = " + batchSizeInBits + ")" +
48
               "\nThe maximum private key is defined in: PublicKeyBytes.MAX_PRIVATE_KEY";
49
    }
50

51
    public BigInteger getProvidedKey() {
NEW
52
        return providedKey;
×
53
    }
54

55
    public BigInteger getMaxAllowedKey() {
NEW
56
        return maxAllowedKey;
×
57
    }
58

59
    public int getBatchSizeInBits() {
NEW
60
        return batchSizeInBits;
×
61
    }
62
}
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