Silk

silk/http_basic

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.

Explicit bounded HTTP Basic authorization from caller-encoded credential bytes.

Details

The caller chooses the character encoding and supplies scratch and output buffers. Encoding validates both credentials and both capacities before it changes either buffer. The HTTP client controls origin binding and permission to send credentials over plain HTTP.

Import as HttpBasic with import silk.http_basic as HttpBasic.

Public declarations: 3.

BasicError

pub enum BasicError

A credential validation or capacity failure without credential contents.

InvalidUsername

InvalidUsername = 0

The username contains a colon, a control byte, or DEL.

InvalidPassword

InvalidPassword = 1

The password contains a control byte or DEL.

SizeOverflow

SizeOverflow = 2

The credential or encoded size cannot fit in usize.

ScratchTooSmall

ScratchTooSmall = 3

Scratch cannot hold the username, separator, and password.

OutputTooSmall

OutputTooSmall = 4

Output cannot hold the complete authorization value.

encodedLength

pub fn encodedLength(usernameLength: usize, passwordLength: usize) -> silk/result.Result<usize, silk/http_basic.BasicError>

Returns the exact output length, including the six-byte Basic prefix.

encodeInto

pub fn encodeInto<'life0, 'life1, 'life2, 'life3>(username: &'life0 [u8], password: &'life1 [u8], scratch: &'life2 mut [u8], output: &'life3 mut [u8]) -> silk/result.Result<usize, silk/http_basic.BasicError>

Writes Basic and padded Base64 of username:password, returning the complete byte count.

Details

A colon in the username or a control byte or DEL in either credential fails before mutation. Non-ASCII bytes are accepted without character conversion. Failure leaves output and scratch unchanged. Scratch retains the combined credential after success; the caller controls its later use and erasure.

On this page