Skip to content

Commit 105d77a

Browse files
committed
set encoding before passing to hash function
This fixes: $ vault_from_gpg_agent.py --clear Traceback (most recent call last): File "/home/tpo/bin/vault_from_gpg_agent.py", line 88, in <module> main() File "/home/tpo/bin/vault_from_gpg_agent.py", line 79, in main hashed_path = base64.b64encode(hashlib.sha1(my_path).hexdigest()) TypeError: Unicode-objects must be encoded before hashing I do `my_path.encode('utf-8')` assuming (hoping) that `vault_from_gpg_agent.py`'s path on a system will not be changing over time with respect to encoding. That means `stat $my_path` will always return the same string with the same encoding. If that remains true then I think we can encode `my_path` as we wish, provided that utf-8 can hold all the characters that can occur in a filename...
1 parent 38cf8d5 commit 105d77a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

vault_from_gpg_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def main():
7272
my_path = os.path.realpath(sys.argv[0])
7373
# Per the source, cache-id is limited to 50 bytes, so we hash our
7474
# path and Base64 encode the path.
75-
hashed_path = base64.b64encode(hashlib.sha1(my_path).digest())
75+
hashed_path = base64.b64encode(hashlib.sha1(my_path.encode('utf-8')).digest())
7676
cache_id = "ansible-vault:%s" % (hashed_path,)
7777
if args.clear:
7878
clear_passphrase(gpg_agent, cache_id)

0 commit comments

Comments
 (0)