当前位置: 首页>>代码示例>>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;未经允许,请勿转载。