Commit db8ecb4a authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

mojo: Hash bytestrings for Python 3 compatibility

Python 3 only accepts bytes and bytestrings as input for hashing.
encode() so it works on both Python 2 and Python 3.

Traceback (most recent call last):
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 557, in <module>
    sys.exit(main())
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 552, in main
    return args.func(args, remaining_args)
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 268, in _Generate
    processor._GenerateModule(args, remaining_args, generator_modules,
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 213, in _GenerateModule
    ScrambleMethodOrdinals(module.interfaces, salt)
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 132, in ScrambleMethodOrdinals
    sha256.update(interface.mojom_name)
TypeError: Unicode-objects must be encoded before hashing

Bug: 941669
Change-Id: Icfb5d7b9762763b12c7795ac23261fb614eef014
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2044078Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#740204}
parent a9e375cf
...@@ -128,8 +128,8 @@ def ScrambleMethodOrdinals(interfaces, salt): ...@@ -128,8 +128,8 @@ def ScrambleMethodOrdinals(interfaces, salt):
# to guess the results without the secret salt, in order to make it # to guess the results without the secret salt, in order to make it
# harder for a compromised process to send fake Mojo messages. # harder for a compromised process to send fake Mojo messages.
sha256 = hashlib.sha256(salt) sha256 = hashlib.sha256(salt)
sha256.update(interface.mojom_name) sha256.update(interface.mojom_name.encode('utf-8'))
sha256.update(str(i)) sha256.update(str(i).encode('utf-8'))
# Take the first 4 bytes as a little-endian uint32. # Take the first 4 bytes as a little-endian uint32.
ordinal = struct.unpack('<L', sha256.digest()[:4])[0] ordinal = struct.unpack('<L', sha256.digest()[:4])[0]
# Trim to 31 bits, so it always fits into a Java (signed) int. # Trim to 31 bits, so it always fits into a Java (signed) int.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment