Skip to content

Commit 68272de

Browse files
committed
javadoc
1 parent d5cbcc1 commit 68272de

File tree

8 files changed

+49
-46
lines changed

8 files changed

+49
-46
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
- name: Upload pages artifact
8181
uses: actions/upload-pages-artifact@v3
8282
with:
83-
path: 'dist/javadoc'
83+
path: 'dist/javadoc/bech32'
8484

8585
- name: Deploy to GitHub Pages
8686
if: github.event_name == 'release'

src/main/java/org/ngengine/bech32/Bech32.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,32 @@ public class Bech32 {
4646
private static final int[] GENERATORS = { 0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3 };
4747
private static final char BECH32_SEPARATOR = '1';
4848

49+
/**
50+
* Encode some arbitrary data into a Bech32 string.
51+
*
52+
* <p>
53+
* This method will internally allocate a 6 byte array to hold the checksum.
54+
* If you want to avoid this internal allocation, use the other overload that takes a byte array as argument
55+
* </p>
56+
*
57+
* @param hrp the human readable part (the prefix), must be utf-8 encoded
58+
* @param data a ByteBuffer containing the data to encode, must be at position 0 and limit set to the length of the data
59+
* @return the Bech32 encoded string
60+
* @throws Bech32EncodingException
61+
*/
4962
public static String bech32Encode(byte[] hrp, ByteBuffer data) throws Bech32EncodingException {
5063
byte[] chk = new byte[6];
5164
return bech32Encode(hrp, data, chk);
5265
}
5366

67+
/**
68+
* Encode some arbitrary data into a Bech32 string.
69+
* @param hrp the human readable part (the prefix), must be utf-8 encoded
70+
* @param data a ByteBuffer containing the data to encode, must be at position 0 and limit set to the length of the data
71+
* @param chkOut a byte array of length 6 that will be filled with the checksum
72+
* @return
73+
* @throws Bech32EncodingException
74+
*/
5475
public static String bech32Encode(byte[] hrp, ByteBuffer data, byte[] chkOut) throws Bech32EncodingException {
5576
if (chkOut == null || chkOut.length < 6) {
5677
throw new Bech32EncodingException("invalid checksum buffer");
@@ -88,6 +109,14 @@ public static String bech32Encode(byte[] hrp, ByteBuffer data, byte[] chkOut) th
88109
return new String(ret, StandardCharsets.UTF_8);
89110
}
90111

112+
/**
113+
* Decode a Bech32 string into a ByteBuffer.
114+
* @param bech the Bech32 encoded string, must be lower case
115+
* @return a ByteBuffer containing the decoded data, the position will be set to 0 and the limit to the length of the data
116+
* @throws Bech32DecodingException
117+
* @throws Bech32InvalidChecksumException
118+
* @throws Bech32InvalidRangeException
119+
*/
91120
public static ByteBuffer bech32Decode(String bech)
92121
throws Bech32DecodingException, Bech32InvalidChecksumException, Bech32InvalidRangeException {
93122
byte[] bytes = getLowerCaseBytes(bech);

src/main/java/org/ngengine/bech32/Bech32DecodingException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
package org.ngengine.bech32;
3333

34+
/**
35+
* Exception thrown when a Bech32 decoding operation fails.
36+
* This can happen due to various reasons such as invalid format or other decoding errors.
37+
*/
3438
public class Bech32DecodingException extends Bech32Exception {
3539

3640
private static final long serialVersionUID = 1L;

src/main/java/org/ngengine/bech32/Bech32EncodingException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
package org.ngengine.bech32;
3333

34+
/**
35+
* Exception thrown when a Bech32 encoding operation fails.
36+
* This can happen due to various reasons such as invalid input data or other encoding errors.
37+
*/
3438
public class Bech32EncodingException extends Bech32Exception {
3539

3640
private static final long serialVersionUID = 1L;

src/main/java/org/ngengine/bech32/Bech32Exception.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
package org.ngengine.bech32;
3333

34+
/**
35+
* A generic exception for Bech32 operations.
36+
*/
3437
public class Bech32Exception extends Exception {
3538

3639
private static final long serialVersionUID = 1L;

src/main/java/org/ngengine/bech32/Bech32InvalidChecksumException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
package org.ngengine.bech32;
3333

34+
/**
35+
* Exception thrown when a Bech32 decoding operation fails due to an invalid checksum.
36+
* This indicates that the checksum does not match the expected value for the given data eg. due to corruption or tampering.
37+
*/
3438
public class Bech32InvalidChecksumException extends Bech32Exception {
3539

3640
private static final long serialVersionUID = 1L;

src/main/java/org/ngengine/bech32/Bech32InvalidRangeException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
package org.ngengine.bech32;
3333

34+
/**
35+
* Exception thrown when a Bech32 decoding operation fails due to the characters in the
36+
* data being out of the valid range. This indicates a malformed input bech32 string.
37+
*/
3438
public class Bech32InvalidRangeException extends Bech32Exception {
3539

3640
private static final long serialVersionUID = 1L;

src/main/java/org/ngengine/bech32/Bech32RuntimeException.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)