This module implements MultiBase.
TODO:
- base32z
Types
MultiBaseStatus {.pure.} = enum Error, Success, Overrun, Incorrect, BadCodec, NotSupported
- Source Edit
Consts
MultibaseList = ["identity", "base1", "base2", "base8", "base10", "base16", "base16upper", "base32hex", "base32hexupper", "base32hexpad", "base32hexpadupper", "base32", "base32upper", "base32pad", "base32padupper", "base32z", "base58flickr", "base58btc", "base64", "base64pad", "base64url", "base64urlpad"]
- Source Edit
Procs
proc decode(mbtype: typedesc[MultiBase]; inbytes: openArray[char]): Result[ seq[byte], string] {....raises: [].}
- Decode MultiBase encoded array inbytes and return decoded sequence of bytes. Source Edit
proc decode(mbtype: typedesc[MultiBase]; inbytes: openArray[char]; outbytes: var openArray[byte]; outlen: var int): MultiBaseStatus {. ...raises: [].}
-
Decode array inbytes using MultiBase encoding and store decoded value to outbytes.
If inbytes is not correct MultiBase string, then MultiBaseStatus.BadCodec if first character is wrong, or MultiBaseStatus.Incorrect if string has incorrect characters for such encoding.
If length of outbytes is not enough to store decoded result, then MultiBaseStatus.Overrun error will be returned and outlen will be set to length required.
On successfull decoding MultiBaseStatus.Success will be returned and outlen will be set to number of encoded octets (bytes).
Source Edit proc decodedLength(mbtype: typedesc[MultiBase]; encoding: char; length: int): int {. ...raises: [].}
- Return estimated size of buffer to store MultiBase decoded value with encoding character encoding of length length. Source Edit
proc encode(mbtype: typedesc[MultiBase]; encoding: string; inbytes: openArray[byte]): Result[string, string] {....raises: [].}
- Encode array inbytes using MultiBase encoding scheme encoding and return encoded string. Source Edit
proc encode(mbtype: typedesc[MultiBase]; encoding: string; inbytes: openArray[byte]; outbytes: var openArray[char]; outlen: var int): MultiBaseStatus {....raises: [].}
-
Encode array inbytes using MultiBase encoding scheme encoding and store encoded value to outbytes.
If encoding is not supported MultiBaseStatus.NotSupported will be returned.
If encoding is not correct string, then MultBaseStatus.BadCodec will be returned.
If length of outbytes is not enough to store encoded result, then MultiBaseStatus.Overrun error will be returned and outlen will be set to length required.
On successfull encoding MultiBaseStatus.Success will be returned and outlen will be set to number of encoded octets (bytes).
Source Edit proc encodedLength(mbtype: typedesc[MultiBase]; encoding: string; length: int): int {. ...raises: [].}
-
Return estimated size of buffer to store MultiBase encoded value with encoding encoding of length length.
Procedure returns -1 if encoding scheme is not supported or not present.
Source Edit