#binary-data #base64 #user-interface #binary-encoding #data-encoding #tags #url-safe

bin+lib tagged-base64

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.

3 unstable releases

0.4.0 Mar 15, 2024
0.3.3 Jun 6, 2023
0.3.2 Jun 6, 2023

#4 in #url-safe

Download history 481/week @ 2024-06-17 729/week @ 2024-06-24 443/week @ 2024-07-01 410/week @ 2024-07-08 637/week @ 2024-07-15 1082/week @ 2024-07-22 740/week @ 2024-07-29 864/week @ 2024-08-05 683/week @ 2024-08-12 599/week @ 2024-08-19 1532/week @ 2024-08-26 1132/week @ 2024-09-02 911/week @ 2024-09-09 685/week @ 2024-09-16 947/week @ 2024-09-23 773/week @ 2024-09-30

3,420 downloads per month
Used in 3 crates (2 directly)

MIT license

27KB
308 lines

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.

Dependencies

~3.5–7MB
~133K SLoC