本文整理汇总了Python中pyasn1.compat.octets.int2oct方法的典型用法代码示例。如果您正苦于以下问题:Python octets.int2oct方法的具体用法?Python octets.int2oct怎么用?Python octets.int2oct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasn1.compat.octets
的用法示例。
在下文中一共展示了octets.int2oct方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encodeValue
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
if not maxChunkSize or len(value) <= maxChunkSize*8:
out_len = (len(value) + 7) // 8
out_list = out_len * [0]
j = 7
i = -1
for val in value:
j += 1
if j == 8:
i += 1
j = 0
out_list[i] = out_list[i] | val << (7-j)
return int2oct(7-j) + ints2octs(out_list), 0
else:
pos = 0; substrate = null
while 1:
# count in octets
v = value.clone(value[pos*8:pos*8+maxChunkSize*8])
if not v:
break
substrate = substrate + encodeFun(v, defMode, maxChunkSize)
pos = pos + maxChunkSize
return substrate, 1
示例2: encodeValue
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
if not maxChunkSize or len(value) <= maxChunkSize * 8:
out_len = (len(value) + 7) // 8
out_list = out_len * [0]
j = 7
i = -1
for val in value:
j += 1
if j == 8:
i += 1
j = 0
out_list[i] |= val << (7 - j)
return int2oct(7 - j) + ints2octs(out_list), 0
else:
pos = 0
substrate = null
while True:
# count in octets
v = value.clone(value[pos * 8:pos * 8 + maxChunkSize * 8])
if not v:
break
substrate = substrate + encodeFun(v, defMode, maxChunkSize)
pos += maxChunkSize
return substrate, 1
示例3: encodeValue
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
if not maxChunkSize or len(value) <= maxChunkSize*8:
r = {}; l = len(value); p = 0; j = 7
while p < l:
i, j = divmod(p, 8)
r[i] = r.get(i,0) | value[p]<<(7-j)
p = p + 1
keys = list(r); keys.sort()
return int2oct(7-j) + ints2octs([r[k] for k in keys]), 0
else:
pos = 0; substrate = null
while 1:
# count in octets
v = value.clone(value[pos*8:pos*8+maxChunkSize*8])
if not v:
break
substrate = substrate + encodeFun(v, defMode, maxChunkSize)
pos = pos + maxChunkSize
return substrate, 1
示例4: encodeValue
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeValue(self, value, encodeFun, **options):
valueLength = len(value)
if valueLength % 8:
alignedValue = value << (8 - valueLength % 8)
else:
alignedValue = value
maxChunkSize = options.get('maxChunkSize', 0)
if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8:
substrate = alignedValue.asOctets()
return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True
# strip off explicit tags
alignedValue = alignedValue.clone(
tagSet=tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)
)
stop = 0
substrate = null
while stop < valueLength:
start = stop
stop = min(start + maxChunkSize * 8, valueLength)
substrate += encodeFun(alignedValue[start:stop], **options)
return substrate, True, True
示例5: encodeTag
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeTag(self, t, isConstructed):
tagClass, tagFormat, tagId = t.asTuple() # this is a hotspot
v = tagClass | tagFormat
if isConstructed:
v = v|tag.tagFormatConstructed
if tagId < 31:
return int2oct(v|tagId)
else:
s = int2oct(tagId&0x7f)
tagId = tagId >> 7
while tagId:
s = int2oct(0x80|(tagId&0x7f)) + s
tagId = tagId >> 7
return int2oct(v|0x1F) + s
示例6: encodeLength
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeLength(self, length, defMode):
if not defMode and self.supportIndefLenMode:
return int2oct(0x80)
if length < 0x80:
return int2oct(length)
else:
substrate = null
while length:
substrate = int2oct(length&0xff) + substrate
length = length >> 8
substrateLen = len(substrate)
if substrateLen > 126:
raise Error('Length octets overflow (%d)' % substrateLen)
return int2oct(0x80 | substrateLen) + substrate
示例7: encodeValue
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeValue(self, encodeFun, client, defMode, maxChunkSize):
if client == 0:
substrate = int2oct(0)
else:
substrate = int2oct(255)
return substrate, 0
示例8: encodeTag
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeTag(self, t, isConstructed):
tagClass, tagFormat, tagId = t.asTuple() # this is a hotspot
v = tagClass | tagFormat
if isConstructed:
v = v | tag.tagFormatConstructed
if tagId < 31:
return int2oct(v | tagId)
else:
s = int2oct(tagId & 0x7f)
tagId >>= 7
while tagId:
s = int2oct(0x80 | (tagId & 0x7f)) + s
tagId >>= 7
return int2oct(v | 0x1F) + s
示例9: encodeLength
# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import int2oct [as 别名]
def encodeLength(self, length, defMode):
if not defMode and self.supportIndefLenMode:
return int2oct(0x80)
if length < 0x80:
return int2oct(length)
else:
substrate = null
while length:
substrate = int2oct(length & 0xff) + substrate
length >>= 8
substrateLen = len(substrate)
if substrateLen > 126:
raise error.PyAsn1Error('Length octets overflow (%d)' % substrateLen)
return int2oct(0x80 | substrateLen) + substrate