1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/apps/gen_cert_header.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,29 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +import sys 1.9 +import binascii 1.10 + 1.11 +def file_byte_generator(filename, block_size = 512): 1.12 + with open(filename, "rb") as f: 1.13 + while True: 1.14 + block = f.read(block_size) 1.15 + if block: 1.16 + for byte in block: 1.17 + yield byte 1.18 + else: 1.19 + break 1.20 + 1.21 +def create_header(array_name, in_filename): 1.22 + hexified = ["0x" + binascii.hexlify(byte) for byte in file_byte_generator(in_filename)] 1.23 + print "const uint8_t " + array_name + "[] = {" 1.24 + print ", ".join(hexified) 1.25 + print "};" 1.26 + return 0 1.27 + 1.28 +if __name__ == '__main__': 1.29 + if len(sys.argv) < 3: 1.30 + print 'ERROR: usage: gen_cert_header.py array_name in_filename' 1.31 + sys.exit(1); 1.32 + sys.exit(create_header(sys.argv[1], sys.argv[2]))