IF Commons GitHub

base64

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-formats FR-008

Base64 and base64url (RFC 4648 §4 and §5), both ways, on bytes (commons 0001-formats FR-008): what DSSE envelopes, JWTs, data URLs, PEM and signed URLs carry. Decoding refuses what is not base64 of the alphabet asked for, rather than skipping it; base64url is written without padding and read with or without it. Taken from the helpers Stolos wrote in src/archon/export/intoto.ts and S/MIME.

import { fromBase64, toBase64, toBase64Url } from "./base64.ts";
toBase64(new TextEncoder().encode("foobar")); // "Zm9vYmFy"
toBase64Url(Uint8Array.of(0xfb, 0xff)); // "-_8"
fromBase64("Zm9v"); // { kind: "ok", value: Uint8Array [102, 111, 111] }

Source: commons/formats/src/base64.ts

4 of 4 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

fromBase64function
function fromBase64(text: string): Result<Uint8Array<ArrayBufferLike>, string>

Standard base64 as bytes; white space between the characters is ignored, and anything else that is not base64 refused.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

fromBase64Urlfunction
function fromBase64Url(text: string): Result<Uint8Array<ArrayBufferLike>, string>

Base64url (padded or not) as bytes; anything else refused.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

toBase64function
function toBase64(bytes: Uint8Array<ArrayBufferLike>): string

Bytes as standard base64, padded.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

toBase64Urlfunction
function toBase64Url(bytes: Uint8Array<ArrayBufferLike>): string

Bytes as base64url, without padding.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.