Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom attributes on RemoteBoxFile #4

Closed
NotStatilko opened this issue Nov 20, 2021 · 2 comments
Closed

Custom attributes on RemoteBoxFile #4

NotStatilko opened this issue Nov 20, 2021 · 2 comments
Labels
team work Make it in team todo Non-critical things that we need to change

Comments

@NotStatilko
Copy link
Member

NotStatilko commented Nov 20, 2021

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?
  4. ;pubkey;sgn;signature; determines that this file was signed by pubkey.
  5. ...
@NotStatilko NotStatilko added enhancement New feature or request help wanted Extra attention is needed todo Non-critical things that we need to change labels Nov 20, 2021
@NotStatilko NotStatilko pinned this issue Dec 17, 2021
@NotStatilko NotStatilko changed the title Make a standart of RemoteBoxFile types Custom attributes on RemoteBoxFile Dec 18, 2021
@NotStatilko
Copy link
Member Author

NotStatilko commented Dec 18, 2021

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 NotStatilko added team work Make it in team and removed enhancement New feature or request help wanted Extra attention is needed labels Dec 18, 2021
@NotStatilko
Copy link
Member Author

NotStatilko commented Aug 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team work Make it in team todo Non-critical things that we need to change
Projects
None yet
Development

No branches or pull requests

1 participant