GoLab 2018 - Anna Bernardi - Decoding invalid base64 with state machines

Опубликовано: 04 Март 2026
на канале: GoLab conference
168
3

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.


💛 Follow us on TWITTER:   / golab_conf  
💜 Follow us on FACEBOOK:   / golabconf  

GoLab is the first Italian international conference on the Go programming language, organized by Develer.
Develer is not just an Italian company projecting and releasing hardware and software solutions for the industrial environment, but is also an ensemble of people sharing their great passion for new technologies and how they can be applied to your everyday life.

🔸 Follow DEVELER on INSTAGRAM:   / wearedeveler  
🔹 Follow DEVELER on FACEBOOK:   / we.are.develer  
🔸 Follow DEVELER on TWITTER:   / develer  
🔹 Follow DEVELER on LINKEDIN:   / 114426  
🔸 Follow DEVELER on TELEGRAM: https://t.me/wearedeveler
🔹 Follow DEVELER on TIK TOK:   / wearedeveler