dnspython  1.16.0
About: dnspython is a DNS toolkit (for Python 2.x) that supports almost all record types.
  Fossies Dox: dnspython-1.16.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

SSHFP.py
Go to the documentation of this file.
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2 
3 # Copyright (C) 2005-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 import binascii
20 
21 import dns.rdata
22 import dns.rdatatype
23 
24 
26 
27  """SSHFP record
28 
29  @ivar algorithm: the algorithm
30  @type algorithm: int
31  @ivar fp_type: the digest type
32  @type fp_type: int
33  @ivar fingerprint: the fingerprint
34  @type fingerprint: string
35  @see: draft-ietf-secsh-dns-05.txt"""
36 
37  __slots__ = ['algorithm', 'fp_type', 'fingerprint']
38 
39  def __init__(self, rdclass, rdtype, algorithm, fp_type,
40  fingerprint):
41  super(SSHFP, self).__init__(rdclass, rdtype)
42  self.algorithm = algorithm
43  self.fp_type = fp_type
44  self.fingerprint = fingerprint
45 
46  def to_text(self, origin=None, relativize=True, **kw):
47  return '%d %d %s' % (self.algorithm,
48  self.fp_type,
50  chunksize=128))
51 
52  @classmethod
53  def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
54  algorithm = tok.get_uint8()
55  fp_type = tok.get_uint8()
56  chunks = []
57  while 1:
58  t = tok.get().unescape()
59  if t.is_eol_or_eof():
60  break
61  if not t.is_identifier():
63  chunks.append(t.value.encode())
64  fingerprint = b''.join(chunks)
65  fingerprint = binascii.unhexlify(fingerprint)
66  return cls(rdclass, rdtype, algorithm, fp_type, fingerprint)
67 
68  def to_wire(self, file, compress=None, origin=None):
69  header = struct.pack("!BB", self.algorithm, self.fp_type)
70  file.write(header)
71  file.write(self.fingerprint)
72 
73  @classmethod
74  def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
75  header = struct.unpack("!BB", wire[current: current + 2])
76  current += 2
77  rdlen -= 2
78  fingerprint = wire[current: current + rdlen].unwrap()
79  return cls(rdclass, rdtype, header[0], header[1], fingerprint)
dns.exception.SyntaxError
Definition: exception.py:113
dns.rdtypes.ANY.SSHFP.SSHFP.__init__
def __init__(self, rdclass, rdtype, algorithm, fp_type, fingerprint)
Definition: SSHFP.py:39
dns.rdtypes.ANY.SSHFP.SSHFP.fingerprint
fingerprint
Definition: SSHFP.py:43
dns.rdata._hexify
def _hexify(data, chunksize=_hex_chunksize)
Definition: rdata.py:40
dns.rdtypes.ANY.SSHFP.SSHFP.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: SSHFP.py:68
dns.rdtypes.ANY.SSHFP.SSHFP.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: SSHFP.py:74
dns.rdata
Definition: rdata.py:1
dns.rdatatype
Definition: rdatatype.py:1
dns.rdtypes.ANY.SSHFP.SSHFP.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: SSHFP.py:46
dns.rdtypes.ANY.SSHFP.SSHFP.algorithm
algorithm
Definition: SSHFP.py:41
dns.rdtypes.ANY.SSHFP.SSHFP
Definition: SSHFP.py:25
dns.rdtypes.ANY.SSHFP.SSHFP.fp_type
fp_type
Definition: SSHFP.py:42
dns.rdtypes.ANY.SSHFP.SSHFP.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: SSHFP.py:53
dns.rdata.Rdata
Definition: rdata.py:95