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

Allow keyfile to be passed as bytes #364

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

janbrummer
Copy link
Contributor

In order to prevent application to create temporary files, provide keyfile as bytes.

Fixes: #363

In order to prevent application to create temporary files,
provide keyfile as bytes.

Fixes: libkeepass#363
@janbrummer
Copy link
Contributor Author

@Evidlo May i ask you for a review?

assert hash == hash_computed, "Keyfile has invalid hash"
# otherwise, try to read plain keyfile
except (etree.XMLSyntaxError, UnicodeDecodeError):
if isinstance(keyfile, bytes):
Copy link
Contributor

Choose a reason for hiding this comment

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

See the save method, where it checks whether the file has hasattr(filename, "write") maybe the same could be done with the read attribute. BytesIO has this btw.

Copy link
Contributor Author

@janbrummer janbrummer Nov 1, 2023

Choose a reason for hiding this comment

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

In this case i'd need to change it from bytes to BytesIO. Not sure we want to enforce this in apps using pykeepass? No strong opinion here, up to the reviewers i guess.

@A6GibKm
Copy link
Contributor

A6GibKm commented Nov 27, 2023

Hello sorry to ping you @Evidlo. Is anything missing on your end?

@Evidlo
Copy link
Member

Evidlo commented Nov 27, 2023

Sorry for the late response.

I did a refactor which is a bit simpler than before, but it assumes that keyfile is a file-like object (such as BytesIO). Also I cleaned up tests a bit so BytesIO can be passed into the keyfiles list.

@Evidlo Evidlo merged commit efef0c4 into libkeepass:master Nov 28, 2023
0 of 6 checks passed
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.

Feature Request: Add option to provide keyfile as bytes
3 participants