| 1 |
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license |
| 2 |
|
| 3 |
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. |
| 4 |
# |
| 5 |
# Permission to use, copy, modify, and distribute this software and its |
| 6 |
# documentation for any purpose with or without fee is hereby granted, |
| 7 |
# provided that the above copyright notice and this permission notice |
| 8 |
# appear in all copies. |
| 9 |
# |
| 10 |
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES |
| 11 |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR |
| 13 |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 16 |
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 |
|
| 18 |
import struct |
| 19 |
|
| 20 |
import dns.exception |
| 21 |
import dns.immutable |
| 22 |
import dns.rdata |
| 23 |
import dns.tokenizer |
| 24 |
|
| 25 |
|
| 26 |
@dns.immutable.immutable |
| 27 |
class CAA(dns.rdata.Rdata): |
| 28 |
"""CAA (Certification Authority Authorization) record""" |
| 29 |
|
| 30 |
# see: RFC 6844 |
| 31 |
|
| 32 |
__slots__ = ["flags", "tag", "value"] |
| 33 |
|
| 34 |
def __init__(self, rdclass, rdtype, flags, tag, value): |
| 35 |
super().__init__(rdclass, rdtype) |
| 36 |
self.flags = self._as_uint8(flags) |
| 37 |
self.tag = self._as_bytes(tag, True, 255) |
| 38 |
if not tag.isalnum(): |
| 39 |
raise ValueError("tag is not alphanumeric") |
| 40 |
self.value = self._as_bytes(value) |
| 41 |
|
| 42 |
def to_text(self, origin=None, relativize=True, **kw): |
| 43 |
return f'{self.flags} {dns.rdata._escapify(self.tag)} "{dns.rdata._escapify(self.value)}"' |
| 44 |
|
| 45 |
@classmethod |
| 46 |
def from_text( |
| 47 |
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None |
| 48 |
): |
| 49 |
flags = tok.get_uint8() |
| 50 |
tag = tok.get_string().encode() |
| 51 |
value = tok.get_string().encode() |
| 52 |
return cls(rdclass, rdtype, flags, tag, value) |
| 53 |
|
| 54 |
def _to_wire(self, file, compress=None, origin=None, canonicalize=False): |
| 55 |
file.write(struct.pack("!B", self.flags)) |
| 56 |
l = len(self.tag) |
| 57 |
assert l < 256 |
| 58 |
file.write(struct.pack("!B", l)) |
| 59 |
file.write(self.tag) |
| 60 |
file.write(self.value) |
| 61 |
|
| 62 |
@classmethod |
| 63 |
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): |
| 64 |
flags = parser.get_uint8() |
| 65 |
tag = parser.get_counted_bytes() |
| 66 |
value = parser.get_remaining() |
| 67 |
return cls(rdclass, rdtype, flags, tag, value) |