NonProjects / tgbox

Encrypted cloud storage Protocol based on Telegram
https://tgbox.readthedocs.io/
GNU Lesser General Public License v2.1
35 stars 4 forks source link

Custom attributes on RemoteBoxFile #4

Closed NotStatilko closed 2 years ago

NotStatilko commented 2 years ago

We have a 255-byte field called comment. I suggest to use it for determining file types.

My thoughts about this:

  1. ;msg; determines that this file is Text-message;
  2. ;rep;5; determines that this file is Reply to another file with ID=5;
  3. ;1;alb;{alb_id}; determines that this file is part of Album. 1 here is order. alb_id is unique Album ID. Maybe 4 random bytes?
    1. ;pubkey;sgn;signature; determines that this file was signed by pubkey.
    2. ...
NotStatilko commented 2 years ago

comment will be used for custom file attributes & types, so every developer may add own.

I suggest this standard:

  1. If comment is custom attributes, it must start from the one 0xFF byte. Otherwise this field will be determined as plain comment.
  2. Every custom attribute must have the Key and the Value, like dict(). Value can be b''.

As delimeters we may use length of Key (not to be confused with keys.Key) and the length of Value. I.e we want to add to the RemoteBoxFile custom attribute key with value value. Then:

comment = b'\xff\x03key\x05value'

  1. We take \x03, convert it to int (3) and take three next bytes, receive Key;
  2. Take next byte from Key, convert it to int (5) and take next five bytes, receive Value;
  3. Repeat until bytestring will be empty.

So, for example, we may use this to store file hash or signatures, or whatever. We can also use this to determine file types, if needed. Let's use type as Key.

Types can be combined, but there is limit in 255 bytes.

Example:

from tgbox.tools import CustomAttributes

# Some random types
cattr = CustomAttributes.make(
    sha256 = b'\x00'*32,
    never  = b'gonna give you up'
)
# Defining text message type
cattr = CustomAttributes.make(
    type = b'message'
)

Further will be list of types. You may suggest your own, if interested.

Key Value Description
sha256 hash May be used any hashfunc from hashlib
reply message.id Reply to the ID
type b'message' Text message type, can be another Value
NotStatilko commented 2 years ago

The CustomAttributes is now a PackedAttributes. This algorithm is used now for packing metadata attrs. comment attribute of prepare_file(...) is now replaced by a cattrs, user can present a dict with custom file attributes he wants, so all of the previous information on this issue isn't actual as per v1.0.

See new metadata: https://tgbox.readthedocs.io/en/latest/remotebox.html#remoteboxfile See new cattrs attr: https://tgbox.readthedocs.io/en/latest/tgbox.html?highlight=prepare_file#tgbox.api.DecryptedLocalBox.prepare_file

Still, i want to make a standart for cattrs keys that different apps based on tgbox can share. Like "comment" key to define a file commentary or "type" to define a file type, e.g with a "message" value or even "sha256" / "md5" / "sha1" ... to define a file hash. You can propose your ideas here.