import dkim.dknewkey as _dknewkey from os.path import dirname as _dirname, abspath as _abspath, join as _join, isfile as _isfile, isdir as _isdir from os import makedirs as _makedirs from shutil import rmtree as _rmtree import __main__ def _eprint(*args, **kwargs): pass _dknewkey.eprint = _eprint HERE = _dirname(_abspath(__main__.__file__)) DKIM_DIR = _join(HERE, 'pki/dkim') def get_dkim_key(domain_name_eth0, domain): dkim_dir = _join(DKIM_DIR, domain_name_eth0, domain) dkim_file_src = _join(dkim_dir, f'{domain}') dkim_file_key = _join(dkim_dir, f'{domain}.key') dkim_file = _join(dkim_dir, f'{domain}.dns') if not _isfile(dkim_file): if _isdir(dkim_dir): _rmtree(dkim_dir) _makedirs(dkim_dir) priv_key = _dknewkey.GenEd25519Keys(dkim_file_src) _dknewkey.ExtractEd25519PublicKey(dkim_file_key, priv_key) with open(dkim_file_key, 'r') as fh: return fh.read().strip()