summaryrefslogtreecommitdiffstats
path: root/onlineupdate/source/update/updater/gen_cert_header.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /onlineupdate/source/update/updater/gen_cert_header.py
parentInitial commit. (diff)
downloadlibreoffice-upstream/4%7.4.7.tar.xz
libreoffice-upstream/4%7.4.7.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'onlineupdate/source/update/updater/gen_cert_header.py')
-rwxr-xr-xonlineupdate/source/update/updater/gen_cert_header.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/onlineupdate/source/update/updater/gen_cert_header.py b/onlineupdate/source/update/updater/gen_cert_header.py
new file mode 100755
index 000000000..3f3798cfb
--- /dev/null
+++ b/onlineupdate/source/update/updater/gen_cert_header.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+import os
+import sys
+import binascii
+
+try:
+ from configparser import ConfigParser
+except ImportError:
+ from ConfigParser import SafeConfigParser as ConfigParser
+
+def file_byte_generator(filename):
+ with open(filename, "rb") as f:
+ block = f.read()
+ return block
+
+def eprint(*args, **kwargs):
+ print(*args, file=sys.stderr, **kwargs)
+
+def create_header(array_name, in_filename):
+ if sys.version_info >= (3,0):
+ hexified = ["0x" + binascii.hexlify(bytes([inp])).decode('ascii') for inp in file_byte_generator(in_filename)]
+ else:
+ hexified = ["0x" + binascii.hexlify(inp).decode('ascii') for inp 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:
+ eprint('ERROR: usage: gen_cert_header.py array_name update_config_file')
+ sys.exit(1)
+
+ if not os.path.exists(sys.argv[2]):
+ eprint('The config file %s does not exist'%(sys.argv[2]))
+ sys.exit(1)
+
+ config = ConfigParser()
+ config.read(sys.argv[2])
+ sys.exit(create_header(sys.argv[1], config.get('Updater', 'certificate-der')))