chiark / gitweb /
Include SHA-256 hash in addition to MD5
authorHenrik Tunedal <tunedal@gmail.com>
Wed, 16 Mar 2011 23:27:42 +0000 (00:27 +0100)
committerHenrik Tunedal <tunedal@gmail.com>
Fri, 18 Mar 2011 18:18:13 +0000 (19:18 +0100)
The MD5 hash element must come last, for compatibility with older
clients.

update.py

index fe18354b581d0f1f83ed0fbba8a758492bab9ed7..c3c106d7d76a1b182b24043601fdc6ea1d18c438 100755 (executable)
--- a/update.py
+++ b/update.py
@@ -24,7 +24,7 @@ import glob
 import subprocess
 import re
 import zipfile
-import md5
+import hashlib
 from xml.dom.minidom import Document
 from optparse import OptionParser
 
@@ -139,15 +139,18 @@ for apkfile in glob.glob(os.path.join('repo','*.apk')):
         print "  WARNING: no SDK version information found"
         thisinfo['sdkversion'] = 0
 
-    # Calculate the md5...
-    m = md5.new()
+    # Calculate the md5 and sha256...
+    m = hashlib.md5()
+    sha = hashlib.sha256()
     f = open(apkfile, 'rb')
     while True:
         t = f.read(1024)
         if len(t) == 0:
             break
         m.update(t)
+        sha.update(t)
     thisinfo['md5'] = m.hexdigest()
+    thisinfo['sha256'] = sha.hexdigest()
     f.close()
 
     # Get the signature (or md5 of, to be precise)...
@@ -303,7 +306,13 @@ for app in apps:
                 addElement('apkname', apk['apkname'], doc, apkel)
                 if apk.has_key('srcname'):
                     addElement('srcname', apk['srcname'], doc, apkel)
-                addElement('hash', apk['md5'], doc, apkel)
+                for hash_type in ('sha256', 'md5'):
+                    if not hash_type in apk:
+                        continue
+                    hashel = doc.createElement("hash")
+                    hashel.setAttribute("type", hash_type)
+                    hashel.appendChild(doc.createTextNode(apk[hash_type]))
+                    apkel.appendChild(hashel)
                 addElement('sig', apk['sig'], doc, apkel)
                 addElement('size', str(apk['size']), doc, apkel)
                 addElement('sdkver', str(apk['sdkversion']), doc, apkel)