std/base64

The std/base64 module provides RFC 4648 Base64 encoding and decoding. Encoding converts binary data into an ASCII string; decoding reverses the process, validating the input length and characters.

Overview

Usage

import "std/encoding/base64.zc"
import "std/io.zc"

fn main() {
    let data = (u8*)"foobar";
    let encoded = Base64::encode(data, strlen(data));
    println(f"Encoded: {encoded.c_str()}");

    let decoded = Base64::decode(encoded.c_str());
    if (decoded.is_ok()) {
        println(f"Decoded back to {decoded.unwrap().len} bytes");
    }
}

Struct Definition

struct Base64 {}

Methods

MethodSignatureDescription
encodeencode(data: u8*, len: usize) -> StringEncodes len bytes into a Base64 String.
decodedecode(data: char*) -> Result<Vec<u8>>Decodes a Base64 string into a Vec<u8>. Returns Err on an invalid length or character.