Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: xarfile.py

Issue 29354722: Issue 4459 - xarfile should not expect Crypto.Signature module to be present (Closed) Base URL: https://hg.adblockplus.org/buildtools
Patch Set: Created Sept. 22, 2016, 8:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import re 5 import re
6 import struct 6 import struct
7 import time 7 import time
8 import zlib 8 import zlib
9 9
10 from Crypto.Hash import SHA 10 from Crypto.Hash import SHA
11 from Crypto.PublicKey import RSA 11 from Crypto.PublicKey import RSA
12 from Crypto.Signature import PKCS1_v1_5
13 12
14 from buildtools.packager import getTemplate 13 from buildtools.packager import getTemplate
15 14
16 XAR_HEADER = struct.Struct('>IHHQQI') 15 XAR_HEADER = struct.Struct('>IHHQQI')
17 XAR_HEADER_MAGIC = 0x78617221 16 XAR_HEADER_MAGIC = 0x78617221
18 XAR_VERSION = 1 17 XAR_VERSION = 1
19 XAR_CKSUM_SHA1 = 1 18 XAR_CKSUM_SHA1 = 1
20 19
21 20
22 def read_certificates_and_key(keyfile): 21 def read_certificates_and_key(keyfile):
(...skipping 16 matching lines...) Expand all
39 38
40 def get_checksum(data): 39 def get_checksum(data):
41 return SHA.new(data).digest() 40 return SHA.new(data).digest()
42 41
43 42
44 def get_hexchecksum(data): 43 def get_hexchecksum(data):
45 return SHA.new(data).hexdigest() 44 return SHA.new(data).hexdigest()
46 45
47 46
48 def get_signature(key, data): 47 def get_signature(key, data):
48 from Crypto.Signature import PKCS1_v1_5
49
49 return PKCS1_v1_5.new(key).sign(SHA.new(data)) 50 return PKCS1_v1_5.new(key).sign(SHA.new(data))
50 51
51 52
52 def compress_files(filedata, root, offset): 53 def compress_files(filedata, root, offset):
53 compressed_data = [] 54 compressed_data = []
54 filedata = sorted(filedata.iteritems()) 55 filedata = sorted(filedata.iteritems())
55 directory_stack = [('', root)] 56 directory_stack = [('', root)]
56 file_id = 1 57 file_id = 1
57 for path, data in filedata: 58 for path, data in filedata:
58 # Remove directories that are done 59 # Remove directories that are done
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 len(toc_uncompressed), XAR_CKSUM_SHA1)) 132 len(toc_uncompressed), XAR_CKSUM_SHA1))
132 133
133 # It's followed up with a compressed XML table of contents 134 # It's followed up with a compressed XML table of contents
134 file.write(toc_compressed) 135 file.write(toc_compressed)
135 136
136 # Now the actual data, all the offsets are in the table of contents 137 # Now the actual data, all the offsets are in the table of contents
137 file.write(get_checksum(toc_compressed)) 138 file.write(get_checksum(toc_compressed))
138 file.write(get_signature(key, toc_compressed)) 139 file.write(get_signature(key, toc_compressed))
139 for blob in compressed_data: 140 for blob in compressed_data:
140 file.write(blob) 141 file.write(blob)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld