Skip to content

fastc-lang/fastc-core-base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastc-core-base64

Base64 encoding / decoding for fastC.

Part of the fastc-core launch set. The implementation currently ships inside the fastC compiler's built-in prelude — every fastC v1.0 program already gets use base64::* for free. This repository is the public home for the module's API and will become installable via fastc add github.com/Skelf-Research/fastc-core-base64 once stage 1.7's vendor-consumption flow completes the loop.

Surface

use base64::encode;       // (bytes: slice(u8)) -> Str
use base64::decode;       // (s: Str) -> opt(Vec[u8])

use base64::encode_url;   // (bytes: slice(u8)) -> Str
use base64::decode_url;   // (s: Str) -> opt(Vec[u8])

Alphabet and padding (RFC 4648):

encode / decode          §4 standard alphabet (A-Za-z0-9+/), '=' padding
encode_url / decode_url  §5 URL-safe alphabet (A-Za-z0-9-_), no padding

decode and decode_url return None on any invalid input: characters outside the chosen alphabet, malformed padding (for the standard form), or truncated quanta.

Example

use base64::encode;
use base64::decode;
use io::println;

fn main() -> i32 {
    let raw: slice(u8) = b"fastC v1.0";
    let s: Str = encode(raw);          // "ZmFzdEMgdjEuMA=="
    println(s.as_cstr());

    let round: opt(Vec[u8]) = decode(s);
    if (round.is_none()) {
        return 1;
    }
    let back: Vec[u8] = round.unwrap();
    if (back.as_slice() != raw) {
        return 1;
    }
    return 0;
}

Capability policy

Pure data transform — no Cap* token required. encode, decode, encode_url, and decode_url touch no syscalls, no clock, no filesystem, no network. They allocate a Str or Vec[u8] and that is the entire side effect.

Status

v0.1.0 — preview. API is final; the package becomes a true installable via fastc add once the consumption flow ships. Until then, the same API is available in every fastC v1.0 program via the built-in prelude.

License

MIT

About

Base64 encoding/decoding for fastC (RFC 4648). Part of the fastc-core six-month set.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors