python-pass icon indicating copy to clipboard operation
python-pass copied to clipboard

get_decrypted_password appends \n

Open trulex opened this issue 5 years ago • 4 comments

pw_store = pypass.PasswordStore()
password = pw_store.get_decrypted_password('[email protected]')

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

trulex avatar Aug 24 '20 12:08 trulex

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

aviau avatar Aug 24 '20 14:08 aviau

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().

prabi avatar Aug 24 '20 17:08 prabi

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 [email protected] and paste the output to a text editor, there's no new line. When I do pass [email protected], it looks like this

➜  ~ pass [email protected]   
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.

trulex avatar Aug 25 '20 04:08 trulex

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?

prabi avatar Aug 25 '20 18:08 prabi