Bug 1754098 - run mochitest as -no-fission. r=releng-reviewers,ahal
[gecko.git] / security / apps / gen_cert_header.py
blob6065b98b83263104876a788929800215d79c8b42
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
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 def _file_byte_generator(filename):
7 with open(filename, "rb") as f:
8 contents = f.read()
10 # Treat empty files the same as a file containing a lone 0;
11 # a single-element array will fail cert verifcation just as an
12 # empty array would.
13 if not contents:
14 return ["\0"]
16 return contents
19 def _create_header(array_name, cert_bytes):
20 hexified = ["0x%02x" % byte for byte in cert_bytes]
22 substs = {"array_name": array_name, "bytes": ", ".join(hexified)}
23 return "const uint8_t %(array_name)s[] = {\n%(bytes)s\n};\n" % substs
26 # Create functions named the same as the data arrays that we're going to
27 # write to the headers, so we don't have to duplicate the names like so:
29 # def arrayName(header, cert_filename):
30 # header.write(_create_header("arrayName", cert_filename))
31 array_names = [
32 "xpcshellRoot",
33 "addonsPublicRoot",
34 "addonsPublicIntermediate",
35 "addonsStageRoot",
38 for n in array_names:
39 # Make sure the lambda captures the right string.
40 globals()[n] = lambda header, cert_filename, name=n: header.write(
41 _create_header(name, _file_byte_generator(cert_filename))