file-transfer-protocol.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. File transfer over the TTY
  2. ===============================
  3. There are sometimes situations where the TTY is the only convenient pipe
  4. between two connected systems, for example, nested SSH sessions, a serial
  5. line, etc. In such scenarios, it is useful to be able to transfer files
  6. over the TTY.
  7. This protocol provides the ability to transfer regular files, directories and
  8. links (both symbolic and hard) preserving most of their metadata. It can
  9. optionally use compression and transmit only binary diffs to speed up
  10. transfers. However, since all data is base64 encoded for transmission over the
  11. TTY, this protocol will never be competitive with more direct file transfer
  12. mechanisms.
  13. Overall design
  14. ----------------
  15. The basic design of this protocol is around transfer "sessions". Since
  16. untrusted software should not be able to read/write to another machines
  17. filesystem, a session must be approved by the user in the terminal emulator
  18. before any actual data is transmitted, unless a :ref:`pre-shared password is
  19. provided <bypass_auth>`.
  20. There can be either send or receive sessions. In send sessions files are sent
  21. from remote client to the terminal emulator and vice versa for receive sessions.
  22. Every session basically consists of sending metadata for the files first and
  23. then sending the actual data. The session is a series of commands, every command
  24. carrying the session id (which should be a random unique-ish identifier, to
  25. avoid conflicts). The session is bi-directional with commands going both to and
  26. from the terminal emulator. Every command in a session also carries an
  27. ``action`` field that specifies what the command does. The remaining fields in
  28. the command are dependent on the nature of the command.
  29. Let's look at some simple examples of sessions to get a feel for the protocol.
  30. Sending files to the computer running the terminal emulator
  31. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  32. The client starts by sending a start send command::
  33. → action=send id=someid
  34. It then waits for a status message from the terminal either
  35. allowing the transfer or refusing it. Until this message is received
  36. the client is not allowed to send any more commands for the session.
  37. The terminal emulator should drop a session if it receives any commands
  38. before sending an ``OK`` response. If the user accepts the transfer,
  39. the terminal will send::
  40. ← action=status id=someid status=OK
  41. Or if the transfer is refused::
  42. ← action=status id=someid status=EPERM:User refused the transfer
  43. The client then sends one or more ``file`` commands with the metadata of the file it wants
  44. to transfer::
  45. → action=file id=someid file_id=f1 name=/path/to/destination
  46. → action=file id=someid file_id=f2 name=/path/to/destination2 ftype=directory
  47. The terminal responds with either ``OK`` for directories or ``STARTED`` for
  48. files::
  49. ← action=status id=someid file_id=f1 status=STARTED
  50. ← action=status id=someid file_id=f2 status=OK
  51. If there was an error with the file, for example, if the terminal does not have
  52. permission to write to the specified location, it will instead respond with an
  53. error, such as::
  54. ← action=status id=someid file_id=f1 status=EPERM:No permission
  55. The client sends data for files using ``data`` commands. It does not need to
  56. wait for the ``STARTED`` from the terminal for this, the terminal must discard data
  57. for files that are not ``STARTED``. Data for a file is sent in individual
  58. chunks of no larger than ``4096`` bytes. For example::
  59. → action=data id=someid file_id=f1 data=chunk of bytes
  60. → action=data id=someid file_id=f1 data=chunk of bytes
  61. ...
  62. → action=end_data id=someid file_id=f1 data=chunk of bytes
  63. The sequence of data transmission for a file is ended with an ``end_data``
  64. command. After each data packet is received the terminal replies with
  65. an acknowledgement of the form::
  66. ← action=status id=someid file_id=f1 status=PROGRESS size=bytes written
  67. After ``end_data`` the terminal replies with::
  68. ← action=status id=someid file_id=f1 status=OK size=bytes written
  69. If an error occurs while writing the data, the terminal replies with an error
  70. code and ignores further commands about that file, for example::
  71. ← action=status id=someid file_id=f1 status=EIO:Failed to write to file
  72. Once the client has finished sending as many files as it wants to, it ends
  73. the session with::
  74. → action=finish id=someid
  75. At this point the terminal commits the session, applying file metadata,
  76. creating links, etc. If any errors occur it responds with an error message,
  77. such as::
  78. ← action=status id=someid status=Some error occurred
  79. Receiving files from the computer running terminal emulator
  80. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  81. The client starts by sending a start receive command::
  82. → action=receive id=someid size=num_of_paths
  83. It then sends a list of ``num_of_paths`` paths it is interested in
  84. receiving::
  85. → action=file id=someid file_id=f1 name=/some/path
  86. → action=file id=someid file_id=f2 name=/some/path2
  87. ...
  88. The client must then wait for responses from the terminal emulator. It
  89. is an error to send anymore commands to the terminal until an ``OK``
  90. response is received from the terminal. The terminal wait for the user to accept
  91. the request. If accepted, it sends::
  92. ← action=status id=someid status=OK
  93. If permission is denied it sends::
  94. ← action=status id=someid status=EPERM:User refused the transfer
  95. The terminal then sends the metadata for all requested files. If any of them
  96. are directories, it traverses the directories recursively, listing all files.
  97. Note that symlinks must not be followed, but sent as symlinks::
  98. ← action=file id=someid file_id=f1 mtime=XXX permissions=XXX name=/absolute/path status=file_id1 size=size_in_bytes file_type=type parent=file_id of parent
  99. ← action=file id=someid file_id=f1 mtime=XXX permissions=XXX name=/absolute/path2 status=file_id2 size=size_in_bytes file_type=type parent=file_id of parent
  100. ...
  101. Here the ``file_id`` field is set to the ``file_id`` value sent from the client
  102. and the ``status`` field is set to the actual file id for each file. This is
  103. because a file query sent from the client can result in multiple actual files if
  104. it is a directory. The ``parent`` field is the actual ``file_id`` of the directory
  105. containing this file and is set for entries that are generated from client
  106. requests that match directories. This allows the client to build an unambiguous picture
  107. of the file tree.
  108. Once all the files are listed, the terminal sends an ``OK`` response that also
  109. specifies the absolute path to the home directory for the user account running
  110. the terminal::
  111. ← action=status id=someid status=OK name=/path/to/home
  112. If an error occurs while listing any of the files asked for by the client,
  113. the terminal will send an error response like::
  114. ← action=status id=someid file_id=f1 status=ENOENT: Does not exist
  115. Here, ``file_id`` is the same as was sent by the client in its initial query.
  116. Now, the client can send requests for file data using the paths sent by the
  117. terminal emulator::
  118. → action=file id=someid file_id=f1 name=/some/path
  119. ...
  120. The client must not send requests for directories and absolute symlinks.
  121. The terminal emulator replies with the data for the files, as a sequence of
  122. ``data`` commands each with a chunk of data no larger than ``4096`` bytes,
  123. for each file (the terminal emulator must send the data for
  124. one file at a time)::
  125. ← action=data id=someid file_id=f1 data=chunk of bytes
  126. ...
  127. ← action=end_data id=someid file_id=f1 data=chunk of bytes
  128. If any errors occur reading file data, the terminal emulator sends an error
  129. message for the file, for example::
  130. ← action=status id=someid file_id=f1 status=EIO:Could not read
  131. Once the client is done reading data for all the files it expects, it
  132. terminates the session with::
  133. → action=finished id=someid
  134. Canceling a session
  135. ----------------------
  136. A client can decide to cancel a session at any time (for example if the user
  137. presses :kbd:`ctrl+c`). To cancel a session it sends a ``cancel`` action to the
  138. terminal emulator::
  139. → action=cancel id=someid
  140. The terminal emulator drops the session and sends a cancel acknowledgement::
  141. ← action=status id=someid status=CANCELED
  142. The client **must** wait for the canceled response from the emulator discarding
  143. any other responses till the cancel is received. If it does not wait, after
  144. it quits the responses might end up being printed to screen.
  145. Quieting responses from the terminal
  146. -------------------------------------
  147. The above protocol includes lots of messages from the terminal acknowledging
  148. receipt of data, granting permission etc., acknowledging cancel requests, etc.
  149. For extremely simple clients like shell scripts, it might be useful to suppress
  150. these responses, which can be done by adding the ``quiet`` key to the start
  151. session command::
  152. → action=send id=someid quiet=1
  153. The key can take the values ``1`` - meaning suppress acknowledgement responses
  154. or ``2`` - meaning suppress all responses including errors. Only actual data
  155. responses are sent. Note that in particular this means acknowledgement of
  156. permission for the transfer to go ahead is suppressed, so this is typically
  157. useful only with :ref:`bypass_auth`.
  158. .. _file_metadata:
  159. File metadata
  160. -----------------
  161. File metadata includes file paths, permissions and modification times. They are
  162. somewhat tricky as different operating systems support different kinds of
  163. metadata. This specification defines a common minimum set which should work
  164. across most operating systems.
  165. File paths
  166. File paths must be valid UTF-8 encoded POSIX paths (i.e. using the forward slash
  167. ``/`` as a separator). Linux systems allow non UTF-8 file paths, these
  168. are not supported. A leading ``~/`` means a path is relative to the
  169. ``HOME`` directory. All path must be either absolute (i.e. with a leading
  170. ``/``) or relative to the HOME directory. Individual components of the
  171. path must be no longer than 255 UTF-8 bytes. Total path length must be no
  172. more than 4096 bytes. Paths from Windows systems must use the forward slash
  173. as the separator, the first path component must be the drive letter with a
  174. colon. For example: :file:`C:\\some\\file.txt` is represented as
  175. :file:`/C:/some/file.txt`. For maximum portability, the following
  176. characters *should* be omitted from paths (however implementations are free
  177. to try to support them returning errors for non-representable paths)::
  178. \ * : < > ? | /
  179. File modification times
  180. Must be represented as the number of nanoseconds since the UNIX epoch. An
  181. individual file system may not store file metadata with this level of
  182. accuracy in which case it should use the closest possible approximation.
  183. File permissions
  184. Represented as a number with the usual UNIX read, write and execute bits.
  185. In addition, the sticky, set-group-id and set-user-id bits may be present.
  186. Implementations should make a best effort to preserve as many bits as
  187. possible. On Windows, there is only a read-only bit. When reading file
  188. metadata all the ``WRITE`` bits should be set if the read only bit is clear
  189. and cleared if it is set. When writing files, the read-only bit should be
  190. set if the bit indicating write permission for the user is clear. The other
  191. UNIX bits must be ignored when writing. When reading, all the ``READ`` bits
  192. should always be set and all the ``EXECUTE`` bits should be set if the file is
  193. directly executable by the Windows Operating system. There is no attempt to
  194. map Window's ACLs to permission bits.
  195. Symbolic and hard links
  196. ---------------------------
  197. Symbolic and hard links can be preserved by this protocol.
  198. .. note::
  199. In the following when target paths of symlinks are sent as actual paths, they must be
  200. encoded in the same way as discussed in :ref:`file_metadata`. It is up to
  201. the receiving side to translate them into appropriate paths for the local
  202. operating system. This may not always be possible, in which case either the
  203. symlink should not be created or a broken symlink should be created.
  204. Sending links to the terminal emulator
  205. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  206. When sending files to the terminal emulator, the file command has the form::
  207. → action=file id=someid file_id=f1 name=/path/to/link file_type=link
  208. → action=file id=someid file_id=f2 name=/path/to/symlink file_type=symlink
  209. Then, when the client is sending data for the files, for hardlinks, the data
  210. will be the ``file_id`` of the target file (assuming the target file is also
  211. being transmitted, otherwise the hard link should be transmitted as a plain
  212. file)::
  213. → action=end_data id=someid file_id=f1 data=target_file_id_encoded_as_utf8
  214. For symbolic links, the data is a little more complex. If the symbolic link is
  215. to a destination being transmitted, the data has the form::
  216. → action=end_data id=someid file_id=f1 data=fid:target_file_id_encoded_as_utf8
  217. → action=end_data id=someid file_id=f1 data=fid_abs:target_file_id_encoded_as_utf8
  218. The ``fid_abs`` form is used if the symlink uses an absolute path, ``fid`` if
  219. it uses a relative path. If the symlink is to a destination that is not being
  220. transmitted, then the prefix ``path:`` and the actual path in the symlink is
  221. transmitted.
  222. Receiving links from the terminal emulator
  223. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  224. When receiving files from the terminal emulator, link data is transmitted in
  225. two parts. First when the emulator sends the initial file listing to the
  226. client, the ``file_type`` is set to the link type and the ``data`` field is set
  227. to file_id of the target file if the target file is included in the listing.
  228. For example::
  229. ← action=file id=someid file_id=f1 status=file_id1 ...
  230. ← action=file id=someid file_id=f1 status=file_id2 file_type=symlink data=file_id1 ...
  231. Here the rest of the metadata has been left out for clarity. Notice that the
  232. second file is symlink whose ``data`` field is set to the file id of the first
  233. file (the value of the ``status`` field of the first file). The same technique
  234. is used for hard links.
  235. The client should not request data for hard links, instead creating them
  236. directly after transmission is complete. For symbolic links the terminal
  237. must send the actual symbolic link target as a UTF-8 encoded path in the
  238. data field. The client can use this path either as-is (when the target is not
  239. a transmitted file) or to decide whether to create the symlink with a relative
  240. or absolute path when the target is a transmitted file.
  241. Transmitting binary deltas
  242. -----------------------------
  243. Repeated transfer of large files that have only changed a little between
  244. the receiving and sending side can be sped up significantly by transmitting
  245. binary deltas of only the changed portions. This protocol has built-in support
  246. for doing that. This support uses the `rsync algorithm
  247. <https://rsync.samba.org/tech_report/tech_report.html>`__. In this algorithm, first the
  248. receiving side sends a file signature that contains hashes of blocks
  249. in the file. Then the sending side sends only those blocks that have changed.
  250. The receiving side applies these deltas to the file to update it till it matches
  251. the file on the sending side.
  252. The modification to the basic protocol consists of setting the
  253. ``transmission_type`` key to ``rsync`` when requesting a file. This triggers
  254. transmission of signatures and deltas instead of file data. The details are
  255. different for sending and receiving.
  256. Sending to the terminal emulator
  257. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  258. When sending the metadata of the file it wants to transfer, the client adds the
  259. ``transmission_type`` key::
  260. → action=file id=someid file_id=f1 name=/path/to/destination transmission_type=rsync
  261. The ``STARTED`` response from the terminal will have ``transmission_type`` set
  262. to ``rsync`` if the file exists and the terminal is able to send signature data::
  263. ← action=status id=someid file_id=f1 status=STARTED transmission_type=rsync
  264. The terminal then transmits the signature using ``data`` commands::
  265. ← action=data id=someid file_id=f1 data=...
  266. ...
  267. ← action=end_data id=someid file_id=f1 data=...
  268. Once the client receives and processes the full signature, it transmits the
  269. file delta to the terminal as ``data`` commands::
  270. → action=data id=someid file_id=f1 data=...
  271. → action=data id=someid file_id=f1 data=...
  272. ...
  273. → action=end_data id=someid file_id=f1 data=...
  274. The terminal then uses this delta to update the file.
  275. Receiving from the terminal emulator
  276. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  277. When the client requests file data from the terminal emulator, it can
  278. add the ``transmission_type=rsync`` key to indicate it will be sending
  279. a signature for that file::
  280. → action=file id=someid file_id=f1 name=/some/path transmission_type=rsync
  281. The client then sends the signature using ``data`` commands::
  282. → action=data id=someid file_id=f1 data=...
  283. ...
  284. → action=end_data id=someid file_id=f1 data=...
  285. After receiving the signature the terminal replies with the delta as a series
  286. of ``data`` commands::
  287. ← action=data id=someid file_id=f1 data=...
  288. ...
  289. ← action=end_data id=someid file_id=f1 data=...
  290. The client then uses this delta to update the file.
  291. The format of signatures and deltas
  292. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  293. In what follows, all integers must be encoded in little-endian format,
  294. regardless of the architecture of the machines involved. The XXH3 hash family
  295. refers to `the xxHash algorithm
  296. <https://github.com/Cyan4973/xxHash/blob/dev/doc/xxhash_spec.md>`__.
  297. A signature first has a 12 byte header of the form:
  298. .. code::
  299. uint16 version
  300. uint16 checksum_type
  301. uint16 strong_hash_type
  302. uint16 weak_hash_type
  303. uint32 block_size
  304. These fields define the parameters to the rsync algorithm. Allowed values are
  305. currently all zero except for ``block_size``, which is usually the square root
  306. of the file size, but implementations are free to use any algorithm they like
  307. to arrive at the block size.
  308. ``checksum_type`` must be ``0`` which indicates using the XXH3-128 bit hash
  309. to verify file integrity after transmission.
  310. ``strong_hash_type`` must be ``0`` which indicates using the XXH3-64 bit hash
  311. to identify blocks.
  312. ``weak_hash_type`` must be ``0`` which indicates using the `rsync rolling
  313. checksum hash <https://rsync.samba.org/tech_report/node3.html>`__ to identify
  314. blocks, weakly.
  315. After the header comes the list of block signatures. The number of blocks is
  316. unknown allowing for streaming, the transfer protocol takes care of indicating
  317. end-of-stream via an ``action=end_data`` packet. Each signature in the list is of the form:
  318. .. code::
  319. uint64 index
  320. uint32 weak_hash
  321. uint64 strong_hash
  322. Here, ``index`` is the zero-based block number. ``weak_hash`` is the weak, but easy
  323. to calculate hash of the block and strong hash is a stronger hash of the block
  324. that is very unlikely to collide.
  325. The algorithms used for these hashes are specified by the signature header
  326. above. Given the ``block_size`` from the header and ``index`` the position of a
  327. block in the file is: ``index * block_size``.
  328. Once the sending side receives the signature, it calculates a *delta* based on
  329. the actual file contents and transmits that delta to the receiving side. The delta
  330. is of the form of a list of *operations*. An operation is a single byte
  331. denoting the operation type followed by variable length data depending on the
  332. type. The types of operations are:
  333. ``Block (type=0)``
  334. Followed by an 8 byte ``uint64`` that is the block index. It means copy the
  335. specified block from the existing file to the output, unmodified.
  336. ``Data (type=1)``
  337. Followed by a 4 byte ``uint32`` that is the size of the payload and then the
  338. payload itself. The payload must be written to the output.
  339. ``Hash (type=2)``
  340. Followed by a 2 byte ``uint16`` specifying the size of the hash checksum and
  341. then the checksum itself. The checksum of the output file must match this
  342. checksum. The algorithm used to calculate the checksum is specified in the
  343. signature header.
  344. ``BlockRange (type=3)``
  345. Followed by an 8 byte ``uint64`` that is the starting block index and then
  346. a 4 byte ``uint32`` (``N``) that is the number of additional blocks. Works just
  347. like ``Block`` above, except that after copying the block an additional (``N``) more
  348. blocks must be copied.
  349. Compression
  350. --------------
  351. Individual files can be transmitted compressed if needed.
  352. Currently, only :rfc:`1950` ZLIB based deflate compression is
  353. supported, which is specified using the ``compression=zlib`` key when
  354. requesting a file. For example when sending files to the terminal emulator,
  355. when sending the file metadata the ``compression`` key can also be
  356. specified::
  357. → action=file id=someid file_id=f1 name=/path/to/destination compression=zlib
  358. Similarly when receiving files from the terminal emulator, the final file
  359. command that the client sends to the terminal requesting the start of the
  360. transfer of data for the file can include the ``compression`` key::
  361. → action=file id=someid file_id=f1 name=/some/path compression=zlib
  362. .. _bypass_auth:
  363. Bypassing explicit user authorization
  364. ------------------------------------------
  365. In order to bypass the requirement of interactive user authentication,
  366. this protocol has the ability to use a pre-shared secret (password).
  367. When initiating a transfer session the client sends a hash of the password and
  368. the session id::
  369. → action=send id=someid bypass=sha256:hash_value
  370. For example, suppose that the session id is ``mysession`` and the
  371. shared secret is ``mypassword``. Then the value of the ``bypass``
  372. key above is ``sha256:SHA256("mysession" + ";" + "mypassword")``, which
  373. is::
  374. → action=send id=mysession bypass=sha256:192bd215915eeaa8c2b2a4c0f8f851826497d12b30036d8b5b1b4fc4411caf2c
  375. The value of ``bypass`` is of the form ``hash_function_name : hash_value``
  376. (without spaces). Currently, only the SHA256 hash function is supported.
  377. .. warning::
  378. Hashing does not effectively hide the value of the password. So this
  379. functionality should only be used in secure/trusted contexts. While there
  380. exist hash functions harder to compute than SHA256, they are unsuitable as
  381. they will introduce a lot of latency to starting a session and in any case
  382. there is no mathematical proof that **any** hash function is not brute-forceable.
  383. Terminal implementations are free to use their own more advanced hashing
  384. schemes, with prefixes other than those starting with ``sha``, which are
  385. reserved. For instance, kitty uses a scheme based on public key encryption
  386. via :envvar:`KITTY_PUBLIC_KEY`. For details of this scheme, see the
  387. ``check_bypass()`` function in the kitty source code.
  388. Encoding of transfer commands as escape codes
  389. ------------------------------------------------
  390. Transfer commands are encoded as ``OSC`` escape codes of the form::
  391. <OSC> 5113 ; key=value ; key=value ... <ST>
  392. Here ``OSC`` is the bytes ``0x1b 0x5d`` and ``ST`` is the bytes
  393. ``0x1b 0x5c``. Keys are words containing only the characters ``[a-zA-Z0-9_]``
  394. and ``value`` is arbitrary data, whose encoding is dependent on the value of
  395. ``key``. Unknown keys **must** be ignored when decoding a command.
  396. The number ``5113`` is a constant and is unused by any known OSC codes. It is
  397. the numeralization of the word ``file``.
  398. .. table:: The keys and value types for this protocol
  399. :align: left
  400. ================= ======== ============== =======================================================================
  401. Key Key name Value type Notes
  402. ================= ======== ============== =======================================================================
  403. action ac enum send, file, data, end_data, receive, cancel, status, finish
  404. compression zip enum none, zlib
  405. file_type ft enum regular, directory, symlink, link
  406. transmission_type tt enum simple, rsync
  407. id id safe_string A unique-ish value, to avoid collisions
  408. file_id fid safe_string Must be unique per file in a session
  409. bypass pw safe_string hash of the bypass password and the session id
  410. quiet q integer 0 - verbose, 1 - only errors, 2 - totally silent
  411. mtime mod integer the modification time of file in nanoseconds since the UNIX epoch
  412. permissions prm integer the UNIX file permissions bits
  413. size sz integer size in bytes
  414. name n base64_string The path to a file
  415. status st base64_string Status messages
  416. parent pr safe_string The file id of the parent directory
  417. data d base64_bytes Binary data
  418. ================= ======== ============== =======================================================================
  419. The ``Key name`` is the actual serialized name of the key sent in the escape
  420. code. So for example, ``permissions=123`` is serialized as ``prm=123``. This
  421. is done to reduce overhead.
  422. The value types are:
  423. enum
  424. One from a permitted set of values, for example::
  425. ac=file
  426. safe_string
  427. A string consisting only of characters from the set ``[0-9a-zA-Z_:./@-]``
  428. Note that the semi-colon is missing from this set.
  429. integer
  430. A base-10 number composed of the characters ``[0-9]`` with a possible
  431. leading ``-`` sign. When missing the value is zero.
  432. base64_string
  433. A base64 encoded UTF-8 string using the standard base64 encoding
  434. base64_bytes
  435. Binary data encoded using the standard base64 encoding
  436. An example of serializing an escape code is shown below::
  437. action=send id=test name=somefile size=3 data=01 02 03
  438. becomes::
  439. <OSC> 5113 ; ac=send ; id=test ; n=c29tZWZpbGU= ; sz=3 ; d=AQID <ST>
  440. Here ``c29tZWZpbGU`` is the base64 encoded form of somefile and ``AQID`` is the
  441. base64 encoded form of the bytes ``0x01 0x02 0x03``. The spaces in the encoded
  442. form are present for clarity and should be ignored.