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
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
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
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
def encodeValue(self, encodeFun, value, defMode, maxChunkSize): if value.isPlusInfinity(): return int2oct(0x40), 0 if value.isMinusInfinity(): return int2oct(0x41), 0 m, b, e = value if not m: return null, 0 if b == 10: return str2octs('\x03%dE%s%d' % (m, e == 0 and '+' or '', e)), 0 elif b == 2: fo = 0x80 # binary enoding if m < 0: fo = fo | 0x40 # sign bit m = -m while int(m) != m: # drop floating point m *= 2 e -= 1 while m & 0x1 == 0: # mantissa normalization m >>= 1 e += 1 eo = null while e not in (0, -1): eo = int2oct(e&0xff) + eo e >>= 8 if e == 0 and eo and oct2int(eo[0]) & 0x80: eo = int2oct(0) + eo n = len(eo) if n > 0xff: raise error.PyAsn1Error('Real exponent overflow') if n == 1: pass elif n == 2: fo |= 1 elif n == 3: fo |= 2 else: fo |= 3 eo = int2oct(n//0xff+1) + eo po = null while m: po = int2oct(m&0xff) + po m >>= 8 substrate = int2oct(fo) + eo + po return substrate, 0 else: raise error.PyAsn1Error('Prohibited Real base %s' % b)
def encodeValue(self, encodeFun, value, defMode, maxChunkSize): if value.isPlusInfinity(): return int2oct(0x40), 0 if value.isMinusInfinity(): return int2oct(0x41), 0 m, b, e = value if not m: return null, 0 if b == 10: return str2octs('\x03%dE%s%d' % (m, e == 0 and '+' or '', e)), 0 elif b == 2: fo = 0x80 # binary enoding if m < 0: fo = fo | 0x40 # sign bit m = -m while int(m) != m: # drop floating point m *= 2 e -= 1 while m & 0x1 == 0: # mantissa normalization m >>= 1 e += 1 eo = null while e not in (0, -1): eo = int2oct(e & 0xff) + eo e >>= 8 if e == 0 and eo and oct2int(eo[0]) & 0x80: eo = int2oct(0) + eo n = len(eo) if n > 0xff: raise error.PyAsn1Error('Real exponent overflow') if n == 1: pass elif n == 2: fo |= 1 elif n == 3: fo |= 2 else: fo |= 3 eo = int2oct(n // 0xff + 1) + eo po = null while m: po = int2oct(m & 0xff) + po m >>= 8 substrate = int2oct(fo) + eo + po return substrate, 0 else: raise error.PyAsn1Error('Prohibited Real base %s' % b)
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
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
def encodeValue(self, encodeFun, client, defMode, maxChunkSize): if client == 0: substrate = int2oct(0) else: substrate = int2oct(255) return substrate, 0