aviau / python-pass

For fun - I have decided to write pass in python
http://aviau.github.io/python-pass/
GNU General Public License v3.0
36 stars 17 forks source link

get_decrypted_password appends \n #29

Open trulex opened 3 years ago

trulex commented 3 years ago
pw_store = pypass.PasswordStore()
password = pw_store.get_decrypted_password('name@example.com')

Expected value of password variable would be, e.g., password1234, but instead a \n is appended, so the actual value is password1234\n.

aviau commented 3 years ago

Did you compare it with pass? Does pass append a newline?

Maybe we need to print the newline in shells but not return it with the get_decrypted_password method

prabi commented 3 years ago

PasswordStore.get_decrypted_password() has a little bit misleading name, because as its doc string sugests, it returns the full decrypted content of the requested entry (.gpg file). It only returns a newline character at the end of the string, if the file contained one.

As long as you use the pypass API to create the entry, you won't be getting a newline at the end.

If pass or other tools added an undesired \n, you can always get rid of it with str.strip().

trulex commented 3 years ago

Did you compare it with pass? Does pass append a newline?

Maybe we need to print the newline in shells but not return it with the get_decrypted_password method

When I do pass -c name@example.com and paste the output to a text editor, there's no new line. When I do pass name@example.com, it looks like this

➜  ~ pass name@example.com   
password1234
➜  ~ 

So I would expect that get_decrypted_password() works in the same manner as pass -c, since the password that was inserted, did not contain a new line.

If pass or other tools added an undesired \n, you can always get rid of it with str.strip().

I'm using some workaround at the moment, but it feels like there a bug either in pypass or in pass.

prabi commented 3 years ago

Maybe we should merge this issue with #5 and make get_decrypted_password() return some Password object instead of an str.

It could have a password field that would contain the decoded first line without any disturbing newlines, and a content field with the full unaltered content. Also other fields already handled by the current implementation to not lose functionality.

Is this proposal a satisfactory solution to this issue? Any suggestions?