Python pyasn1.compat.octets.oct2int() Examples
The following are 30
code examples of pyasn1.compat.octets.oct2int().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyasn1.compat.octets
, or try the search function
.
Example #1
Source File: decoder.py From bash-lambda-layer with MIT License | 6 votes |
def valueDecoder(self, substrate, asn1Spec, tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value, **options), tail # TODO: prohibit non-canonical encoding
Example #2
Source File: decoder.py From teleport with Apache License 2.0 | 6 votes |
def valueDecoder(self, substrate, asn1Spec, tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value, **options), tail # TODO: prohibit non-canonical encoding
Example #3
Source File: decoder.py From plugin.video.bdyun with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #4
Source File: decoder.py From oss-ftp with MIT License | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail
Example #5
Source File: decoder.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #6
Source File: decoder.py From plugin.video.bdyun with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail
Example #7
Source File: decoder.py From pelisalacarta-ce with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #8
Source File: decoder.py From xunfengES with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #9
Source File: decoder.py From pelisalacarta-ce with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail
Example #10
Source File: decoder.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail # TODO: prohibit non-canonical encoding
Example #11
Source File: decoder.py From teleport with Apache License 2.0 | 6 votes |
def valueDecoder(self, substrate, asn1Spec, tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value, **options), tail # TODO: prohibit non-canonical encoding
Example #12
Source File: decoder.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #13
Source File: decoder.py From opsbro with MIT License | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #14
Source File: decoder.py From aqua-monitor with GNU Lesser General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #15
Source File: decoder.py From oss-ftp with MIT License | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #16
Source File: decoder.py From scalyr-agent-2 with Apache License 2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #17
Source File: decoder.py From scalyr-agent-2 with Apache License 2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail
Example #18
Source File: decoder.py From learn_python3_spider with MIT License | 6 votes |
def valueDecoder(self, substrate, asn1Spec, tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value, **options), tail # TODO: prohibit non-canonical encoding
Example #19
Source File: decoder.py From addon with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #20
Source File: decoder.py From addon with GNU General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail
Example #21
Source File: decoder.py From xbmc-addons-chinese with GNU General Public License v2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #22
Source File: decoder.py From xbmc-addons-chinese with GNU General Public License v2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #23
Source File: decoder.py From baidupan_shell with GNU General Public License v2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head: return self._createComponent(asn1Spec, tagSet, 0), tail if head in self.precomputedValues: value = self.precomputedValues[head] else: firstOctet = oct2int(head[0]) if firstOctet & 0x80: value = -1 else: value = 0 for octet in head: value = value << 8 | oct2int(octet) return self._createComponent(asn1Spec, tagSet, value), tail
Example #24
Source File: decoder.py From aqua-monitor with GNU Lesser General Public License v3.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail
Example #25
Source File: decoder.py From xbmc-addons-chinese with GNU General Public License v2.0 | 6 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value), tail
Example #26
Source File: decoder.py From luci-py with Apache License 2.0 | 6 votes |
def valueDecoder(self, substrate, asn1Spec, tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): head, tail = substrate[:length], substrate[length:] if not head or length != 1: raise error.PyAsn1Error('Not single-octet Boolean payload') byte = oct2int(head[0]) # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1 # in https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf if byte == 0xff: value = 1 elif byte == 0x00: value = 0 else: raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte) return self._createComponent(asn1Spec, tagSet, value, **options), tail # TODO: prohibit non-canonical encoding
Example #27
Source File: TRANSPORT-ADDRESS-MIB.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def __getitem__(self, i): if not hasattr(self, '__tuple_value'): if not has_ipv6: raise error.PySnmpError('IPv6 not supported by platform') v = self.asOctets() self.__tuple_value = ( inet_ntop(socket.AF_INET6, v[:16]), oct2int(v[16]) << 8 | oct2int(v[17]), 0, # flowinfo 0) # scopeid return self.__tuple_value[i]
Example #28
Source File: decoder.py From oss-ftp with MIT License | 5 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if tagSet[0][1] == tag.tagFormatSimple: # XXX what tag to check? if not head: raise error.PyAsn1Error('Empty substrate') trailingBits = oct2int(head[0]) if trailingBits > 7: raise error.PyAsn1Error( 'Trailing bits overflow %s' % trailingBits ) head = head[1:] lsb = p = 0; l = len(head)-1; b = [] while p <= l: if p == l: lsb = trailingBits j = 7 o = oct2int(head[p]) while j >= lsb: b.append((o>>j)&0x01) j = j - 1 p = p + 1 return self._createComponent(asn1Spec, tagSet, b), tail r = self._createComponent(asn1Spec, tagSet, ()) if substrateFun: return substrateFun(r, substrate, length) while head: component, head = decodeFun(head, self.protoComponent) r = r + component return r, tail
Example #29
Source File: decoder.py From addon with GNU General Public License v3.0 | 5 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if tagSet[0][1] == tag.tagFormatSimple: # XXX what tag to check? if not head: raise error.PyAsn1Error('Empty substrate') trailingBits = oct2int(head[0]) if trailingBits > 7: raise error.PyAsn1Error( 'Trailing bits overflow %s' % trailingBits ) head = head[1:] lsb = p = 0; l = len(head)-1; b = [] while p <= l: if p == l: lsb = trailingBits j = 7 o = oct2int(head[p]) while j >= lsb: b.append((o>>j)&0x01) j = j - 1 p = p + 1 return self._createComponent(asn1Spec, tagSet, b), tail r = self._createComponent(asn1Spec, tagSet, ()) if substrateFun: return substrateFun(r, substrate, length) while head: component, head = decodeFun(head, self.protoComponent) r = r + component return r, tail
Example #30
Source File: decoder.py From xunfengES with GNU General Public License v3.0 | 5 votes |
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] if tagSet[0][1] == tag.tagFormatSimple: # XXX what tag to check? if not head: raise error.PyAsn1Error('Empty substrate') trailingBits = oct2int(head[0]) if trailingBits > 7: raise error.PyAsn1Error( 'Trailing bits overflow %s' % trailingBits ) head = head[1:] lsb = p = 0; l = len(head)-1; b = [] while p <= l: if p == l: lsb = trailingBits j = 7 o = oct2int(head[p]) while j >= lsb: b.append((o>>j)&0x01) j = j - 1 p = p + 1 return self._createComponent(asn1Spec, tagSet, b), tail r = self._createComponent(asn1Spec, tagSet, ()) if substrateFun: return substrateFun(r, substrate, length) while head: component, head = decodeFun(head, self.protoComponent) r = r + component return r, tail