Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /usr/lib/python2.7/dist-packages/twisted/conch/ssh/ |
Upload File : |
# -*- test-case-name: twisted.conch.test.test_common -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Backported functions from Cryptography to support older versions. These functions can be obtained from C{cryptography.utils} instead, from version 1.1 onwards. """ from __future__ import absolute_import, division import binascii import struct def intFromBytes(data, byteorder, signed=False): """ Convert an integer in packed form to a Python C{int}. @type data: L{bytes} @param data: The packed integer. @type byteorder: L{str} @param byteorder: The byte order the data is in. Only C{'big'} is currently supported. @type signed: L{bool} @param signed: C{True} for signed, C{False} for unsigned. @rtype: L{int} @return: The decoded integer. """ assert byteorder == 'big' assert not signed if len(data) % 4 != 0: data = (b'\x00' * (4 - (len(data) % 4))) + data result = 0 while len(data) > 0: digit, = struct.unpack('>I', data[:4]) result = (result << 32) + digit data = data[4:] return result def intToBytes(integer, length=None): """ Convert a Python C{int} to packed data. @type integer: L{int} @param integer: The integer to pack. @type length: L{int} or C{None} @param length: The length to pad the result to, or C{None} for no padding. @rtype: C{bytes} @return: The packed integer. """ hexString = '%x' % (integer,) if length is None: n = len(hexString) else: n = length * 2 return binascii.unhexlify(hexString.zfill(n + (n & 1)))