Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/dns/rdtypes/ANY/CAA.py: 86%

36 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 07:09 +0000

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 

18import struct 

19 

20import dns.exception 

21import dns.immutable 

22import dns.rdata 

23import dns.tokenizer 

24 

25 

26@dns.immutable.immutable 

27class CAA(dns.rdata.Rdata): 

28 

29 """CAA (Certification Authority Authorization) record""" 

30 

31 # see: RFC 6844 

32 

33 __slots__ = ["flags", "tag", "value"] 

34 

35 def __init__(self, rdclass, rdtype, flags, tag, value): 

36 super().__init__(rdclass, rdtype) 

37 self.flags = self._as_uint8(flags) 

38 self.tag = self._as_bytes(tag, True, 255) 

39 if not tag.isalnum(): 

40 raise ValueError("tag is not alphanumeric") 

41 self.value = self._as_bytes(value) 

42 

43 def to_text(self, origin=None, relativize=True, **kw): 

44 return '%u %s "%s"' % ( 

45 self.flags, 

46 dns.rdata._escapify(self.tag), 

47 dns.rdata._escapify(self.value), 

48 ) 

49 

50 @classmethod 

51 def from_text( 

52 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None 

53 ): 

54 flags = tok.get_uint8() 

55 tag = tok.get_string().encode() 

56 value = tok.get_string().encode() 

57 return cls(rdclass, rdtype, flags, tag, value) 

58 

59 def _to_wire(self, file, compress=None, origin=None, canonicalize=False): 

60 file.write(struct.pack("!B", self.flags)) 

61 l = len(self.tag) 

62 assert l < 256 

63 file.write(struct.pack("!B", l)) 

64 file.write(self.tag) 

65 file.write(self.value) 

66 

67 @classmethod 

68 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): 

69 flags = parser.get_uint8() 

70 tag = parser.get_counted_bytes() 

71 value = parser.get_remaining() 

72 return cls(rdclass, rdtype, flags, tag, value)