security/apps/gen_cert_header.py
author Alexandre Poirot <poirot.alex@gmail.com>
Thu, 10 Apr 2014 10:35:26 -0400
changeset 196368 e1c19ed25b12e8d8a03c26f7d562561d66c9a521
parent 186013 8cdaaf3da9f84ba309429aee968d2f55a905c63d
child 225023 d883d8b4bfd6a3b37925356ed3c7a2c625171247
permissions -rw-r--r--
Bug 990065 - Ship simulator screen xpcom in b2g desktop package and prevent it from breaking bfcache. r=vingtetun

# 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]))