3 from __future__
import print_function
9 from configparser
import ConfigParser
11 from ConfigParser
import SafeConfigParser
as ConfigParser
13 def file_byte_generator(filename
):
14 with
open(filename
, "rb") as f
:
18 def eprint(*args
, **kwargs
):
19 print(*args
, file=sys
.stderr
, **kwargs
)
21 def create_header(array_name
, in_filename
):
22 if sys
.version_info
>= (3,0):
23 hexified
= ["0x" + binascii
.hexlify(bytes([inp
])).decode('ascii') for inp
in file_byte_generator(in_filename
)]
25 hexified
= ["0x" + binascii
.hexlify(inp
).decode('ascii') for inp
in file_byte_generator(in_filename
)]
26 print("const uint8_t " + array_name
+ "[] = {")
27 print(", ".join(hexified
))
31 if __name__
== '__main__':
33 eprint('ERROR: usage: gen_cert_header.py array_name update_config_file')
36 if not os
.path
.exists(sys
.argv
[2]):
37 eprint('The config file %s does not exist'%(sys
.argv
[2]))
40 config
= ConfigParser()
41 config
.read(sys
.argv
[2])
42 sys
.exit(create_header(sys
.argv
[1], config
.get('Updater', 'certificate-der')))