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

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

#2162 in Encoding

Download history 801/week @ 2024-07-26 827/week @ 2024-08-02 761/week @ 2024-08-09 528/week @ 2024-08-16 1475/week @ 2024-08-23 1043/week @ 2024-08-30 909/week @ 2024-09-06 774/week @ 2024-09-13 996/week @ 2024-09-20 830/week @ 2024-09-27 649/week @ 2024-10-04 744/week @ 2024-10-11 942/week @ 2024-10-18 913/week @ 2024-10-25 1116/week @ 2024-11-01 1031/week @ 2024-11-08

4,243 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

~2.7–6.5MB
~115K SLoC