basenc: implement --base58 encoding option (#8751)

* basenc: implement --base58 encoding option

Add support for Base58 encoding to basenc as per GNU coreutils 9.8.
Base58 uses the alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
which excludes visually ambiguous characters (0, O, I, l).

Resolves issue #8744.

* basenc: fix clippy warnings and spelling issues

Fix explicit iteration clippy warnings. Add Base58 alphabet to spell-checker ignore list to resolve cspell errors.
This commit is contained in:
AnarchistHoneybun
2025-10-05 14:03:45 +02:00
committed by GitHub
parent c0cdd904b8
commit e16ce60a38
6 changed files with 177 additions and 15 deletions
+31 -13
View File
@@ -185,21 +185,30 @@ fn test_base2lsbf_decode() {
}
#[test]
fn test_choose_last_encoding_z85() {
fn test_z85_decode() {
new_ucmd!()
.args(&[
"--base2lsbf",
"--base2msbf",
"--base16",
"--base32hex",
"--base64url",
"--base32",
"--base64",
"--z85",
])
.pipe_in("Hello, World")
.args(&["--z85", "-d"])
.pipe_in("nm=QNz.92jz/PV8")
.succeeds()
.stdout_only("nm=QNz.92jz/PV8\n");
.stdout_only("Hello, World");
}
#[test]
fn test_base58() {
new_ucmd!()
.arg("--base58")
.pipe_in("Hello, World!")
.succeeds()
.stdout_only("72k1xXWG59fYdzSNoA\n");
}
#[test]
fn test_base58_decode() {
new_ucmd!()
.args(&["--base58", "-d"])
.pipe_in("72k1xXWG59fYdzSNoA")
.succeeds()
.stdout_only("Hello, World!");
}
#[test]
@@ -238,6 +247,15 @@ fn test_choose_last_encoding_base2lsbf() {
.stdout_only("00110110110011100100011001100110\n");
}
#[test]
fn test_choose_last_encoding_base58() {
new_ucmd!()
.args(&["--base64", "--base32", "--base16", "--z85", "--base58"])
.pipe_in("Hello!")
.succeeds()
.stdout_only("d3yC1LKr\n");
}
#[test]
fn test_base32_decode_repeated() {
new_ucmd!()