Refactor load_pk_from_dns to reduce code duplication between async and non-async.

This commit is contained in:
Scott Kitterman
2019-11-05 08:34:13 -05:00
parent e8ee183a7f
commit 3de1dc0362
2 changed files with 8 additions and 48 deletions
+7 -2
View File
@@ -425,8 +425,7 @@ def fold(header, namelen=0, linesep=b'\r\n'):
return pre + header
def load_pk_from_dns(name, dnsfunc, timeout=5):
s = dnsfunc(name, timeout=timeout)
def evaluate_pk(name, s):
if not s:
raise KeyFormatError("missing public key: %s"%name)
try:
@@ -475,6 +474,12 @@ def load_pk_from_dns(name, dnsfunc, timeout=5):
return pk, keysize, ktag, seqtlsrpt
def load_pk_from_dns(name, dnsfunc=get_txt, timeout=5):
s = dnsfunc(name, timeout=timeout)
pk, keysize, ktag, seqtlsrpt = evaluate_pk(name, s)
return pk, keysize, ktag, seqtlsrpt
#: Abstract base class for holding messages and options during DKIM/ARC signing and verification.
class DomainSigner(object):
# NOTE - the first 2 indentation levels are 2 instead of 4