URI Encoding #
This module provides utilities for percent-encoding URI components according to RFC 3986. It includes character validation, encoding/decoding functions, and types that maintain encoding invariants through Lean's dependent type system.
Reference: https://www.rfc-editor.org/rfc/rfc3986.html#section-2.1
Checks if a byte is valid in a percent-encoded query string component. Extends isEncodedChar to also
allow '+' which represents space in application/x-www-form-urlencoded format.
Instances For
Validates that all percent signs in a byte array are followed by exactly two hexadecimal digits. This ensures proper percent-encoding according to RFC 3986.
For example:
%20is valid (percent followed by two hex digits)%is invalid (percent with no following digits)%2is invalid (percent followed by only one digit)%GGis invalid (percent followed by non-hex characters)
Instances For
Converts a nibble (4-bit value, 0-15) to its hexadecimal digit representation. Returns '0'-'9' for values 0-9, and 'A'-'F' for values 10-15.
Instances For
Converts a hexadecimal digit character to its numeric value (0-15).
Returns none if the character is not a valid hex digit.
Instances For
A percent-encoded URI component with a compile-time proof that it contains only valid encoded characters. This provides type-safe URI encoding without runtime validation.
The invariant guarantees that the string contains only unreserved characters (alphanumeric, hyphen, period, underscore, tilde) and percent signs (for escape sequences).
- toByteArray : ByteArray
The underlying byte array containing the percent-encoded data.
- valid : IsAllowedEncodedChars r self.toByteArray
Proof that all characters in the byte array are valid encoded characters.
Instances For
Creates an empty encoded string.
Instances For
Encodes a raw string into an EncodedString with automatic proof construction. Unreserved characters
(alphanumeric, hyphen, period, underscore, tilde) are kept as-is, while all other characters are percent-encoded.
Instances For
Attempts to create an EncodedString from a ByteArray. Returns some if the byte array contains only
valid encoded characters and all percent signs are followed by exactly two hex digits, none otherwise.
Instances For
Creates an EncodedString from a ByteArray, panicking if the byte array is invalid.
Instances For
Creates an EncodedString from a String by checking if it's already a valid percent-encoded string.
Returns some if valid, none otherwise.
Instances For
Creates an EncodedString from a String, panicking if the string is not a valid percent-encoded string.
Instances For
Creates an EncodedString from a ByteArray with compile-time proofs.
Use this when you have proofs that the byte array is valid.
Instances For
Decodes an EncodedString back to a regular String. Converts percent-encoded sequences (e.g., "%20")
back to their original characters. Returns none if the decoded bytes are not valid UTF-8.
Instances For
A percent-encoded query string component with a compile-time proof that it contains only valid encoded
query characters. Extends EncodedString to support the '+' character for spaces, following the
application/x-www-form-urlencoded format.
This type is specifically designed for encoding query parameters where spaces can be represented as '+' instead of "%20".
- toByteArray : ByteArray
The underlying byte array containing the percent-encoded query data.
- valid : IsAllowedEncodedQueryChars r self.toByteArray
Proof that all characters in the byte array are valid encoded query characters.
Instances For
Creates an empty encoded query string.
Instances For
Attempts to create an EncodedQueryString from a ByteArray. Returns some if the byte array contains
only valid encoded query characters and all percent signs are followed by exactly two hex digits, none otherwise.
Instances For
Creates an EncodedQueryString from a ByteArray, panicking if the byte array is invalid.
Instances For
Creates an EncodedQueryString from a String by checking if it's already a valid percent-encoded string.
Returns some if valid, none otherwise.
Instances For
Creates an EncodedQueryString from a String, panicking if the string is not a valid percent-encoded string.
Instances For
Creates an EncodedQueryString from a ByteArray with compile-time proofs.
Use this when you have proofs that the byte array is valid.
Instances For
Encodes a raw string into an EncodedQueryString with automatic proof construction. Unreserved characters
are kept as-is, spaces are encoded as '+', and all other characters are percent-encoded.
Instances For
Converts an EncodedQueryString to a String, given a proof that all characters satisfying r are ASCII.
Instances For
Decodes an EncodedQueryString back to a regular String. Converts percent-encoded sequences and '+'
signs back to their original characters. Returns none if the decoded bytes are not valid UTF-8.
This is almost the same code from System.Uri.UriEscape.decodeUri, but with Option instead.
Instances For
A percent-encoded URI path segment. Valid characters are pchar (unreserved, sub-delims, ':', '@').
Instances For
Encodes a raw string into an encoded path segment.
Instances For
Attempts to create an encoded path segment from raw bytes.
Instances For
Creates an encoded path segment from raw bytes, panicking on invalid encoding.
Instances For
Decodes an encoded path segment back to a UTF-8 string.
Instances For
A percent-encoded URI fragment component. Valid characters are pchar / "/" / "?".
Instances For
Encodes a raw string into an encoded fragment component.
Instances For
Attempts to create an encoded fragment component from raw bytes.
Instances For
Creates an encoded fragment component from raw bytes, panicking on invalid encoding.
Instances For
Decodes an encoded fragment component back to a UTF-8 string.
Instances For
A percent-encoded URI userinfo component. Valid characters are unreserved / sub-delims / ":".
Instances For
Encodes a raw string into an encoded userinfo component.
Instances For
Attempts to create an encoded userinfo component from raw bytes.
Instances For
Creates an encoded userinfo component from raw bytes, panicking on invalid encoding.
Instances For
Decodes an encoded userinfo component back to a UTF-8 string.
Instances For
A percent-encoded URI query parameter. Valid characters are pchar / "/" / "?" with '+' for spaces.
Instances For
Encodes a raw string into an encoded query parameter.
Instances For
Attempts to create an encoded query parameter from raw bytes.
Instances For
Creates an encoded query parameter from raw bytes, panicking on invalid encoding.
Instances For
Attempts to create an encoded query parameter from an encoded string.
Instances For
Decodes an encoded query parameter back to a UTF-8 string.