home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import cStringIO
- import struct
- import dns.exception as dns
- import dns.dnssec as dns
- import dns.rdata as dns
- import dns.tokenizer as dns
- _ctype_by_value = {
- 1: 'PKIX',
- 2: 'SPKI',
- 3: 'PGP',
- 253: 'URI',
- 254: 'OID' }
- _ctype_by_name = {
- 'PKIX': 1,
- 'SPKI': 2,
- 'PGP': 3,
- 'URI': 253,
- 'OID': 254 }
-
- def _ctype_from_text(what):
- v = _ctype_by_name.get(what)
- if v is not None:
- return v
- return int(what)
-
-
- def _ctype_to_text(what):
- v = _ctype_by_value.get(what)
- if v is not None:
- return v
- return str(what)
-
-
- class CERT(dns.rdata.Rdata):
- __slots__ = [
- 'certificate_type',
- 'key_tag',
- 'algorithm',
- 'certificate']
-
- def __init__(self, rdclass, rdtype, certificate_type, key_tag, algorithm, certificate):
- super(CERT, self).__init__(rdclass, rdtype)
- self.certificate_type = certificate_type
- self.key_tag = key_tag
- self.algorithm = algorithm
- self.certificate = certificate
-
-
- def to_text(self, origin = None, relativize = True, **kw):
- certificate_type = _ctype_to_text(self.certificate_type)
- return '%s %d %s %s' % (certificate_type, self.key_tag, dns.dnssec.algorithm_to_text(self.algorithm), dns.rdata._base64ify(self.certificate))
-
-
- def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
- certificate_type = _ctype_from_text(tok.get_string())
- key_tag = tok.get_uint16()
- algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
- if algorithm < 0 or algorithm > 255:
- raise dns.exception.SyntaxError, 'bad algorithm type'
- algorithm > 255
- 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)
- certificate = b64.decode('base64_codec')
- return cls(rdclass, rdtype, certificate_type, key_tag, algorithm, certificate)
-
- from_text = classmethod(from_text)
-
- def to_wire(self, file, compress = None, origin = None):
- prefix = struct.pack('!HHB', self.certificate_type, self.key_tag, self.algorithm)
- file.write(prefix)
- file.write(self.certificate)
-
-
- def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
- prefix = wire[current:current + 5]
- current += 5
- rdlen -= 5
- if rdlen < 0:
- raise dns.exception.FormError
- rdlen < 0
- (certificate_type, key_tag, algorithm) = struct.unpack('!HHB', prefix)
- certificate = wire[current:current + rdlen]
- return cls(rdclass, rdtype, certificate_type, key_tag, algorithm, certificate)
-
- from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- f = cStringIO.StringIO()
- self.to_wire(f)
- wire1 = f.getvalue()
- f.seek(0)
- f.truncate()
- other.to_wire(f)
- wire2 = f.getvalue()
- f.close()
- return cmp(wire1, wire2)
-
-
-