Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding: implement RFC4648 base32 encoding #1596

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

konimarti
Copy link
Contributor

Implement base32 encoding and decoding according to RFC 4648 with the standard and extended hex alphabets. Add unit tests.

Link: https://www.rfc-editor.org/rfc/rfc4648

Implement base32 encoding and decoding according to RFC 4648 with the
standard and extended hex alphabets. Add unit tests.

Link: https://www.rfc-editor.org/rfc/rfc4648
Signed-off-by: Koni Marti <koni.marti@gmail.com>
@lerno
Copy link
Collaborator

lerno commented Nov 3, 2024

Looks good, can you also put a not in the release notes for it, plus change to Allman brace style, which is the style used in the stdlib elsewhere, so rather than this:

 	if (self.padding >= 0) {
 		// with padding
 		return (n / 8) * 5;
 	} else {
 		// no padding
 		usz trailing = n % 8;
 		return n / 8 * 5 + (trailing * 5 ) / 8;
 	}

Use:

 	if (self.padding >= 0) 
 	{
 		// with padding
 		return (n / 8) * 5;
 	} 
 	else 
 	{
 		// no padding
 		usz trailing = n % 8;
 		return n / 8 * 5 + (trailing * 5 ) / 8;
 	}

@konimarti
Copy link
Contributor Author

Thanks @lerno! I've addressed your comments above with two fixup commits for easier review. Let me know if you want me to squash them.

@lerno
Copy link
Collaborator

lerno commented Nov 4, 2024

I can squash it, so that's fine. Thank you for the contribution!

@lerno lerno merged commit 8154e27 into c3lang:master Nov 4, 2024
43 checks passed
@lerno
Copy link
Collaborator

lerno commented Nov 4, 2024

One thing that would be nice would be to have Base64 and Base32 streams. It would be a much nicer interface to output things.

@konimarti konimarti deleted the add-base32-enc branch November 4, 2024 12:06
@konimarti
Copy link
Contributor Author

Yes, having streams would be very useful.

I've actually played around with streams for a base16/hex encoding port from Golang's stdlib to c3: https://github.com/konimarti/hex.c3l/blob/master/hex.c3

Could be a starting point.

@lerno
Copy link
Collaborator

lerno commented Nov 4, 2024

Yeah, it's not super hard to, and you get some nice features to copy one stream to another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants