How to use the ldaptor.protocols.pureber.BEROctetString function in ldaptor

To help you get started, we’ve selected a few ldaptor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twisted / ldaptor / tests / test_pureber.py View on Github external
def testToBEROctetStringKnownValues(self):
        """str(BEROctetString(n)) should give known result with known input"""
        for st, encoded in self.knownValues:
            result = pureber.BEROctetString(st)
            result = str(result)
            result = map(ord, result)
            assert encoded==result
github twisted / ldaptor / tests / test_pureber.py View on Github external
def testSanity(self):
        """BEROctetString(encoded=BEROctetString(n*'x')).value==n*'x' for some values of n"""
        for n in 0,1,2,3,4,5,6,100,126,127,128,129,1000,2000:
            encoded = MutableString(pureber.BEROctetString(n*'x'))
            encoded.append('foo')
            result = pureber.BEROctetString(encoded=encoded, berdecoder=pureber.BERDecoderContext())
            result = result.value
            assert encoded=='foo'
            assert n*'x'==result
github twisted / ldaptor / ldaptor / protocols / pureldap.py View on Github external
def toWire(self):
        self.data = [LDAPOID(self.controlType)]
        if self.criticality is not None:
            self.data.append(BERBoolean(self.criticality))
        if self.controlValue is not None:
            self.data.append(BEROctetString(self.controlValue))
        return BERSequence.toWire(self)
github twisted / ldaptor / ldaptor / protocols / pureldap.py View on Github external
return '(%s=*)' % self.value


class LDAPFilter_approxMatch(LDAPAttributeValueAssertion):
    tag = CLASS_CONTEXT | 0x08

    def asText(self):
        return '(' + self.attributeDesc.value + '~=' + \
               self.escaper(self.assertionValue.value) + ')'


class LDAPMatchingRuleId(LDAPString):
    pass


class LDAPAssertionValue(BEROctetString):
    pass


class LDAPMatchingRuleAssertion_matchingRule(LDAPMatchingRuleId):
    tag = CLASS_CONTEXT | 0x01
    pass


class LDAPMatchingRuleAssertion_type(LDAPAttributeDescription):
    tag = CLASS_CONTEXT | 0x02
    pass


class LDAPMatchingRuleAssertion_matchValue(LDAPAssertionValue):
    tag = CLASS_CONTEXT | 0x03
    pass
github twisted / ldaptor / ldaptor / protocols / pureldap.py View on Github external
assert requestName is not None
        assert isinstance(requestName, (six.binary_type, six.text_type))
        assert requestValue is None or isinstance(
            requestValue, (six.binary_type, six.text_type))
        self.requestName = requestName
        self.requestValue = requestValue

    def toWire(self):
        l = [LDAPOID(self.requestName, tag=CLASS_CONTEXT | 0)]
        if self.requestValue is not None:
            value = to_bytes(self.requestValue)
            l.append(BEROctetString(value, tag=CLASS_CONTEXT | 1))
        return BERSequence(l, tag=self.tag).toWire()


class LDAPPasswordModifyRequest_userIdentity(BEROctetString):
    tag = CLASS_CONTEXT | 0


class LDAPPasswordModifyRequest_passwd(BEROctetString):
    def __repr__(self):
        value = '*' * len(self.value)
        return '{}(value={}{})'.format(
            self.__class__.__name__,
            repr(value),
            ', tag={}'.format(self.tag) if self.tag != self.__class__.tag else '',
        )


class LDAPPasswordModifyRequest_oldPasswd(LDAPPasswordModifyRequest_passwd):
    tag = CLASS_CONTEXT | 1
github twisted / ldaptor / ldaptor / protocols / pureldap.py View on Github external
def toWire(self):
        assert self.referral is None  # TODO
        if self.serverSaslCreds:
            return BERSequence([
                BEREnumerated(self.resultCode),
                BEROctetString(self.matchedDN),
                BEROctetString(self.errorMessage),
                LDAPBindResponse_serverSaslCreds(self.serverSaslCreds)],
                tag=self.tag).toWire()
        else:
            return BERSequence([
                BEREnumerated(self.resultCode),
                BEROctetString(self.matchedDN),
                BEROctetString(self.errorMessage)],
                tag=self.tag).toWire()
github twisted / ldaptor / ldaptor / protocols / pureldap.py View on Github external
return LDAPResult.__repr__(self)


class LDAPUnbindRequest(LDAPProtocolRequest, BERNull):
    tag = CLASS_APPLICATION | 0x02
    needs_answer = 0

    def __init__(self, *args, **kwargs):
        LDAPProtocolRequest.__init__(self)
        BERNull.__init__(self, *args, **kwargs)

    def toWire(self):
        return BERNull.toWire(self)


class LDAPAttributeDescription(BEROctetString):
    pass


class LDAPAttributeValueAssertion(BERSequence):
    @classmethod
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)
        assert len(l) == 2

        r = klass(attributeDesc=l[0],
                  assertionValue=l[1],
                  tag=tag)
        return r

    def __init__(self, attributeDesc=None, assertionValue=None, tag=None, escaper=escape):
        BERSequence.__init__(self, value=[], tag=tag)
github twisted / ldaptor / ldaptor / protocols / pureldap.py View on Github external
binary_count = sum(c not in string.printable for c in s)
    if float(binary_count) / float(len(s)) > threshold:
        return binary_escape(s)

    return escape(s)

class LDAPInteger(BERInteger):
    pass


class LDAPString(BEROctetString):
    def __init__(self, *args, **kwargs):
        self.escaper = kwargs.pop('escaper', escape)
        super(LDAPString, self).__init__(*args, **kwargs)

class LDAPAttributeValue(BEROctetString):
    pass


class LDAPMessage(BERSequence):
    """
    To encode this object in order to be sent over the network use the toWire()
    method.
    """
    id = None
    value = None

    @classmethod
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        id_ = l[0].value
github twisted / ldaptor / ldaptor / protocols / pureldap.py View on Github external
class LDAPOID(BEROctetString):
    pass


class LDAPResponseName(LDAPOID):
    tag = CLASS_CONTEXT | 10


class LDAPResponse(BEROctetString):
    tag = CLASS_CONTEXT | 11


class LDAPBERDecoderContext_LDAPExtendedRequest(BERDecoderContext):
    Identities = {
        CLASS_CONTEXT | 0x00: BEROctetString,
        CLASS_CONTEXT | 0x01: BEROctetString,
        }


class LDAPExtendedRequest(LDAPProtocolRequest, BERSequence):
    tag = CLASS_APPLICATION | 23

    requestName = None
    requestValue = None

    @classmethod
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content,
                              LDAPBERDecoderContext_LDAPExtendedRequest(
                                  fallback=berdecoder))

        kw = {}