#include <string.h>
#include "ldap.h"
#include <str.h>
#include <rangecheck.h>
size_t fmt_ldapbindrequest(char* dest,long version,const char* name,const char* simple) {
size_t l,sum;
size_t nlen=str_len(name);
sum=l=fmt_asn1INTEGER(dest,version);
if (dest) dest+=l;
l=fmt_asn1OCTETSTRING(dest,name,nlen);
if (add_of(sum,sum,l)) return (size_t)-1;
if (dest) dest+=l;
// sum+=l; if (dest) dest+=l;
nlen=str_len(simple);
l=fmt_asn1string(dest,CONTEXT_SPECIFIC,PRIMITIVE,0,simple,nlen);
if (add_of(sum,sum,l)) return (size_t)-1;
return sum;
}
size_t fmt_ldapbindrequeststring(char* dest,long version,const struct string* name,const struct string* simple) {
size_t l,sum;
sum=l=fmt_asn1INTEGER(dest,version);
if (dest) dest+=l;
l=fmt_asn1OCTETSTRING(dest,name->s,name->l);
if (add_of(sum,sum,l)) return (size_t)-1;
if (dest) dest+=l;
// sum+=l; if (dest) dest+=l;
l=fmt_asn1string(dest,CONTEXT_SPECIFIC,PRIMITIVE,0,simple->s,simple->l);
if (add_of(sum,sum,l)) return (size_t)-1;
return sum;
}