gecko/security/apps/gen_cert_header.py
Brian Smith 83e4eaa908 Bug 896620: Make marketplace certs work on in all products, r=keeler
--HG--
extra : source : 86ec7137a8892f75918c77e605df970f5b96ef62
extra : histedit_source : 33326790804d49e6ec658626116ebf870d94d445
2014-02-14 14:37:07 -08:00

30 lines
879 B
Python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import binascii
def file_byte_generator(filename, block_size = 512):
with open(filename, "rb") as f:
while True:
block = f.read(block_size)
if block:
for byte in block:
yield byte
else:
break
def create_header(array_name, in_filename):
hexified = ["0x" + binascii.hexlify(byte) for byte in file_byte_generator(in_filename)]
print "const uint8_t " + array_name + "[] = {"
print ", ".join(hexified)
print "};"
return 0
if __name__ == '__main__':
if len(sys.argv) < 3:
print 'ERROR: usage: gen_cert_header.py array_name in_filename'
sys.exit(1);
sys.exit(create_header(sys.argv[1], sys.argv[2]))