Crate tagged_base64
source ·Expand description
User-oriented format for binary data. Tagged Base64 is intended to be used in user interfaces including URLs and text to be copied and pasted without the need for additional encoding, such as quoting or escape sequences. A checksum is included so that common problems such as inadvertent deletions or typos can be caught without knowing the structure of the binary data.
To further reduce confusion, the values are prefixed with a tag intended to disambiguate usage. Although not necessary for correctness, developers and users may find it convenient to have a usage hint enabling them to see at a glance whether something is a transaction id or a ledger address, etc.
For example,
KEY~cHVibGljIGtleSBiaXRzBQ
TX~dHJhbnNhY3Rpb24gaWRlbnRpZmllciBnb2VzIGhlcmUC
Zg~Zgg
mytag~bXl0YWd7
Like the base64 value, the tag is also restricted to the URL-safe base64 character set.
Note: It is allowed for the tag to be the empty string. The base64 portion cannot be empty; at a minimum, it will encode a single byte checksum.
The tag and delimiter help to avoid problems with binary values that happen to parse as numbers. Large binary values don’t fit nicely into JavaScript numbers due to range and representation. JavaScript numbers are represented as 64-bit floating point numbers. This means that the largest unsigned integer that can be represented is 2^53 - 1. Moreover, it is very easy to accidentally coerce a string that looks like a number into a JavaScript number, thus running the risk of loss of precision, which is corruption. Therefore, values are encoded in base64 to allow safe transit to- and from JavaScript, including in URLs, as well as display and input in a user interface.
Structs§
- JavaScript-compatible wrapper for TaggedBase64
- A structure holding a string tag, vector of bytes, and a checksum covering the tag and the bytes.
Enums§
Constants§
- Base 64 engine configured for TaggedBase64.
- Separator that does not appear in URL-safe base64 encoding and can appear in URLs without percent-encoding.
Traits§
- Trait for types whose serialization is not human-readable.
Functions§
- Converts a TaggedBase64 value to a String.
Attribute Macros§
- Derive serdes for a type which serializes as a binary blob.