MCPcopy Index your code
hub / github.com/apache/commons-codec / Base32

Class Base32

src/main/java/org/apache/commons/codec/binary/Base32.java:43–582  ·  view source on GitHub ↗

Provides Base32 encoding and decoding as defined by RFC 4648 . The class can be parameterized in the following manner with various constructors: Whether to use the "base32hex" variant instead of the default "base32" Line le

Source from the content-addressed store, hash-verified

41 * @since 1.5
42 */
43public class Base32 extends BaseNCodec {
44
45 /**
46 * BASE32 characters are 5 bits in length.
47 * They are formed by taking a block of five octets to form a 40-bit string,
48 * which is converted into eight BASE32 characters.
49 */
50 private static final int BITS_PER_ENCODED_BYTE = 5;
51 private static final int BYTES_PER_ENCODED_BLOCK = 8;
52 private static final int BYTES_PER_UNENCODED_BLOCK = 5;
53
54 /**
55 * Chunk separator per RFC 2045 section 2.1.
56 *
57 * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
58 */
59 private static final byte[] CHUNK_SEPARATOR = {'\r', '\n'};
60
61 /**
62 * This array is a lookup table that translates Unicode characters drawn from the "Base32 Alphabet" (as specified
63 * in Table 3 of RFC 4648) into their 5-bit positive integer equivalents. Characters that are not in the Base32
64 * alphabet but fall within the bounds of the array are translated to -1.
65 */
66 private static final byte[] DECODE_TABLE = {
67 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
68 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f
69 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f
70 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 20-2f
71 -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, // 30-3f 2-7
72 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 40-4f A-O
73 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // 50-5a P-Z
74 -1, -1, -1, -1, -1, // 5b - 5f
75 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 60 - 6f a-o
76 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // 70 - 7a p-z/**/
77 };
78
79 /**
80 * This array is a lookup table that translates 5-bit positive integer index values into their "Base32 Alphabet"
81 * equivalents as specified in Table 3 of RFC 4648.
82 */
83 private static final byte[] ENCODE_TABLE = {
84 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
85 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
86 '2', '3', '4', '5', '6', '7',
87 };
88
89 /**
90 * This array is a lookup table that translates Unicode characters drawn from the "Base32 Hex Alphabet" (as
91 * specified in Table 4 of RFC 4648) into their 5-bit positive integer equivalents. Characters that are not in the
92 * Base32 Hex alphabet but fall within the bounds of the array are translated to -1.
93 */
94 private static final byte[] HEX_DECODE_TABLE = {
95 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
96 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f
97 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f
98 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 20-2f
99 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 30-3f 2-7
100 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 40-4f A-O

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…