2 # -*- coding: utf-8 -*-
4 ########################################################################
6 # Copyright 2018 Gerhard Klostermeier
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ########################################################################
23 # Usage: ./key-file-diff.py <file A> <file B>
25 ########################################################################
28 # - Read two key files and show the keys that are in file B but not in A.
29 # - Keys must be 12 hex characters long and at the beginning of a line.
31 ########################################################################
39 Read two key files and show the keys that are in file B but not in A.
40 :param args: Path to two key files A and B (positional shell parameters).
41 :return: 0 if everything went fine.
46 with
open(key_file_a
, 'r') as f
:
47 keys_a
= parse_keys(f
)
48 with
open(key_file_b
, 'r') as f
:
49 keys_b
= parse_keys(f
)
51 # Show all keys that are in B but not in A.
52 keys_diff
= keys_b
.difference(keys_a
)
61 Parse keys from a file and return them as a set.
62 Keys must be 12 hex characters long and at the beginning of a line.
63 :param file: Path to a file containing keys.
64 :return: A set of keys read from the file.
67 key_regex
= re
.compile('^[0-9a-fA-F]{12}')
69 key
= key_regex
.match(line
)
71 key
= key
.group(0).upper()
73 except AttributeError:
78 if __name__
== '__main__':
80 sys
.exit(main(sys
.argv
))