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