algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
if algorithm < 0 or algorithm > 255:
raise dns.exception.SyntaxError("bad algorithm type")
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- b64 = b''.join(chunks)
+ b64 = tok.concatenate_remaining_identifiers().encode()
certificate = base64.b64decode(b64)
return cls(rdclass, rdtype, certificate_type, key_tag,
algorithm, certificate)
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True,
relativize_to=None):
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- b64 = b''.join(chunks)
+ b64 = tok.concatenate_remaining_identifiers().encode()
key = base64.b64decode(b64)
return cls(rdclass, rdtype, key)
inception = sigtime_to_posixtime(tok.get_string())
key_tag = tok.get_int()
signer = tok.get_name(origin, relativize, relativize_to)
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- b64 = b''.join(chunks)
+ b64 = tok.concatenate_remaining_identifiers().encode()
signature = base64.b64decode(b64)
return cls(rdclass, rdtype, type_covered, algorithm, labels,
original_ttl, expiration, inception, key_tag, signer,
relativize_to=None):
algorithm = tok.get_uint8()
fp_type = tok.get_uint8()
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- fingerprint = b''.join(chunks)
+ fingerprint = tok.concatenate_remaining_identifiers().encode()
fingerprint = binascii.unhexlify(fingerprint)
return cls(rdclass, rdtype, algorithm, fp_type, fingerprint)
usage = tok.get_uint8()
selector = tok.get_uint8()
mtype = tok.get_uint8()
- cert_chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- cert_chunks.append(t.value.encode())
- cert = b''.join(cert_chunks)
+ cert = tok.concatenate_remaining_identifiers().encode()
cert = binascii.unhexlify(cert)
return cls(rdclass, rdtype, usage, selector, mtype, cert)
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True,
relativize_to=None):
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- b64 = b''.join(chunks)
+ b64 = tok.concatenate_remaining_identifiers().encode()
data = base64.b64decode(b64)
return cls(rdclass, rdtype, data)
gateway = tok.get_name(origin, relativize, relativize_to)
else:
gateway = tok.get_string()
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- b64 = b''.join(chunks)
+ b64 = tok.concatenate_remaining_identifiers().encode()
key = base64.b64decode(b64)
return cls(rdclass, rdtype, precedence, gateway_type, algorithm,
gateway, key)
flags = tok.get_uint16()
protocol = tok.get_uint8()
algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- b64 = b''.join(chunks)
+ b64 = tok.concatenate_remaining_identifiers().encode()
key = base64.b64decode(b64)
return cls(rdclass, rdtype, flags, protocol, algorithm, key)
key_tag = tok.get_uint16()
algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
digest_type = tok.get_uint8()
- chunks = []
- while 1:
- t = tok.get().unescape()
- if t.is_eol_or_eof():
- break
- if not t.is_identifier():
- raise dns.exception.SyntaxError
- chunks.append(t.value.encode())
- digest = b''.join(chunks)
+ digest = tok.concatenate_remaining_identifiers().encode()
digest = binascii.unhexlify(digest)
return cls(rdclass, rdtype, key_tag, algorithm, digest_type,
digest)
raise dns.exception.SyntaxError('expecting an identifier')
return token.value
+ def concatenate_remaining_identifiers(self):
+ """Read the remaining tokens on the line, which should be identifiers.
+
+ Raises dns.exception.SyntaxError if a token is seen that is not an
+ identifier.
+
+ Returns a string containing a concatenation of the remaining
+ identifiers.
+ """
+ s = ""
+ while True:
+ token = self.get().unescape()
+ if token.is_eol_or_eof():
+ break
+ if not token.is_identifier():
+ raise dns.exception.SyntaxError
+ s += token.value
+ return s
+
def as_name(self, token, origin=None, relativize=False, relativize_to=None):
"""Try to interpret the token as a DNS name.