UNPKG

@alessiofrittoli/crypto-encoder

Version:
103 lines (100 loc) 3.9 kB
import { CoerceToUint8ArrayInput } from '@alessiofrittoli/crypto-buffer'; /** * Base32 Variant * * - `'RFC3548'` - Alias for `'RFC4648'` * - `'RFC4648'` - [Base32 from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'RFC4648-HEX'` - [base32hex from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'Crockford'` - [Crockford's Base32](http://www.crockford.com/wrmg/base32.html) */ type Variant = 'RFC3548' | 'RFC4648' | 'RFC4648-HEX' | 'Crockford'; interface EncodeOptions { /** If set, forcefully enable or disable padding. The default behavior is to follow the default of the selected variant. */ padding?: boolean; } /** * Base32 Utility static class. * * Supported Variants: * * - `'RFC3548'` - Alias for `'RFC4648'` * - `'RFC4648'` - [Base32 from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'RFC4648-HEX'` - [base32hex from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'Crockford'` - [Crockford's Base32](http://www.crockford.com/wrmg/base32.html) */ declare class Base32 { /** * Base32 Variant * * - `'RFC3548'` - Alias for `'RFC4648'` * - `'RFC4648'` - [Base32 from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'RFC4648-HEX'` - [base32hex from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'Crockford'` - [Crockford's Base32](http://www.crockford.com/wrmg/base32.html) */ static VARIANT: { /** Alias for `'RFC4648'` */ readonly RFC3548: "RFC3548"; /** [Base32 from RFC4648](https://tools.ietf.org/html/rfc4648) */ readonly RFC4648: "RFC4648"; /** [base32hex from RFC4648](https://tools.ietf.org/html/rfc4648) */ readonly RFC4648_HEX: "RFC4648-HEX"; /** [Crockford's Base32](http://www.crockford.com/wrmg/base32.html) */ readonly Crockford: "Crockford"; }; /** * Alphabet based on the Base32 Variant. * */ private static ALPHABET; /** * Encode data to Base32. * * @param data The data to encode. * @param variant The Variant to use. * @param options ( Optional ) An object defining encoding options. * @returns The encoded `data` to Base32 string. * * --- * * Supported variants: * * - `'RFC3548'` - Alias for `'RFC4648'` * - `'RFC4648'` - [Base32 from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'RFC4648-HEX'` - [base32hex from RFC4648](https://tools.ietf.org/html/rfc4648) * - `'Crockford'` - [Crockford's Base32](http://www.crockford.com/wrmg/base32.html) */ static encode(data: CoerceToUint8ArrayInput, variant: Variant, options?: EncodeOptions): string; /** * Decode a Base32 data. * * @param data The input data to decode. * @param variant The Variant used to encode the given input. * @returns The `ArrayBuffer` result of decoded `input`. */ static decode(data: CoerceToUint8ArrayInput, variant: Variant): Uint8Array<ArrayBuffer>; /** * Get the index of the `char` in the Base32 Variant `alphabet`. * * @param alphabet The Base32 Variant alphabet. * @param char The character. * @returns The index of the `char` in the `alphabet`. */ private static readChar; /** * Get Variant alphabet and default padding setting. * * @param variant The Base32 Variant. * @returns An object with `alphabet` and default `padding` flag based on the given `variant`. */ private static getEncodeVariantAlphabetAndPadding; /** * Get Variant alphabet and parsed input. * * @param input The input to parse. * @param variant The Base32 Variant. * @returns An object with `alphabet` and parsed `input` based on the given `variant`. */ private static getDecodeVariantAlphabetAndInput; static toString: (input: CoerceToUint8ArrayInput) => string; } export { Base32, type Variant };