Index: tools/crx_id/crx_id.py |
diff --git a/tools/crx_id/crx_id.py b/tools/crx_id/crx_id.py |
index 5f8e2b227907fde1f204e14ef8f7ee696f9f695c..2bd13d70070baf070bf9c4e37145003193a009d7 100755 |
--- a/tools/crx_id/crx_id.py |
+++ b/tools/crx_id/crx_id.py |
@@ -75,7 +75,7 @@ def GetPublicKeyPacked(f): |
pub_key = f.read(pub_key_len_bytes) |
return pub_key |
-def GetPublicKeyFromPath(filepath): |
+def GetPublicKeyFromPath(filepath, encode_path_for_windows=False): |
# Normalize the path for windows to have capital drive letters. |
# We intentionally don't check if sys.platform == 'win32' and just |
# check if this looks like drive letter so that we can test this |
@@ -83,7 +83,15 @@ def GetPublicKeyFromPath(filepath): |
if (len(filepath) >= 2 and |
filepath[0].islower() and |
filepath[1] == ':'): |
- return filepath[0].upper() + filepath[1:] |
+ filepath = filepath[0].upper() + filepath[1:] |
+ |
+ # On Windows, filepaths are encoded using UTF-16, little endian byte order, |
+ # using "wide characters" that are 16 bits in size. On POSIX systems, the |
+ # encoding is generally UTF-8, which has the property of being equivalent to |
+ # ASCII when only ASCII characters are in the path. |
+ if encode_path_for_windows: |
+ filepath = filepath.encode('utf-16le') |
+ |
return filepath |
def GetPublicKeyUnpacked(f, filepath): |
@@ -102,9 +110,10 @@ def HasPublicKey(filename): |
return 'key' in manifest |
return False |
-def GetPublicKey(filename, from_file_path): |
+def GetPublicKey(filename, from_file_path, encode_path_for_windows=False): |
achuithb
2013/06/04 18:33:29
encode_path_for_windows seems overly verbose. is_w
Tim Song
2013/06/05 18:36:27
Done.
|
if from_file_path: |
- return GetPublicKeyFromPath(filename) |
+ return GetPublicKeyFromPath( |
+ filename, encode_path_for_windows=encode_path_for_windows) |
pub_key = '' |
if os.path.isdir(filename): |
@@ -119,13 +128,15 @@ def GetPublicKey(filename, from_file_path): |
f.close() |
return pub_key |
-def GetCRXHash(filename, from_file_path=False): |
- pub_key = GetPublicKey(filename, from_file_path) |
+def GetCRXHash(filename, from_file_path=False, encode_path_for_windows=False): |
+ pub_key = GetPublicKey(filename, from_file_path, |
+ encode_path_for_windows=encode_path_for_windows) |
pub_key_hash = hashlib.sha256(pub_key).digest() |
return HexTo256(pub_key_hash) |
-def GetCRXAppID(filename, from_file_path=False): |
- pub_key = GetPublicKey(filename, from_file_path) |
+def GetCRXAppID(filename, from_file_path=False, encode_path_for_windows=False): |
+ pub_key = GetPublicKey(filename, from_file_path, |
+ encode_path_for_windows=encode_path_for_windows) |
pub_key_hash = hashlib.sha256(pub_key).digest() |
# AppID is the MPDecimal of only the first 128 bits of the hash. |
return HexToMPDecimal(pub_key_hash[:128/8]) |