Python pyasn1.type.univ.Integer() Examples

The following are 30 code examples of pyasn1.type.univ.Integer(). 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.type.univ , or try the search function .
Example #1
Source File: microsoft.py    From teleport with Apache License 2.0 6 votes vote down vote up
def dir_sync_control(criticality, object_security, ancestors_first, public_data_only, incremental_values, max_length, cookie):
    control_value = DirSyncControlRequestValue()
    flags = 0x0
    if object_security:
        flags |= 0x00000001

    if ancestors_first:
        flags |= 0x00000800

    if public_data_only:
        flags |= 0x00002000

    if incremental_values:
        flags |= 0x80000000
        # converts flags to signed 32 bit (AD expects a 4 bytes long unsigned integer, but ASN.1 Integer type is signed
        # so the BER encoder gives back a 5 bytes long signed integer
        flags = ctypes.c_long(flags & 0xFFFFFFFF).value

    control_value.setComponentByName('Flags', flags)
    control_value.setComponentByName('MaxBytes', max_length)
    if cookie:
        control_value.setComponentByName('Cookie', cookie)
    else:
        control_value.setComponentByName('Cookie', OctetString(''))
    return build_control('1.2.840.113556.1.4.841', criticality, control_value) 
Example #2
Source File: ca.py    From pymobiledevice with GNU General Public License v3.0 6 votes vote down vote up
def convertPKCS1toPKCS8pubKey(bitsdata):
    pubkey_pkcs1_b64 = b''.join(bitsdata.split(b'\n')[1:-2])
    pubkey_pkcs1, restOfInput = der_decoder.decode(base64.b64decode(pubkey_pkcs1_b64))
    bitstring = univ.Sequence()
    bitstring.setComponentByPosition(0, univ.Integer(pubkey_pkcs1[0]))
    bitstring.setComponentByPosition(1, univ.Integer(pubkey_pkcs1[1]))
    bitstring = der_encoder.encode(bitstring)
    try:
        bitstring = ''.join([('00000000'+bin(ord(x))[2:])[-8:] for x in list(bitstring)])
    except:
        bitstring = ''.join([('00000000'+bin(x)[2:])[-8:] for x in list(bitstring)])
    bitstring = univ.BitString("'%s'B" % bitstring)
    pubkeyid = univ.Sequence()
    pubkeyid.setComponentByPosition(0, univ.ObjectIdentifier('1.2.840.113549.1.1.1')) # == OID for rsaEncryption
    pubkeyid.setComponentByPosition(1, univ.Null(''))
    pubkey_seq = univ.Sequence()
    pubkey_seq.setComponentByPosition(0, pubkeyid)
    pubkey_seq.setComponentByPosition(1, bitstring)
    base64.MAXBINSIZE = (64//4)*3
    res =  b"-----BEGIN PUBLIC KEY-----\n"
    res += base64.encodestring(der_encoder.encode(pubkey_seq))
    res += b"-----END PUBLIC KEY-----\n"
    return res 
Example #3
Source File: replicaInfo.py    From teleport with Apache License 2.0 6 votes vote down vote up
def populate_result(self):
        substrate = self.decoded_response
        try:
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['partition_id'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['replica_state'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['modification_time'] = datetime.utcfromtimestamp(int(decoded))
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['purge_time'] = datetime.utcfromtimestamp(int(decoded))
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['local_partition_id'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=LDAPDN())
            self.result['partition_dn'] = str(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['replica_type'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['flags'] = int(decoded)
        except Exception:
            raise LDAPExtensionError('unable to decode substrate')

        if substrate:
            raise LDAPExtensionError('unknown substrate remaining') 
Example #4
Source File: dom.py    From peach with Mozilla Public License 2.0 6 votes vote down vote up
def __init__(self, name, parent):
        ElementWithChildren.__init__(self, name, parent)

        self.elementType = "seek"

        #: Python expression to calculate new position
        self.expression = None
        #: Integer position
        self.position = None
        #: Position change is relative to current position
        self.relative = None

        # EMulate some of the DataElement stuff
        self.array = None
        self.minOccurs = 1
        self.maxOccurs = 1
        self.currentValue = None
        self.defaultValue = None 
Example #5
Source File: replicaInfo.py    From teleport with Apache License 2.0 6 votes vote down vote up
def populate_result(self):
        substrate = self.decoded_response
        try:
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['partition_id'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['replica_state'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['modification_time'] = datetime.utcfromtimestamp(int(decoded))
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['purge_time'] = datetime.utcfromtimestamp(int(decoded))
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['local_partition_id'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=LDAPDN())
            self.result['partition_dn'] = str(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['replica_type'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['flags'] = int(decoded)
        except Exception:
            raise LDAPExtensionError('unable to decode substrate')

        if substrate:
            raise LDAPExtensionError('unknown substrate remaining') 
Example #6
Source File: replicaInfo.py    From teleport with Apache License 2.0 6 votes vote down vote up
def populate_result(self):
        substrate = self.decoded_response
        try:
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['partition_id'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['replica_state'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['modification_time'] = datetime.utcfromtimestamp(int(decoded))
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['purge_time'] = datetime.utcfromtimestamp(int(decoded))
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['local_partition_id'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=LDAPDN())
            self.result['partition_dn'] = str(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['replica_type'] = int(decoded)
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['flags'] = int(decoded)
        except Exception:
            raise LDAPExtensionError('unable to decode substrate')

        if substrate:
            raise LDAPExtensionError('unknown substrate remaining') 
Example #7
Source File: microsoft.py    From teleport with Apache License 2.0 6 votes vote down vote up
def dir_sync_control(criticality, object_security, ancestors_first, public_data_only, incremental_values, max_length, cookie):
    control_value = DirSyncControlRequestValue()
    flags = 0x0
    if object_security:
        flags |= 0x00000001

    if ancestors_first:
        flags |= 0x00000800

    if public_data_only:
        flags |= 0x00002000

    if incremental_values:
        flags |= 0x80000000
        # converts flags to signed 32 bit (AD expects a 4 bytes long unsigned integer, but ASN.1 Integer type is signed
        # so the BER encoder gives back a 5 bytes long signed integer
        flags = ctypes.c_long(flags & 0xFFFFFFFF).value

    control_value.setComponentByName('Flags', flags)
    control_value.setComponentByName('MaxBytes', max_length)
    if cookie:
        control_value.setComponentByName('Cookie', cookie)
    else:
        control_value.setComponentByName('Cookie', OctetString(''))
    return build_control('1.2.840.113556.1.4.841', criticality, control_value) 
Example #8
Source File: key.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def _save_pkcs1_der(self):
        '''Saves the private key in PKCS#1 DER format.

        @returns: the DER-encoded private key.
        '''

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                namedtype.NamedType('version', univ.Integer()),
                namedtype.NamedType('modulus', univ.Integer()),
                namedtype.NamedType('publicExponent', univ.Integer()),
                namedtype.NamedType('privateExponent', univ.Integer()),
                namedtype.NamedType('prime1', univ.Integer()),
                namedtype.NamedType('prime2', univ.Integer()),
                namedtype.NamedType('exponent1', univ.Integer()),
                namedtype.NamedType('exponent2', univ.Integer()),
                namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
        asn_key.setComponentByName('privateExponent', self.d)
        asn_key.setComponentByName('prime1', self.p)
        asn_key.setComponentByName('prime2', self.q)
        asn_key.setComponentByName('exponent1', self.exp1)
        asn_key.setComponentByName('exponent2', self.exp2)
        asn_key.setComponentByName('coefficient', self.coef)

        return encoder.encode(asn_key) 
Example #9
Source File: verdec.py    From scalyr-agent-2 with Apache License 2.0 5 votes vote down vote up
def decodeMessageVersion(wholeMsg):
    try:
        seq, wholeMsg = decoder.decode(
            wholeMsg, asn1Spec=univ.Sequence(), recursiveFlag=0
        )
        ver, wholeMsg = decoder.decode(
            wholeMsg, asn1Spec=univ.Integer(), recursiveFlag=0
        )
        if eoo.endOfOctets.isSameTypeWith(ver):
            raise ProtocolError('EOO at SNMP version component')
        return ver
    except PyAsn1Error:
        raise ProtocolError('Invalid BER at SNMP version component') 
Example #10
Source File: key.py    From iot-core-micropython with Apache License 2.0 5 votes vote down vote up
def _save_pkcs1_der(self):
        """Saves the private key in PKCS#1 DER format.

        :returns: the DER-encoded private key.
        :rtype: bytes
        """

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                namedtype.NamedType('version', univ.Integer()),
                namedtype.NamedType('modulus', univ.Integer()),
                namedtype.NamedType('publicExponent', univ.Integer()),
                namedtype.NamedType('privateExponent', univ.Integer()),
                namedtype.NamedType('prime1', univ.Integer()),
                namedtype.NamedType('prime2', univ.Integer()),
                namedtype.NamedType('exponent1', univ.Integer()),
                namedtype.NamedType('exponent2', univ.Integer()),
                namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
        asn_key.setComponentByName('privateExponent', self.d)
        asn_key.setComponentByName('prime1', self.p)
        asn_key.setComponentByName('prime2', self.q)
        asn_key.setComponentByName('exponent1', self.exp1)
        asn_key.setComponentByName('exponent2', self.exp2)
        asn_key.setComponentByName('coefficient', self.coef)

        return encoder.encode(asn_key) 
Example #11
Source File: key.py    From opsbro with MIT License 5 votes vote down vote up
def _save_pkcs1_der(self):
        '''Saves the private key in PKCS#1 DER format.

        @returns: the DER-encoded private key.
        '''

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                namedtype.NamedType('version', univ.Integer()),
                namedtype.NamedType('modulus', univ.Integer()),
                namedtype.NamedType('publicExponent', univ.Integer()),
                namedtype.NamedType('privateExponent', univ.Integer()),
                namedtype.NamedType('prime1', univ.Integer()),
                namedtype.NamedType('prime2', univ.Integer()),
                namedtype.NamedType('exponent1', univ.Integer()),
                namedtype.NamedType('exponent2', univ.Integer()),
                namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
        asn_key.setComponentByName('privateExponent', self.d)
        asn_key.setComponentByName('prime1', self.p)
        asn_key.setComponentByName('prime2', self.q)
        asn_key.setComponentByName('exponent1', self.exp1)
        asn_key.setComponentByName('exponent2', self.exp2)
        asn_key.setComponentByName('coefficient', self.coef)

        return encoder.encode(asn_key) 
Example #12
Source File: dom.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def pack(self, num):
        """
        Pack a number into proper format for this Number
        """

        # 1. Get the transformer we need
        isSigned = 0
        if self.signed:
            isSigned = 1

        isLittleEndian = 0
        if self.endian == 'little':
            isLittleEndian = 1

        if self.size == 8:
            trans = Transformers.Type.Integer.AsInt8(isSigned, isLittleEndian)
        elif self.size == 16:
            trans = Transformers.Type.Integer.AsInt16(isSigned, isLittleEndian)
        elif self.size == 24:
            trans = Transformers.Type.Integer.AsInt24(isSigned, isLittleEndian)
        elif self.size == 32:
            trans = Transformers.Type.Integer.AsInt32(isSigned, isLittleEndian)
        elif self.size == 64:
            trans = Transformers.Type.Integer.AsInt64(isSigned, isLittleEndian)

        # 2. Encode number

        try:
            # This could fail if our override was not
            # a number or empty ('')
            num = int(num)
        except:
            num = 0

        return trans.encode(int(num)) 
Example #13
Source File: dom.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def unpack(self, buff):
        """
        Unpack a number from proper format fo this Number
        """
        # 1. Get the transformer we need
        isSigned = 0
        if self.signed:
            isSigned = 1

        isLittleEndian = 0
        if self.endian == 'little':
            isLittleEndian = 1

        if self.size == 8:
            trans = Transformers.Type.Integer.AsInt8(isSigned, isLittleEndian)
        elif self.size == 16:
            trans = Transformers.Type.Integer.AsInt16(isSigned, isLittleEndian)
        elif self.size == 24:
            trans = Transformers.Type.Integer.AsInt24(isSigned, isLittleEndian)
        elif self.size == 32:
            trans = Transformers.Type.Integer.AsInt32(isSigned, isLittleEndian)
        elif self.size == 64:
            trans = Transformers.Type.Integer.AsInt64(isSigned, isLittleEndian)

        # 2. Encode number

        try:
            # This could fail if our override was not
            # a number or empty ('')
            return trans.decode(buff)

        except:
            pass

        return 0 
Example #14
Source File: ASN1.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def realEncode(self, data):
            return der.encoder.encode(univ.Integer(int(data))) 
Example #15
Source File: ASN1.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def realEncode(self, data):
            return ber.encoder.encode(univ.Integer(int(data))) 
Example #16
Source File: fields.py    From PGPy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __sig__(self):
        # return the signature data into an ASN.1 sequence of integers in DER format
        seq = Sequence(componentType=NamedTypes(*[NamedType(n, Integer()) for n in self.__mpis__]))
        for n in self.__mpis__:
            seq.setComponentByName(n, getattr(self, n))

        return encoder.encode(seq) 
Example #17
Source File: fields.py    From PGPy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def from_signer(self, sig):
        ##TODO: just use pyasn1 for this
        def _der_intf(_asn):
            if _asn[0] != 0x02:  # pragma: no cover
                raise ValueError("Expected: Integer (0x02). Got: 0x{:02X}".format(_asn[0]))
            del _asn[0]

            if _asn[0] & 0x80:  # pragma: no cover
                llen = _asn[0] & 0x7F
                del _asn[0]

                flen = self.bytes_to_int(_asn[:llen])
                del _asn[:llen]

            else:
                flen = _asn[0] & 0x7F
                del _asn[0]

            i = self.bytes_to_int(_asn[:flen])
            del _asn[:flen]
            return i

        if isinstance(sig, bytes):
            sig = bytearray(sig)

        # this is a very limited asn1 decoder - it is only intended to decode a DER encoded sequence of integers
        if not sig[0] == 0x30:
            raise NotImplementedError("Expected: Sequence (0x30). Got: 0x{:02X}".format(sig[0]))
        del sig[0]

        # skip the sequence length field
        if sig[0] & 0x80:  # pragma: no cover
            llen = sig[0] & 0x7F
            del sig[:llen + 1]

        else:
            del sig[0]

        self.r = MPI(_der_intf(sig))
        self.s = MPI(_der_intf(sig)) 
Example #18
Source File: asn1.py    From Slackor with GNU General Public License v3.0 5 votes vote down vote up
def _vno_component(tag_value, name="pvno"):
    return _sequence_component(
        name, tag_value, univ.Integer(),
        subtypeSpec=constraint.ValueRangeConstraint(5, 5)) 
Example #19
Source File: asn1.py    From Slackor with GNU General Public License v3.0 5 votes vote down vote up
def _msg_type_component(tag_value, values):
    c = constraint.ConstraintsUnion(
        *(constraint.SingleValueConstraint(int(v)) for v in values))
    return _sequence_component('msg-type', tag_value, univ.Integer(),
                               subtypeSpec=c) 
Example #20
Source File: key.py    From plugin.video.bdyun with GNU General Public License v3.0 5 votes vote down vote up
def _save_pkcs1_der(self):
        """Saves the private key in PKCS#1 DER format.

        @returns: the DER-encoded private key.
        """

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                    namedtype.NamedType('version', univ.Integer()),
                    namedtype.NamedType('modulus', univ.Integer()),
                    namedtype.NamedType('publicExponent', univ.Integer()),
                    namedtype.NamedType('privateExponent', univ.Integer()),
                    namedtype.NamedType('prime1', univ.Integer()),
                    namedtype.NamedType('prime2', univ.Integer()),
                    namedtype.NamedType('exponent1', univ.Integer()),
                    namedtype.NamedType('exponent2', univ.Integer()),
                    namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
        asn_key.setComponentByName('privateExponent', self.d)
        asn_key.setComponentByName('prime1', self.p)
        asn_key.setComponentByName('prime2', self.q)
        asn_key.setComponentByName('exponent1', self.exp1)
        asn_key.setComponentByName('exponent2', self.exp2)
        asn_key.setComponentByName('coefficient', self.coef)

        return encoder.encode(asn_key) 
Example #21
Source File: key.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def _save_pkcs1_der(self):
        """Saves the private key in PKCS#1 DER format.

        @returns: the DER-encoded private key.
        """

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                    namedtype.NamedType('version', univ.Integer()),
                    namedtype.NamedType('modulus', univ.Integer()),
                    namedtype.NamedType('publicExponent', univ.Integer()),
                    namedtype.NamedType('privateExponent', univ.Integer()),
                    namedtype.NamedType('prime1', univ.Integer()),
                    namedtype.NamedType('prime2', univ.Integer()),
                    namedtype.NamedType('exponent1', univ.Integer()),
                    namedtype.NamedType('exponent2', univ.Integer()),
                    namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
        asn_key.setComponentByName('privateExponent', self.d)
        asn_key.setComponentByName('prime1', self.p)
        asn_key.setComponentByName('prime2', self.q)
        asn_key.setComponentByName('exponent1', self.exp1)
        asn_key.setComponentByName('exponent2', self.exp2)
        asn_key.setComponentByName('coefficient', self.coef)

        return encoder.encode(asn_key) 
Example #22
Source File: key.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def _save_pkcs1_der(self):
        """Saves the private key in PKCS#1 DER format.

        @returns: the DER-encoded private key.
        """

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                    namedtype.NamedType('version', univ.Integer()),
                    namedtype.NamedType('modulus', univ.Integer()),
                    namedtype.NamedType('publicExponent', univ.Integer()),
                    namedtype.NamedType('privateExponent', univ.Integer()),
                    namedtype.NamedType('prime1', univ.Integer()),
                    namedtype.NamedType('prime2', univ.Integer()),
                    namedtype.NamedType('exponent1', univ.Integer()),
                    namedtype.NamedType('exponent2', univ.Integer()),
                    namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
        asn_key.setComponentByName('privateExponent', self.d)
        asn_key.setComponentByName('prime1', self.p)
        asn_key.setComponentByName('prime2', self.q)
        asn_key.setComponentByName('exponent1', self.exp1)
        asn_key.setComponentByName('exponent2', self.exp2)
        asn_key.setComponentByName('coefficient', self.coef)

        return encoder.encode(asn_key) 
Example #23
Source File: asn1.py    From PiBunny with MIT License 5 votes vote down vote up
def _vno_component(tag_value, name="pvno"):
    return _sequence_component(
        name, tag_value, univ.Integer(),
        subtypeSpec=constraint.ValueRangeConstraint(5, 5)) 
Example #24
Source File: asn1.py    From PiBunny with MIT License 5 votes vote down vote up
def _msg_type_component(tag_value, values):
    c = constraint.ConstraintsUnion(
        *(constraint.SingleValueConstraint(int(v)) for v in values))
    return _sequence_component('msg-type', tag_value, univ.Integer(),
                               subtypeSpec=c) 
Example #25
Source File: partition_entry_count.py    From teleport with Apache License 2.0 5 votes vote down vote up
def populate_result(self):
        substrate = self.decoded_response
        try:
            decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
            self.result['entry_count'] = int(decoded)
        except Exception:
            raise LDAPExtensionError('unable to decode substrate')

        if substrate:
            raise LDAPExtensionError('unknown substrate remaining') 
Example #26
Source File: asn1.py    From CVE-2017-7494 with GNU General Public License v3.0 5 votes vote down vote up
def _msg_type_component(tag_value, values):
    c = constraint.ConstraintsUnion(
        *(constraint.SingleValueConstraint(int(v)) for v in values))
    return _sequence_component('msg-type', tag_value, univ.Integer(),
                               subtypeSpec=c) 
Example #27
Source File: asn1.py    From cracke-dit with MIT License 5 votes vote down vote up
def _vno_component(tag_value, name="pvno"):
    return _sequence_component(
        name, tag_value, univ.Integer(),
        subtypeSpec=constraint.ValueRangeConstraint(5, 5)) 
Example #28
Source File: asn1.py    From cracke-dit with MIT License 5 votes vote down vote up
def _msg_type_component(tag_value, values):
    c = constraint.ConstraintsUnion(
        *(constraint.SingleValueConstraint(int(v)) for v in values))
    return _sequence_component('msg-type', tag_value, univ.Integer(),
                               subtypeSpec=c) 
Example #29
Source File: microsoft.py    From teleport with Apache License 2.0 5 votes vote down vote up
def extended_dn_control(criticality=False, hex_format=False):
    control_value = ExtendedDN()
    control_value.setComponentByName('option', Integer(not hex_format))
    return build_control('1.2.840.113556.1.4.529', criticality, control_value) 
Example #30
Source File: persistentSearch.py    From teleport with Apache License 2.0 5 votes vote down vote up
def persistent_search_control(change_types, changes_only=True, return_ecs=True, criticality=False):
    control_value = PersistentSearchControl()
    control_value.setComponentByName('changeTypes', Integer(change_types))
    control_value.setComponentByName('changesOnly', Boolean(changes_only))
    control_value.setComponentByName('returnECs', Boolean(return_ecs))
    return build_control('2.16.840.1.113730.3.4.3', criticality, control_value)