Decoding invalid base64 with state machines

How many times did you try to decode a string and couldn’t because it was malformed? With state machines, we can dynamically decode malformed or incomplete strings. This talk will discuss how to implement such state machines and the problems you might encounter.

Abstract

How many times did you try to decode a string and couldn’t because it was malformed? With state machines, we can dynamically decode malformed or incomplete strings. This talk will discuss how to implement such state machines and the problems you might encounter. Applying university computer science to real projects is not always a straightforward process. This talk is an example of how to implement a finite state machine (FSM) from a paper design to a Go project. It all started with a bunch of malformed b64 strings that couldn’t be decoded by standard tools only because they had some invalid characters in the middle. After stripping a couple of them manually, it was time to solve this problem more definitively. Our use case was the decoding package of an open source suite to test web applications, Wapty (https://github.com/empijei/wapty). The decode package uses a finite state machine to parse strings and intelligently decode them. If an invalid sequence is encountered, the tool will replace it with a default character and then try to recover the decoding process. This is possible thanks to a FSM that peeks the next characters and, if they are valid, proceeds to decode them, otherwise ignoring them and moving on.

Video

Stay connected

You can subscribe to our newsletter to stay updated on the latest news and announcements. Follow us on social media to join our community and engage with other attendees, speakers, and staff. We're on Twitter, Mastodon, Youtube and Facebook. Don't forget to use our official hashtag #GoLab2023 to share your experience and connect with other attendees on social media.

Subscribe to our newsletter

We hate spam just as much as you do, which is why we promise to only send you relevant communications. We respect your privacy and will never share your information with third parties.
©2023 GoLab | The international conference on Go in Florence-Design & devCantiere Creativo-Made withDatoCMS