當前位置: 首頁>>代碼示例>>Python>>正文


Python common.chr方法代碼示例

本文整理匯總了Python中shadowsocks.common.chr方法的典型用法代碼示例。如果您正苦於以下問題:Python common.chr方法的具體用法?Python common.chr怎麽用?Python common.chr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在shadowsocks.common的用法示例。


在下文中一共展示了common.chr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: nonce_increment

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def nonce_increment(nonce, nlen):
    """
    Increase nonce by 1 in little endian
    From libsodium sodium_increment():
    for (; i < nlen; i++) {
        c += (uint_fast16_t) n[i];
        n[i] = (unsigned char) c;
        c >>= 8;
    }
    :param nonce: string_buffer nonce
    :param nlen: nonce length
    :return: nonce plus by 1
    """
    c = 1
    i = 0
    # n = create_string_buffer(nlen)
    while i < nlen:
        c += ord(nonce[i])
        nonce[i] = chr(c & 0xFF)
        c >>= 8
        i += 1
    return  # n.raw 
開發者ID:PaperDashboard,項目名稱:shadowsocks,代碼行數:24,代碼來源:aead.py

示例2: build_address

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def build_address(address):
    """
    填充DNS請求中的QNAME字段
    :param address:     查詢的域名
    :return:            若域名合法則返回填充的字節流,否則返回None
    """
    address = address.strip(b'.')
    labels = address.split(b'.')
    results = []
    for label in labels:
        l = len(label)
        if l > 63:
            return None
        # 將“.”替換為下一個有效字段長度
        results.append(common.chr(l))
        results.append(label)
    results.append(b'\0')
    return b''.join(results) 
開發者ID:youkochan,項目名稱:shadowsocks-analysis,代碼行數:20,代碼來源:asyncdns.py

示例3: build_address

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def build_address(address):
    address = address.strip(b'.')
    labels = address.split(b'.')
    results = []
    for label in labels:
        l = len(label)
        if l > 63:
            return None
        results.append(common.chr(l))
        results.append(label)
    results.append(b'\0')
    return b''.join(results) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:14,代碼來源:asyncdns.py

示例4: pack_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def pack_data(self, buf):
        if len(buf) == 0:
            return b''
        rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 16)
        data = common.chr(len(rnd_data) + 1) + rnd_data + buf
        data = struct.pack('>H', len(data) + 6) + data
        crc = (0xffffffff - binascii.crc32(data)) & 0xffffffff
        data += struct.pack('<I', crc)
        return data 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:11,代碼來源:verify_simple.py

示例5: _pack_rsp_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def _pack_rsp_data(self, cmd, data):
        reqid_str = struct.pack(">H", self._request_id)
        return b''.join([CMD_VER_STR, common.chr(cmd), reqid_str, data, self._rand_data[:random.randint(0, len(self._rand_data))], reqid_str]) 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:5,代碼來源:udprelay.py

示例6: _pack_rnd_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def _pack_rnd_data(self, data):
        length = random.randint(0, len(self._rand_data))
        if length == 0:
            return data
        elif length == 1:
            return b"\x81" + data
        elif length < 256:
            return b"\x80" + common.chr(length) + self._rand_data[:length - 2] + data
        else:
            return b"\x82" + struct.pack(">H", length) + self._rand_data[:length - 3] + data 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:12,代碼來源:udprelay.py

示例7: _pack_post_data_64

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def _pack_post_data_64(self, cmd, send_id, pack_id, data):
        reqid_str = struct.pack(">H", self._request_id)
        recv_id = self._recvqueue.get_begin_id()
        rsp_data = b''.join([CMD_VER_STR, common.chr(cmd), reqid_str, struct.pack(">Q", recv_id), struct.pack(">Q", pack_id), data, reqid_str])
        return rsp_data 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:7,代碼來源:udprelay.py

示例8: _handel_protocol_error

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def _handel_protocol_error(self, client_address, ogn_data):
        #raise Exception('can not parse header')
        logging.warn("Protocol ERROR, TCP ogn data %s from %s:%d" % (binascii.hexlify(ogn_data), client_address[0], client_address[1]))
        self._encrypt_correct = False
        #create redirect or disconnect by hash code
        host, port = self._get_redirect_host(client_address, ogn_data)
        data = b"\x03" + common.chr(len(host)) + host + struct.pack('>H', port)
        logging.warn("TCP data redir %s:%d %s" % (host, port, binascii.hexlify(data)))
        return data + ogn_data 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:11,代碼來源:tcprelay.py

示例9: rnd_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def rnd_data(self, buf_size):
        if buf_size > 1200:
            return b'\x01'

        if buf_size > 400:
            rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 256)
        else:
            rnd_data = os.urandom(struct.unpack('>H', os.urandom(2))[0] % 512)

        if len(rnd_data) < 128:
            return common.chr(len(rnd_data) + 1) + rnd_data
        else:
            return common.chr(255) + struct.pack('>H', len(rnd_data) + 3) + rnd_data 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:15,代碼來源:auth.py

示例10: pack_auth_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def pack_auth_data(self, buf):
        data = chr(ord(buf[0]) | 0x10) + buf[1:]
        data += hmac.new(self.server_info.iv + self.server_info.key, data, hashlib.sha1).digest()[:10]
        return data 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:6,代碼來源:verify.py

示例11: server_post_decrypt

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def server_post_decrypt(self, buf):
        if self.raw_trans:
            return (buf, False)
        self.recv_buf += buf
        out_buf = b''
        if not self.has_recv_header:
            if len(self.recv_buf) < 2:
                return (b'', False)
            if (ord(self.recv_buf[0]) & 0x10) != 0x10:
                return self.not_match_return(self.recv_buf)
            head_size = self.get_head_size(self.recv_buf, 65536)
            if len(self.recv_buf) < head_size + 10:
                return self.not_match_return(self.recv_buf)
            sha1data = hmac.new(self.server_info.recv_iv + self.server_info.key, self.recv_buf[:head_size], hashlib.sha1).digest()[:10]
            if sha1data != self.recv_buf[head_size:head_size + 10]:
                logging.error('server_post_decrype data uncorrect auth HMAC-SHA1')
                return self.not_match_return(self.recv_buf)
            out_buf = to_bytes(chr(ord(self.recv_buf[0]) & 0xEF)) + self.recv_buf[1:head_size]
            self.recv_buf = self.recv_buf[head_size + 10:]
            self.has_recv_header = True
        while len(self.recv_buf) > 2:
            length = struct.unpack('>H', self.recv_buf[:2])[0] + 12
            if length > len(self.recv_buf):
                break

            data = self.recv_buf[12:length]
            sha1data = hmac.new(self.server_info.recv_iv + struct.pack('>I', self.recv_id), data, hashlib.sha1).digest()[:10]
            if sha1data != self.recv_buf[2:12]:
                raise Exception('server_post_decrype data uncorrect chunk HMAC-SHA1')

            self.recv_id = (self.recv_id + 1) & 0xFFFFFFFF
            out_buf += data
            self.recv_buf = self.recv_buf[length:]

        return (out_buf, False) 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:37,代碼來源:verify.py

示例12: client_udp_pre_encrypt

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def client_udp_pre_encrypt(self, buf):
        ret = self.pack_auth_data(buf)
        return chr(ord(buf[0]) | 0x10) + buf[1:] 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:5,代碼來源:verify.py

示例13: pack_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def pack_data(self, buf):
        rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 16)
        data = common.chr(len(rnd_data) + 1) + rnd_data + buf
        data = struct.pack('>H', len(data) + 6) + data
        adler32 = zlib.adler32(data) & 0xFFFFFFFF
        data += struct.pack('<I', adler32)
        return data 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:9,代碼來源:auth.py

示例14: pack_auth_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def pack_auth_data(self, buf):
        if len(buf) == 0:
            return b''
        rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 128)
        data = common.chr(len(rnd_data) + 1) + rnd_data + buf
        data = struct.pack('>H', len(data) + 16) + data
        crc = binascii.crc32(self.server_info.key) & 0xFFFFFFFF
        data = struct.pack('<I', crc) + data
        data += hmac.new(self.server_info.iv + self.server_info.key, data, hashlib.sha1).digest()[:10]
        return data 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:12,代碼來源:auth.py

示例15: rnd_data

# 需要導入模塊: from shadowsocks import common [as 別名]
# 或者: from shadowsocks.common import chr [as 別名]
def rnd_data(self, buf_size):
        if buf_size > 1300:
            return b'\x01'

        if buf_size > 400:
            rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 128)
            return common.chr(len(rnd_data) + 1) + rnd_data

        rnd_data = os.urandom(struct.unpack('>H', os.urandom(2))[0] % 1024)
        return common.chr(255) + struct.pack('>H', len(rnd_data) + 3) + rnd_data 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:12,代碼來源:auth.py


注:本文中的shadowsocks.common.chr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。