public override int BerDecode(IAsn1DecodingBuffer buffer, bool explicitTag = true)
        {
            int headLen = 0;
            Asn1Tag seqTag;
            headLen += TagBerDecode(buffer, out seqTag);
            int valueLen;
            headLen += LengthBerDecode(buffer, out valueLen);

            int valueLenDecode = 0;
            resultCode = new LDAPResult_resultCode();
            valueLenDecode += resultCode.BerDecode(buffer);
            matchedDN = new LDAPDN();
            valueLenDecode += matchedDN.BerDecode(buffer);
            errorMessage = new LDAPString();
            valueLenDecode += errorMessage.BerDecode(buffer);
            if (valueLenDecode == valueLen)
            {
                referral = null;
                serverSaslCreds = null;
            }
            else
            {
                Asn1Tag contextTag;
                valueLenDecode += TagBerDecode(buffer, out contextTag);
                if (contextTag.TagValue == 3)
                {
                    //referral
                    referral = new Referral();
                    valueLenDecode += referral.BerDecodeWithoutUnisersalTag(buffer);
                    if (valueLenDecode < valueLen)
                    {
                        valueLenDecode += TagBerDecode(buffer, out contextTag);
                    }
                }
                if (contextTag.TagValue == 7)
                {
                    //serverSaslCreds
                    serverSaslCreds = new Asn1OctetString();
                    valueLenDecode += serverSaslCreds.BerDecodeWithoutUnisersalTag(buffer);
                }
               }
            if (valueLen != valueLenDecode)
            {
                throw new Asn1DecodingUnexpectedData(ExceptionMessages.DecodingUnexpectedData + " BindResponse.");
            }
            return headLen + valueLen;
        }
 public override int BerDecode(IAsn1DecodingBuffer buffer, bool explicitTag = true)
 {
     int allLen = 0;
     Asn1Tag contextTag;
     allLen += TagBerDecode(buffer, out contextTag);
     switch (contextTag.TagValue)
     {
         case 0:
             field0 = new Asn1OctetString();
             allLen += field0.BerDecodeWithoutUnisersalTag(buffer);
             SetData(0, field0);
             break;
         case 3:
             field1 = new SaslCredentials();
             allLen += field1.BerDecodeWithoutUnisersalTag(buffer);
             SetData(1, field1);
             break;
         case 9:
             field2 = new Asn1OctetString();
             allLen += field2.BerDecodeWithoutUnisersalTag(buffer);
             SetData(2, field2);
             break;
         case 10:
             field3 = new Asn1OctetString();
             allLen += field3.BerDecodeWithoutUnisersalTag(buffer);
             SetData(3, field3);
             break;
         case 11:
             field4 = new Asn1OctetString();
             allLen += field4.BerDecodeWithoutUnisersalTag(buffer);
             SetData(4, field4);
             break;
         default:
             throw new Asn1DecodingUnexpectedData(ExceptionMessages.DecodingUnexpectedData + " AuthenticationChoice");
     }
     return allLen;
 }