sseemayer / keepass-rs

Rust KeePass database file parser for KDB, KDBX3 and KDBX4, with experimental support for KDBX4 writing.
https://docs.rs/keepass
MIT License
116 stars 39 forks source link

FR: Better ergonomics in structs? #159

Open max-ishere opened 1 year ago

max-ishere commented 1 year ago

Here is what I expected an entry to look like. Imo it's better.

Entry {
    pub title: String,
    pub username: String,
    pub password: String,
    // ...
}

My expectation comes seeing it this way in a GUI. Another reason is that renaming a string key is not a good idea.

This would require adding custom serde code tho..

max-ishere commented 1 year ago

Just to be clear I wanted to get some feedback to know if this is something I should try to implement.

sseemayer commented 1 year ago

Sorry for the late reply. I agree from a usability perspective.

Right now, the crate more closely follows the format of the XML file that is inside of every KeePass database, where there can be arbitrary key-value pairs called fields, and username, title and password are just special cases. Handling fields as a HashMap<String, Value> simplifies the parsing and writing code.

We provide the Entry::get_username and other convenience functions to retrieve the most important field values.

I'm not sure if you were referring to our feature-gated serde support when you were talking about custom serde code. I would be willing to accept a PR that has a custom impl Serialize for Entry which generates more intuitive JSON output.

max-ishere commented 1 year ago

Hi, thanks for the reply. The custom serde code is the implementation of deserialize that puts specific xml keys into a struct