Skip to content

signer: _from/_to_dict helpers for Key base fields#558

Merged
lukpueh merged 1 commit intosecure-systems-lab:mainfrom
lukpueh:base-de_serialization-helpers
Apr 14, 2023
Merged

signer: _from/_to_dict helpers for Key base fields#558
lukpueh merged 1 commit intosecure-systems-lab:mainfrom
lukpueh:base-de_serialization-helpers

Conversation

@lukpueh
Copy link
Copy Markdown
Member

@lukpueh lukpueh commented Mar 31, 2023

Add de/serialization helpers for common fields in the Key base class, which may be used in subclass from/to_dict methods for convenience.

  • _to_dict: This could be Key.to_dict, which subclasses default to, but we prefer that subclasses must implement a to_dict, to avoid unnoticed serialization errors.

  • _from_dict: Other than from_dict, this one does not create a Key instance, but just returns the popped off fields. This makes usage in subclasses more flexible and less mystical (lessons learned from theupdateframework/python-tuf@ace25e4).

Add de/serialization helpers for common fields in the Key base
class, which may be used in subclass from/to_dict methods for
convenience.

* _to_dict: This could be Key.to_dict, which subclasses default to,
but we prefer that subclasses must implement a to_dict, to avoid
unnoticed serialization errors.

* _from_dict: Other than from_dict, this one does not create a Key
instance, but just returns the popped off fields. This makes usage
in subclasses more flexible and less mystical.

Signed-off-by: Lukas Puehringer <[email protected]>
Copy link
Copy Markdown
Collaborator

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method naming is a bit suspicious maybe... but I've tried to come up with better suggestions for a week and came up with nothing so LGTM.

@lukpueh
Copy link
Copy Markdown
Member Author

lukpueh commented Apr 12, 2023

Method naming is a bit suspicious maybe... but I've tried to come up with better suggestions for a week and came up with nothing so LGTM.

In the TUF metadata API we call these _common_fields_(from,to)_dict. I didn't seem that much better to me.

@lukpueh lukpueh merged commit b1b14eb into secure-systems-lab:main Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants