home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import struct
- import dns.exception as dns
- import dns.dnssec as dns
- import dns.rdata as dns
- _flags_from_text = {
- 'NOCONF': (16384, 49152),
- 'NOAUTH': (32768, 49152),
- 'NOKEY': (49152, 49152),
- 'FLAG2': (8192, 8192),
- 'EXTEND': (4096, 4096),
- 'FLAG4': (2048, 2048),
- 'FLAG5': (1024, 1024),
- 'USER': (0, 768),
- 'ZONE': (256, 768),
- 'HOST': (512, 768),
- 'NTYP3': (768, 768),
- 'FLAG8': (128, 128),
- 'FLAG9': (64, 64),
- 'FLAG10': (32, 32),
- 'FLAG11': (16, 16),
- 'SIG0': (0, 15),
- 'SIG1': (1, 15),
- 'SIG2': (2, 15),
- 'SIG3': (3, 15),
- 'SIG4': (4, 15),
- 'SIG5': (5, 15),
- 'SIG6': (6, 15),
- 'SIG7': (7, 15),
- 'SIG8': (8, 15),
- 'SIG9': (9, 15),
- 'SIG10': (10, 15),
- 'SIG11': (11, 15),
- 'SIG12': (12, 15),
- 'SIG13': (13, 15),
- 'SIG14': (14, 15),
- 'SIG15': (15, 15) }
- _protocol_from_text = {
- 'NONE': 0,
- 'TLS': 1,
- 'EMAIL': 2,
- 'DNSSEC': 3,
- 'IPSEC': 4,
- 'ALL': 255 }
-
- class KEYBase(dns.rdata.Rdata):
- __slots__ = [
- 'flags',
- 'protocol',
- 'algorithm',
- 'key']
-
- def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key):
- super(KEYBase, self).__init__(rdclass, rdtype)
- self.flags = flags
- self.protocol = protocol
- self.algorithm = algorithm
- self.key = key
-
-
- def to_text(self, origin = None, relativize = True, **kw):
- return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm, dns.rdata._base64ify(self.key))
-
-
- def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
- flags = tok.get_string()
- if flags.isdigit():
- flags = int(flags)
- else:
- flag_names = flags.split('|')
- flags = 0
- for flag in flag_names:
- v = _flags_from_text.get(flag)
- if v is None:
- raise dns.exception.SyntaxError, 'unknown flag %s' % flag
- v is None
- flags &= ~v[1]
- flags |= v[0]
-
- protocol = tok.get_string()
- if protocol.isdigit():
- protocol = int(protocol)
- else:
- protocol = _protocol_from_text.get(protocol)
- if protocol is None:
- raise dns.exception.SyntaxError, 'unknown protocol %s' % protocol
- protocol is None
- algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
- chunks = []
- while None:
- t = tok.get()
- if t[0] == dns.tokenizer.EOL or t[0] == dns.tokenizer.EOF:
- break
-
- if t[0] != dns.tokenizer.IDENTIFIER:
- raise dns.exception.SyntaxError
- chunks.append(t[1])
- continue
- b64 = ''.join(chunks)
- key = b64.decode('base64_codec')
- return cls(rdclass, rdtype, flags, protocol, algorithm, key)
-
- from_text = classmethod(from_text)
-
- def to_wire(self, file, compress = None, origin = None):
- header = struct.pack('!HBB', self.flags, self.protocol, self.algorithm)
- file.write(header)
- file.write(self.key)
-
-
- def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
- if rdlen < 4:
- raise dns.exception.FormError
- rdlen < 4
- header = struct.unpack('!HBB', wire[current:current + 4])
- current += 4
- rdlen -= 4
- key = wire[current:current + rdlen]
- return cls(rdclass, rdtype, header[0], header[1], header[2], key)
-
- from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- hs = struct.pack('!HBB', self.flags, self.protocol, self.algorithm)
- ho = struct.pack('!HBB', other.flags, other.protocol, other.algorithm)
- v = cmp(hs, ho)
- if v == 0:
- v = cmp(self.key, other.key)
-
- return v
-
-
-