Advertisement
Guest User

wat

a guest
Jun 6th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 96.91 KB | None | 0 0
  1. %% Generated by the Erlang ASN.1 BER compiler. Version: 5.0.5
  2. %% Purpose: Encoding and decoding of the types in Lightweight-Directory-Access-Protocol-V3.
  3.  
  4. -module('Lightweight-Directory-Access-Protocol-V3').
  5. -compile(nowarn_unused_vars).
  6. -dialyzer(no_improper_lists).
  7. -include("Lightweight-Directory-Access-Protocol-V3.hrl").
  8. -asn1_info([{vsn,'5.0.5'},
  9.             {module,'Lightweight-Directory-Access-Protocol-V3'},
  10.             {options,[ber,{i,"."}]}]).
  11.  
  12. -export([encoding_rule/0,maps/0,bit_string_format/0,
  13.          legacy_erlang_types/0]).
  14. -export(['dialyzer-suppressions'/1]).
  15. -export([
  16. enc_LDAPMessage/2,
  17. enc_MessageID/2,
  18. enc_LDAPString/2,
  19. enc_LDAPOID/2,
  20. enc_LDAPDN/2,
  21. enc_RelativeLDAPDN/2,
  22. enc_AttributeDescription/2,
  23. enc_AttributeValue/2,
  24. enc_AttributeValueAssertion/2,
  25. enc_AssertionValue/2,
  26. enc_PartialAttribute/2,
  27. enc_Attribute/2,
  28. enc_MatchingRuleId/2,
  29. enc_LDAPResult/2,
  30. enc_Referral/2,
  31. enc_URI/2,
  32. enc_Controls/2,
  33. enc_Control/2,
  34. enc_BindRequest/2,
  35. enc_AuthenticationChoice/2,
  36. enc_SaslCredentials/2,
  37. enc_BindResponse/2,
  38. enc_UnbindRequest/2,
  39. enc_SearchRequest/2,
  40. enc_AttributeSelection/2,
  41. enc_Filter/2,
  42. enc_SubstringFilter/2,
  43. enc_MatchingRuleAssertion/2,
  44. enc_SearchResultEntry/2,
  45. enc_PartialAttributeList/2,
  46. enc_SearchResultReference/2,
  47. enc_SearchResultDone/2,
  48. enc_ModifyRequest/2,
  49. enc_ModifyResponse/2,
  50. enc_AddRequest/2,
  51. enc_AttributeList/2,
  52. enc_AddResponse/2,
  53. enc_DelRequest/2,
  54. enc_DelResponse/2,
  55. enc_ModifyDNRequest/2,
  56. enc_ModifyDNResponse/2,
  57. enc_CompareRequest/2,
  58. enc_CompareResponse/2,
  59. enc_AbandonRequest/2,
  60. enc_ExtendedRequest/2,
  61. enc_ExtendedResponse/2,
  62. enc_IntermediateResponse/2
  63. ]).
  64.  
  65. -export([
  66. dec_LDAPMessage/2,
  67. dec_MessageID/2,
  68. dec_LDAPString/2,
  69. dec_LDAPOID/2,
  70. dec_LDAPDN/2,
  71. dec_RelativeLDAPDN/2,
  72. dec_AttributeDescription/2,
  73. dec_AttributeValue/2,
  74. dec_AttributeValueAssertion/2,
  75. dec_AssertionValue/2,
  76. dec_PartialAttribute/2,
  77. dec_Attribute/2,
  78. dec_MatchingRuleId/2,
  79. dec_LDAPResult/2,
  80. dec_Referral/2,
  81. dec_URI/2,
  82. dec_Controls/2,
  83. dec_Control/2,
  84. dec_BindRequest/2,
  85. dec_AuthenticationChoice/2,
  86. dec_SaslCredentials/2,
  87. dec_BindResponse/2,
  88. dec_UnbindRequest/2,
  89. dec_SearchRequest/2,
  90. dec_AttributeSelection/2,
  91. dec_Filter/2,
  92. dec_SubstringFilter/2,
  93. dec_MatchingRuleAssertion/2,
  94. dec_SearchResultEntry/2,
  95. dec_PartialAttributeList/2,
  96. dec_SearchResultReference/2,
  97. dec_SearchResultDone/2,
  98. dec_ModifyRequest/2,
  99. dec_ModifyResponse/2,
  100. dec_AddRequest/2,
  101. dec_AttributeList/2,
  102. dec_AddResponse/2,
  103. dec_DelRequest/2,
  104. dec_DelResponse/2,
  105. dec_ModifyDNRequest/2,
  106. dec_ModifyDNResponse/2,
  107. dec_CompareRequest/2,
  108. dec_CompareResponse/2,
  109. dec_AbandonRequest/2,
  110. dec_ExtendedRequest/2,
  111. dec_ExtendedResponse/2,
  112. dec_IntermediateResponse/2
  113. ]).
  114.  
  115. -export([
  116. maxInt/0
  117. ]).
  118.  
  119. -export([info/0]).
  120.  
  121. -export([encode/2,decode/2]).
  122.  
  123. encoding_rule() -> ber.
  124.  
  125. maps() -> false.
  126.  
  127. bit_string_format() -> bitstring.
  128.  
  129. legacy_erlang_types() -> false.
  130.  
  131. encode(Type, Data) ->
  132. try iolist_to_binary(element(1, encode_disp(Type, Data))) of
  133.   Bytes ->
  134.     {ok,Bytes}
  135.   catch
  136.     Class:Exception when Class =:= error; Class =:= exit ->
  137.       Stk = erlang:get_stacktrace(),
  138.       case Exception of
  139.         {error,{asn1,Reason}} ->
  140.           {error,{asn1,{Reason,Stk}}};
  141.         Reason ->
  142.          {error,{asn1,{Reason,Stk}}}
  143.       end
  144. end.
  145.  
  146. decode(Type, Data) ->
  147. try
  148.    Result = decode_disp(Type, element(1, ber_decode_nif(Data))),
  149.    {ok,Result}
  150.   catch
  151.     Class:Exception when Class =:= error; Class =:= exit ->
  152.       Stk = erlang:get_stacktrace(),
  153.       case Exception of
  154.         {error,{asn1,Reason}} ->
  155.           {error,{asn1,{Reason,Stk}}};
  156.         Reason ->
  157.          {error,{asn1,{Reason,Stk}}}
  158.       end
  159. end.
  160.  
  161. encode_disp('LDAPMessage', Data) -> enc_LDAPMessage(Data);
  162. encode_disp('MessageID', Data) -> enc_MessageID(Data);
  163. encode_disp('LDAPString', Data) -> enc_LDAPString(Data);
  164. encode_disp('LDAPOID', Data) -> enc_LDAPOID(Data);
  165. encode_disp('LDAPDN', Data) -> enc_LDAPDN(Data);
  166. encode_disp('RelativeLDAPDN', Data) -> enc_RelativeLDAPDN(Data);
  167. encode_disp('AttributeDescription', Data) -> enc_AttributeDescription(Data);
  168. encode_disp('AttributeValue', Data) -> enc_AttributeValue(Data);
  169. encode_disp('AttributeValueAssertion', Data) -> enc_AttributeValueAssertion(Data);
  170. encode_disp('AssertionValue', Data) -> enc_AssertionValue(Data);
  171. encode_disp('PartialAttribute', Data) -> enc_PartialAttribute(Data);
  172. encode_disp('Attribute', Data) -> enc_Attribute(Data);
  173. encode_disp('MatchingRuleId', Data) -> enc_MatchingRuleId(Data);
  174. encode_disp('LDAPResult', Data) -> enc_LDAPResult(Data);
  175. encode_disp('Referral', Data) -> enc_Referral(Data);
  176. encode_disp('URI', Data) -> enc_URI(Data);
  177. encode_disp('Controls', Data) -> enc_Controls(Data);
  178. encode_disp('Control', Data) -> enc_Control(Data);
  179. encode_disp('BindRequest', Data) -> enc_BindRequest(Data);
  180. encode_disp('AuthenticationChoice', Data) -> enc_AuthenticationChoice(Data);
  181. encode_disp('SaslCredentials', Data) -> enc_SaslCredentials(Data);
  182. encode_disp('BindResponse', Data) -> enc_BindResponse(Data);
  183. encode_disp('UnbindRequest', Data) -> enc_UnbindRequest(Data);
  184. encode_disp('SearchRequest', Data) -> enc_SearchRequest(Data);
  185. encode_disp('AttributeSelection', Data) -> enc_AttributeSelection(Data);
  186. encode_disp('Filter', Data) -> enc_Filter(Data);
  187. encode_disp('SubstringFilter', Data) -> enc_SubstringFilter(Data);
  188. encode_disp('MatchingRuleAssertion', Data) -> enc_MatchingRuleAssertion(Data);
  189. encode_disp('SearchResultEntry', Data) -> enc_SearchResultEntry(Data);
  190. encode_disp('PartialAttributeList', Data) -> enc_PartialAttributeList(Data);
  191. encode_disp('SearchResultReference', Data) -> enc_SearchResultReference(Data);
  192. encode_disp('SearchResultDone', Data) -> enc_SearchResultDone(Data);
  193. encode_disp('ModifyRequest', Data) -> enc_ModifyRequest(Data);
  194. encode_disp('ModifyResponse', Data) -> enc_ModifyResponse(Data);
  195. encode_disp('AddRequest', Data) -> enc_AddRequest(Data);
  196. encode_disp('AttributeList', Data) -> enc_AttributeList(Data);
  197. encode_disp('AddResponse', Data) -> enc_AddResponse(Data);
  198. encode_disp('DelRequest', Data) -> enc_DelRequest(Data);
  199. encode_disp('DelResponse', Data) -> enc_DelResponse(Data);
  200. encode_disp('ModifyDNRequest', Data) -> enc_ModifyDNRequest(Data);
  201. encode_disp('ModifyDNResponse', Data) -> enc_ModifyDNResponse(Data);
  202. encode_disp('CompareRequest', Data) -> enc_CompareRequest(Data);
  203. encode_disp('CompareResponse', Data) -> enc_CompareResponse(Data);
  204. encode_disp('AbandonRequest', Data) -> enc_AbandonRequest(Data);
  205. encode_disp('ExtendedRequest', Data) -> enc_ExtendedRequest(Data);
  206. encode_disp('ExtendedResponse', Data) -> enc_ExtendedResponse(Data);
  207. encode_disp('IntermediateResponse', Data) -> enc_IntermediateResponse(Data);
  208. encode_disp(Type, _Data) -> exit({error,{asn1,{undefined_type,Type}}}).
  209.  
  210. decode_disp('LDAPMessage', Data) -> dec_LDAPMessage(Data);
  211. decode_disp('MessageID', Data) -> dec_MessageID(Data);
  212. decode_disp('LDAPString', Data) -> dec_LDAPString(Data);
  213. decode_disp('LDAPOID', Data) -> dec_LDAPOID(Data);
  214. decode_disp('LDAPDN', Data) -> dec_LDAPDN(Data);
  215. decode_disp('RelativeLDAPDN', Data) -> dec_RelativeLDAPDN(Data);
  216. decode_disp('AttributeDescription', Data) -> dec_AttributeDescription(Data);
  217. decode_disp('AttributeValue', Data) -> dec_AttributeValue(Data);
  218. decode_disp('AttributeValueAssertion', Data) -> dec_AttributeValueAssertion(Data);
  219. decode_disp('AssertionValue', Data) -> dec_AssertionValue(Data);
  220. decode_disp('PartialAttribute', Data) -> dec_PartialAttribute(Data);
  221. decode_disp('Attribute', Data) -> dec_Attribute(Data);
  222. decode_disp('MatchingRuleId', Data) -> dec_MatchingRuleId(Data);
  223. decode_disp('LDAPResult', Data) -> dec_LDAPResult(Data);
  224. decode_disp('Referral', Data) -> dec_Referral(Data);
  225. decode_disp('URI', Data) -> dec_URI(Data);
  226. decode_disp('Controls', Data) -> dec_Controls(Data);
  227. decode_disp('Control', Data) -> dec_Control(Data);
  228. decode_disp('BindRequest', Data) -> dec_BindRequest(Data);
  229. decode_disp('AuthenticationChoice', Data) -> dec_AuthenticationChoice(Data);
  230. decode_disp('SaslCredentials', Data) -> dec_SaslCredentials(Data);
  231. decode_disp('BindResponse', Data) -> dec_BindResponse(Data);
  232. decode_disp('UnbindRequest', Data) -> dec_UnbindRequest(Data);
  233. decode_disp('SearchRequest', Data) -> dec_SearchRequest(Data);
  234. decode_disp('AttributeSelection', Data) -> dec_AttributeSelection(Data);
  235. decode_disp('Filter', Data) -> dec_Filter(Data);
  236. decode_disp('SubstringFilter', Data) -> dec_SubstringFilter(Data);
  237. decode_disp('MatchingRuleAssertion', Data) -> dec_MatchingRuleAssertion(Data);
  238. decode_disp('SearchResultEntry', Data) -> dec_SearchResultEntry(Data);
  239. decode_disp('PartialAttributeList', Data) -> dec_PartialAttributeList(Data);
  240. decode_disp('SearchResultReference', Data) -> dec_SearchResultReference(Data);
  241. decode_disp('SearchResultDone', Data) -> dec_SearchResultDone(Data);
  242. decode_disp('ModifyRequest', Data) -> dec_ModifyRequest(Data);
  243. decode_disp('ModifyResponse', Data) -> dec_ModifyResponse(Data);
  244. decode_disp('AddRequest', Data) -> dec_AddRequest(Data);
  245. decode_disp('AttributeList', Data) -> dec_AttributeList(Data);
  246. decode_disp('AddResponse', Data) -> dec_AddResponse(Data);
  247. decode_disp('DelRequest', Data) -> dec_DelRequest(Data);
  248. decode_disp('DelResponse', Data) -> dec_DelResponse(Data);
  249. decode_disp('ModifyDNRequest', Data) -> dec_ModifyDNRequest(Data);
  250. decode_disp('ModifyDNResponse', Data) -> dec_ModifyDNResponse(Data);
  251. decode_disp('CompareRequest', Data) -> dec_CompareRequest(Data);
  252. decode_disp('CompareResponse', Data) -> dec_CompareResponse(Data);
  253. decode_disp('AbandonRequest', Data) -> dec_AbandonRequest(Data);
  254. decode_disp('ExtendedRequest', Data) -> dec_ExtendedRequest(Data);
  255. decode_disp('ExtendedResponse', Data) -> dec_ExtendedResponse(Data);
  256. decode_disp('IntermediateResponse', Data) -> dec_IntermediateResponse(Data);
  257. decode_disp(Type, _Data) -> exit({error,{asn1,{undefined_type,Type}}}).
  258.  
  259. info() ->
  260.    case ?MODULE:module_info(attributes) of
  261.      Attributes when is_list(Attributes) ->
  262.        case lists:keyfind(asn1_info, 1, Attributes) of
  263.          {_,Info} when is_list(Info) ->
  264.            Info;
  265.          _ ->
  266.            []
  267.        end;
  268.      _ ->
  269.        []
  270.    end.
  271.  
  272.  
  273. %%================================
  274. %%  LDAPMessage
  275. %%================================
  276. enc_LDAPMessage(Val) ->
  277.     enc_LDAPMessage(Val, [<<48>>]).
  278.  
  279. enc_LDAPMessage(Val, TagIn) ->
  280. {_,Cindex1,Cindex2,Cindex3} = Val,
  281.  
  282. %%-------------------------------------------------
  283. %% attribute messageID(1) with type INTEGER
  284. %%-------------------------------------------------
  285.    {EncBytes1,EncLen1} = encode_integer(Cindex1, [<<2>>]),
  286.  
  287. %%-------------------------------------------------
  288. %% attribute protocolOp(2) with type CHOICE
  289. %%-------------------------------------------------
  290.    {EncBytes2,EncLen2} = 'enc_LDAPMessage_protocolOp'(Cindex2, []),
  291.  
  292. %%-------------------------------------------------
  293. %% attribute controls(3)   External Lightweight-Directory-Access-Protocol-V3:Controls OPTIONAL
  294. %%-------------------------------------------------
  295.    {EncBytes3,EncLen3} =  case Cindex3 of
  296.          asn1_NOVALUE -> {<<>>,0};
  297.          _ ->
  298.             'enc_Controls'(Cindex3, [<<160>>])
  299.        end,
  300.  
  301.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
  302. LenSoFar = EncLen1 + EncLen2 + EncLen3,
  303. encode_tags(TagIn, BytesSoFar, LenSoFar).
  304.  
  305.  
  306.  
  307. %%================================
  308. %%  LDAPMessage_protocolOp
  309. %%================================
  310. enc_LDAPMessage_protocolOp(Val, TagIn) ->
  311.       {EncBytes,EncLen} = case element(1,Val) of
  312.       bindRequest ->
  313.          'enc_BindRequest'(element(2,Val), [<<96>>]);
  314.       bindResponse ->
  315.          'enc_BindResponse'(element(2,Val), [<<97>>]);
  316.       unbindRequest ->
  317.          encode_null(element(2,Val), [<<66>>]);
  318.       searchRequest ->
  319.          'enc_SearchRequest'(element(2,Val), [<<99>>]);
  320.       searchResEntry ->
  321.          'enc_SearchResultEntry'(element(2,Val), [<<100>>]);
  322.       searchResDone ->
  323.          'enc_SearchResultDone'(element(2,Val), [<<101>>]);
  324.       searchResRef ->
  325.          'enc_SearchResultReference'(element(2,Val), [<<115>>]);
  326.       modifyRequest ->
  327.          'enc_ModifyRequest'(element(2,Val), [<<102>>]);
  328.       modifyResponse ->
  329.          'enc_ModifyResponse'(element(2,Val), [<<103>>]);
  330.       addRequest ->
  331.          'enc_AddRequest'(element(2,Val), [<<104>>]);
  332.       addResponse ->
  333.          'enc_AddResponse'(element(2,Val), [<<105>>]);
  334.       delRequest ->
  335.          encode_restricted_string(element(2,Val), [<<74>>]);
  336.       delResponse ->
  337.          'enc_DelResponse'(element(2,Val), [<<107>>]);
  338.       modDNRequest ->
  339.          'enc_ModifyDNRequest'(element(2,Val), [<<108>>]);
  340.       modDNResponse ->
  341.          'enc_ModifyDNResponse'(element(2,Val), [<<109>>]);
  342.       compareRequest ->
  343.          'enc_CompareRequest'(element(2,Val), [<<110>>]);
  344.       compareResponse ->
  345.          'enc_CompareResponse'(element(2,Val), [<<111>>]);
  346.       abandonRequest ->
  347.          encode_integer(element(2,Val), [<<80>>]);
  348.       extendedReq ->
  349.          'enc_ExtendedRequest'(element(2,Val), [<<119>>]);
  350.       extendedResp ->
  351.          'enc_ExtendedResponse'(element(2,Val), [<<120>>]);
  352.       intermediateResponse ->
  353.          'enc_IntermediateResponse'(element(2,Val), [<<121>>]);
  354.       Else ->
  355.          exit({error,{asn1,{invalid_choice_type,Else}}})
  356.    end,
  357.  
  358. encode_tags(TagIn, EncBytes, EncLen).
  359.  
  360.  
  361.  
  362.  
  363. dec_LDAPMessage(Tlv) ->
  364.    dec_LDAPMessage(Tlv, [16]).
  365.  
  366. dec_LDAPMessage(Tlv, TagIn) ->
  367.    %%-------------------------------------------------
  368.    %% decode tag and length
  369.    %%-------------------------------------------------
  370. Tlv1 = match_tags(Tlv, TagIn),
  371.  
  372. %%-------------------------------------------------
  373. %% attribute messageID(1) with type INTEGER
  374. %%-------------------------------------------------
  375. [V1|Tlv2] = Tlv1,
  376. Term1 = begin
  377. Val1 = decode_integer(V1, [2]),
  378. if 0 =< Val1, Val1 =< 2147483647 ->
  379. Val1;
  380. true ->
  381. exit({error,{asn1,bad_range}})
  382. end
  383. end,
  384.  
  385. %%-------------------------------------------------
  386. %% attribute protocolOp(2) with type CHOICE
  387. %%-------------------------------------------------
  388. [V2|Tlv3] = Tlv2,
  389. Term2 = 'dec_LDAPMessage_protocolOp'(V2, []),
  390.  
  391. %%-------------------------------------------------
  392. %% attribute controls(3)   External Lightweight-Directory-Access-Protocol-V3:Controls OPTIONAL
  393. %%-------------------------------------------------
  394. {Term3,Tlv4} = case Tlv3 of
  395. [{131072,V3}|TempTlv4] ->
  396.     {'dec_Controls'(V3, []), TempTlv4};
  397.     _ ->
  398.         { asn1_NOVALUE, Tlv3}
  399. end,
  400.  
  401. case Tlv4 of [] -> true; _ -> true end, % ... extra fields skipped
  402. Res1 = {'LDAPMessage',Term1,Term2,Term3},
  403. Res1.
  404. 'dec_LDAPMessage_protocolOp'(Tlv, TagIn) ->
  405. Tlv1 = match_tags(Tlv, TagIn),
  406. case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
  407.  
  408. %% 'bindRequest'
  409.     {65536, V1} ->
  410.         {bindRequest, 'dec_BindRequest'(V1, [])};
  411.  
  412.  
  413. %% 'bindResponse'
  414.     {65537, V1} ->
  415.         {bindResponse, 'dec_BindResponse'(V1, [])};
  416.  
  417.  
  418. %% 'unbindRequest'
  419.     {65538, V1} ->
  420.         {unbindRequest, decode_null(V1, [])};
  421.  
  422.  
  423. %% 'searchRequest'
  424.     {65539, V1} ->
  425.         {searchRequest, 'dec_SearchRequest'(V1, [])};
  426.  
  427.  
  428. %% 'searchResEntry'
  429.     {65540, V1} ->
  430.         {searchResEntry, 'dec_SearchResultEntry'(V1, [])};
  431.  
  432.  
  433. %% 'searchResDone'
  434.     {65541, V1} ->
  435.         {searchResDone, 'dec_SearchResultDone'(V1, [])};
  436.  
  437.  
  438. %% 'searchResRef'
  439.     {65555, V1} ->
  440.         {searchResRef, 'dec_SearchResultReference'(V1, [])};
  441.  
  442.  
  443. %% 'modifyRequest'
  444.     {65542, V1} ->
  445.         {modifyRequest, 'dec_ModifyRequest'(V1, [])};
  446.  
  447.  
  448. %% 'modifyResponse'
  449.     {65543, V1} ->
  450.         {modifyResponse, 'dec_ModifyResponse'(V1, [])};
  451.  
  452.  
  453. %% 'addRequest'
  454.     {65544, V1} ->
  455.         {addRequest, 'dec_AddRequest'(V1, [])};
  456.  
  457.  
  458. %% 'addResponse'
  459.     {65545, V1} ->
  460.         {addResponse, 'dec_AddResponse'(V1, [])};
  461.  
  462.  
  463. %% 'delRequest'
  464.     {65546, V1} ->
  465.         {delRequest, decode_octet_string(V1, [])};
  466.  
  467.  
  468. %% 'delResponse'
  469.     {65547, V1} ->
  470.         {delResponse, 'dec_DelResponse'(V1, [])};
  471.  
  472.  
  473. %% 'modDNRequest'
  474.     {65548, V1} ->
  475.         {modDNRequest, 'dec_ModifyDNRequest'(V1, [])};
  476.  
  477.  
  478. %% 'modDNResponse'
  479.     {65549, V1} ->
  480.         {modDNResponse, 'dec_ModifyDNResponse'(V1, [])};
  481.  
  482.  
  483. %% 'compareRequest'
  484.     {65550, V1} ->
  485.         {compareRequest, 'dec_CompareRequest'(V1, [])};
  486.  
  487.  
  488. %% 'compareResponse'
  489.     {65551, V1} ->
  490.         {compareResponse, 'dec_CompareResponse'(V1, [])};
  491.  
  492.  
  493. %% 'abandonRequest'
  494.     {65552, V1} ->
  495.         {abandonRequest, begin
  496. Val1 = decode_integer(V1, []),
  497. if 0 =< Val1, Val1 =< 2147483647 ->
  498. Val1;
  499. true ->
  500. exit({error,{asn1,bad_range}})
  501. end
  502. end};
  503.  
  504.  
  505. %% 'extendedReq'
  506.     {65559, V1} ->
  507.         {extendedReq, 'dec_ExtendedRequest'(V1, [])};
  508.  
  509.  
  510. %% 'extendedResp'
  511.     {65560, V1} ->
  512.         {extendedResp, 'dec_ExtendedResponse'(V1, [])};
  513.  
  514.  
  515. %% 'intermediateResponse'
  516.     {65561, V1} ->
  517.         {intermediateResponse, 'dec_IntermediateResponse'(V1, [])};
  518.  
  519.       Else ->
  520.          {asn1_ExtAlt,ber_encode(Else)}
  521.    end
  522. .
  523.  
  524.  
  525. %%================================
  526. %%  MessageID
  527. %%================================
  528. enc_MessageID(Val) ->
  529.     enc_MessageID(Val, [<<2>>]).
  530.  
  531. enc_MessageID(Val, TagIn) ->
  532. encode_integer(Val, TagIn).
  533.  
  534.  
  535. dec_MessageID(Tlv) ->
  536.    dec_MessageID(Tlv, [2]).
  537.  
  538. dec_MessageID(Tlv, TagIn) ->
  539. begin
  540. Val1 = decode_integer(Tlv, TagIn),
  541. if 0 =< Val1, Val1 =< 2147483647 ->
  542. Val1;
  543. true ->
  544. exit({error,{asn1,bad_range}})
  545. end
  546. end.
  547.  
  548.  
  549.  
  550. %%================================
  551. %%  LDAPString
  552. %%================================
  553. enc_LDAPString(Val) ->
  554.     enc_LDAPString(Val, [<<4>>]).
  555.  
  556. enc_LDAPString(Val, TagIn) ->
  557. encode_restricted_string(Val, TagIn).
  558.  
  559.  
  560. dec_LDAPString(Tlv) ->
  561.    dec_LDAPString(Tlv, [4]).
  562.  
  563. dec_LDAPString(Tlv, TagIn) ->
  564. decode_octet_string(Tlv, TagIn).
  565.  
  566.  
  567.  
  568. %%================================
  569. %%  LDAPOID
  570. %%================================
  571. enc_LDAPOID(Val) ->
  572.     enc_LDAPOID(Val, [<<4>>]).
  573.  
  574. enc_LDAPOID(Val, TagIn) ->
  575. encode_restricted_string(Val, TagIn).
  576.  
  577.  
  578. dec_LDAPOID(Tlv) ->
  579.    dec_LDAPOID(Tlv, [4]).
  580.  
  581. dec_LDAPOID(Tlv, TagIn) ->
  582. decode_octet_string(Tlv, TagIn).
  583.  
  584.  
  585.  
  586. %%================================
  587. %%  LDAPDN
  588. %%================================
  589. enc_LDAPDN(Val) ->
  590.     enc_LDAPDN(Val, [<<4>>]).
  591.  
  592. enc_LDAPDN(Val, TagIn) ->
  593. encode_restricted_string(Val, TagIn).
  594.  
  595.  
  596. dec_LDAPDN(Tlv) ->
  597.    dec_LDAPDN(Tlv, [4]).
  598.  
  599. dec_LDAPDN(Tlv, TagIn) ->
  600. decode_octet_string(Tlv, TagIn).
  601.  
  602.  
  603.  
  604. %%================================
  605. %%  RelativeLDAPDN
  606. %%================================
  607. enc_RelativeLDAPDN(Val) ->
  608.     enc_RelativeLDAPDN(Val, [<<4>>]).
  609.  
  610. enc_RelativeLDAPDN(Val, TagIn) ->
  611. encode_restricted_string(Val, TagIn).
  612.  
  613.  
  614. dec_RelativeLDAPDN(Tlv) ->
  615.    dec_RelativeLDAPDN(Tlv, [4]).
  616.  
  617. dec_RelativeLDAPDN(Tlv, TagIn) ->
  618. decode_octet_string(Tlv, TagIn).
  619.  
  620.  
  621.  
  622. %%================================
  623. %%  AttributeDescription
  624. %%================================
  625. enc_AttributeDescription(Val) ->
  626.     enc_AttributeDescription(Val, [<<4>>]).
  627.  
  628. enc_AttributeDescription(Val, TagIn) ->
  629. encode_restricted_string(Val, TagIn).
  630.  
  631.  
  632. dec_AttributeDescription(Tlv) ->
  633.    dec_AttributeDescription(Tlv, [4]).
  634.  
  635. dec_AttributeDescription(Tlv, TagIn) ->
  636. decode_octet_string(Tlv, TagIn).
  637.  
  638.  
  639.  
  640. %%================================
  641. %%  AttributeValue
  642. %%================================
  643. enc_AttributeValue(Val) ->
  644.     enc_AttributeValue(Val, [<<4>>]).
  645.  
  646. enc_AttributeValue(Val, TagIn) ->
  647. encode_restricted_string(Val, TagIn).
  648.  
  649.  
  650. dec_AttributeValue(Tlv) ->
  651.    dec_AttributeValue(Tlv, [4]).
  652.  
  653. dec_AttributeValue(Tlv, TagIn) ->
  654. decode_octet_string(Tlv, TagIn).
  655.  
  656.  
  657.  
  658. %%================================
  659. %%  AttributeValueAssertion
  660. %%================================
  661. enc_AttributeValueAssertion(Val) ->
  662.     enc_AttributeValueAssertion(Val, [<<48>>]).
  663.  
  664. enc_AttributeValueAssertion(Val, TagIn) ->
  665. {_,Cindex1,Cindex2} = Val,
  666.  
  667. %%-------------------------------------------------
  668. %% attribute attributeDesc(1) with type OCTET STRING
  669. %%-------------------------------------------------
  670.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  671.  
  672. %%-------------------------------------------------
  673. %% attribute assertionValue(2) with type OCTET STRING
  674. %%-------------------------------------------------
  675.    {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]),
  676.  
  677.    BytesSoFar = [EncBytes1, EncBytes2],
  678. LenSoFar = EncLen1 + EncLen2,
  679. encode_tags(TagIn, BytesSoFar, LenSoFar).
  680.  
  681.  
  682. dec_AttributeValueAssertion(Tlv) ->
  683.    dec_AttributeValueAssertion(Tlv, [16]).
  684.  
  685. dec_AttributeValueAssertion(Tlv, TagIn) ->
  686.    %%-------------------------------------------------
  687.    %% decode tag and length
  688.    %%-------------------------------------------------
  689. Tlv1 = match_tags(Tlv, TagIn),
  690.  
  691. %%-------------------------------------------------
  692. %% attribute attributeDesc(1) with type OCTET STRING
  693. %%-------------------------------------------------
  694. [V1|Tlv2] = Tlv1,
  695. Term1 = decode_octet_string(V1, [4]),
  696.  
  697. %%-------------------------------------------------
  698. %% attribute assertionValue(2) with type OCTET STRING
  699. %%-------------------------------------------------
  700. [V2|Tlv3] = Tlv2,
  701. Term2 = decode_octet_string(V2, [4]),
  702.  
  703. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  704. Res1 = {'AttributeValueAssertion',Term1,Term2},
  705. Res1.
  706.  
  707.  
  708. %%================================
  709. %%  AssertionValue
  710. %%================================
  711. enc_AssertionValue(Val) ->
  712.     enc_AssertionValue(Val, [<<4>>]).
  713.  
  714. enc_AssertionValue(Val, TagIn) ->
  715. encode_restricted_string(Val, TagIn).
  716.  
  717.  
  718. dec_AssertionValue(Tlv) ->
  719.    dec_AssertionValue(Tlv, [4]).
  720.  
  721. dec_AssertionValue(Tlv, TagIn) ->
  722. decode_octet_string(Tlv, TagIn).
  723.  
  724.  
  725.  
  726. %%================================
  727. %%  PartialAttribute
  728. %%================================
  729. enc_PartialAttribute(Val) ->
  730.     enc_PartialAttribute(Val, [<<48>>]).
  731.  
  732. enc_PartialAttribute(Val, TagIn) ->
  733. {_,Cindex1,Cindex2} = Val,
  734.  
  735. %%-------------------------------------------------
  736. %% attribute type(1) with type OCTET STRING
  737. %%-------------------------------------------------
  738.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  739.  
  740. %%-------------------------------------------------
  741. %% attribute vals(2) with type SET OF
  742. %%-------------------------------------------------
  743.    {EncBytes2,EncLen2} = 'enc_PartialAttribute_vals'(Cindex2, [<<49>>]),
  744.  
  745.    BytesSoFar = [EncBytes1, EncBytes2],
  746. LenSoFar = EncLen1 + EncLen2,
  747. encode_tags(TagIn, BytesSoFar, LenSoFar).
  748.  
  749.  
  750.  
  751. %%================================
  752. %%  PartialAttribute_vals
  753. %%================================
  754. enc_PartialAttribute_vals(Val, TagIn) ->
  755.       {EncBytes,EncLen} = 'enc_PartialAttribute_vals_components'(Val,[],0),
  756.    encode_tags(TagIn, EncBytes, EncLen).
  757.  
  758. 'enc_PartialAttribute_vals_components'([], AccBytes, AccLen) ->
  759.    {lists:reverse(AccBytes),AccLen};
  760.  
  761. 'enc_PartialAttribute_vals_components'([H|T],AccBytes, AccLen) ->
  762.    {EncBytes,EncLen} = encode_restricted_string(H, [<<4>>]),
  763.    'enc_PartialAttribute_vals_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  764.  
  765.  
  766.  
  767. dec_PartialAttribute(Tlv) ->
  768.    dec_PartialAttribute(Tlv, [16]).
  769.  
  770. dec_PartialAttribute(Tlv, TagIn) ->
  771.    %%-------------------------------------------------
  772.    %% decode tag and length
  773.    %%-------------------------------------------------
  774. Tlv1 = match_tags(Tlv, TagIn),
  775.  
  776. %%-------------------------------------------------
  777. %% attribute type(1) with type OCTET STRING
  778. %%-------------------------------------------------
  779. [V1|Tlv2] = Tlv1,
  780. Term1 = decode_octet_string(V1, [4]),
  781.  
  782. %%-------------------------------------------------
  783. %% attribute vals(2) with type SET OF
  784. %%-------------------------------------------------
  785. [V2|Tlv3] = Tlv2,
  786. Term2 = 'dec_PartialAttribute_vals'(V2, [17]),
  787.  
  788. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  789. Res1 = {'PartialAttribute',Term1,Term2},
  790. Res1.
  791. 'dec_PartialAttribute_vals'(Tlv, TagIn) ->
  792.    %%-------------------------------------------------
  793.    %% decode tag and length
  794.    %%-------------------------------------------------
  795. Tlv1 = match_tags(Tlv, TagIn),
  796. [decode_octet_string(V1, [4]) || V1 <- Tlv1].
  797.  
  798.  
  799.  
  800.  
  801. %%================================
  802. %%  Attribute
  803. %%================================
  804. enc_Attribute(Val) ->
  805.     enc_Attribute(Val, [<<48>>]).
  806.  
  807. enc_Attribute(Val, TagIn) ->
  808.    enc_PartialAttribute(Val, TagIn).
  809.  
  810.  
  811. dec_Attribute(Tlv) ->
  812.    dec_Attribute(Tlv, [16]).
  813.  
  814. dec_Attribute(Tlv, TagIn) ->
  815. 'dec_PartialAttribute'(Tlv, TagIn).
  816.  
  817.  
  818.  
  819. %%================================
  820. %%  MatchingRuleId
  821. %%================================
  822. enc_MatchingRuleId(Val) ->
  823.     enc_MatchingRuleId(Val, [<<4>>]).
  824.  
  825. enc_MatchingRuleId(Val, TagIn) ->
  826. encode_restricted_string(Val, TagIn).
  827.  
  828.  
  829. dec_MatchingRuleId(Tlv) ->
  830.    dec_MatchingRuleId(Tlv, [4]).
  831.  
  832. dec_MatchingRuleId(Tlv, TagIn) ->
  833. decode_octet_string(Tlv, TagIn).
  834.  
  835.  
  836.  
  837. %%================================
  838. %%  LDAPResult
  839. %%================================
  840. enc_LDAPResult(Val) ->
  841.     enc_LDAPResult(Val, [<<48>>]).
  842.  
  843. enc_LDAPResult(Val, TagIn) ->
  844. {_,Cindex1,Cindex2,Cindex3,Cindex4} = Val,
  845.  
  846. %%-------------------------------------------------
  847. %% attribute resultCode(1) with type ENUMERATED
  848. %%-------------------------------------------------
  849.    {EncBytes1,EncLen1} = case Cindex1 of
  850. success -> encode_tags([<<10>>], [0], 1);
  851. operationsError -> encode_tags([<<10>>], [1], 1);
  852. protocolError -> encode_tags([<<10>>], [2], 1);
  853. timeLimitExceeded -> encode_tags([<<10>>], [3], 1);
  854. sizeLimitExceeded -> encode_tags([<<10>>], [4], 1);
  855. compareFalse -> encode_tags([<<10>>], [5], 1);
  856. compareTrue -> encode_tags([<<10>>], [6], 1);
  857. authMethodNotSupported -> encode_tags([<<10>>], [7], 1);
  858. strongerAuthRequired -> encode_tags([<<10>>], [8], 1);
  859. referral -> encode_tags([<<10>>], [10], 1);
  860. adminLimitExceeded -> encode_tags([<<10>>], [11], 1);
  861. unavailableCriticalExtension -> encode_tags([<<10>>], [12], 1);
  862. confidentialityRequired -> encode_tags([<<10>>], [13], 1);
  863. saslBindInProgress -> encode_tags([<<10>>], [14], 1);
  864. noSuchAttribute -> encode_tags([<<10>>], [16], 1);
  865. undefinedAttributeType -> encode_tags([<<10>>], [17], 1);
  866. inappropriateMatching -> encode_tags([<<10>>], [18], 1);
  867. constraintViolation -> encode_tags([<<10>>], [19], 1);
  868. attributeOrValueExists -> encode_tags([<<10>>], [20], 1);
  869. invalidAttributeSyntax -> encode_tags([<<10>>], [21], 1);
  870. noSuchObject -> encode_tags([<<10>>], [32], 1);
  871. aliasProblem -> encode_tags([<<10>>], [33], 1);
  872. invalidDNSyntax -> encode_tags([<<10>>], [34], 1);
  873. aliasDereferencingProblem -> encode_tags([<<10>>], [36], 1);
  874. inappropriateAuthentication -> encode_tags([<<10>>], [48], 1);
  875. invalidCredentials -> encode_tags([<<10>>], [49], 1);
  876. insufficientAccessRights -> encode_tags([<<10>>], [50], 1);
  877. busy -> encode_tags([<<10>>], [51], 1);
  878. unavailable -> encode_tags([<<10>>], [52], 1);
  879. unwillingToPerform -> encode_tags([<<10>>], [53], 1);
  880. loopDetect -> encode_tags([<<10>>], [54], 1);
  881. namingViolation -> encode_tags([<<10>>], [64], 1);
  882. objectClassViolation -> encode_tags([<<10>>], [65], 1);
  883. notAllowedOnNonLeaf -> encode_tags([<<10>>], [66], 1);
  884. notAllowedOnRDN -> encode_tags([<<10>>], [67], 1);
  885. entryAlreadyExists -> encode_tags([<<10>>], [68], 1);
  886. objectClassModsProhibited -> encode_tags([<<10>>], [69], 1);
  887. affectsMultipleDSAs -> encode_tags([<<10>>], [71], 1);
  888. other -> encode_tags([<<10>>], [80], 1);
  889. Enumval1 -> exit({error,{asn1, {enumerated_not_in_range,Enumval1}}})
  890. end,
  891.  
  892. %%-------------------------------------------------
  893. %% attribute matchedDN(2) with type OCTET STRING
  894. %%-------------------------------------------------
  895.    {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]),
  896.  
  897. %%-------------------------------------------------
  898. %% attribute diagnosticMessage(3) with type OCTET STRING
  899. %%-------------------------------------------------
  900.    {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<4>>]),
  901.  
  902. %%-------------------------------------------------
  903. %% attribute referral(4)   External Lightweight-Directory-Access-Protocol-V3:Referral OPTIONAL
  904. %%-------------------------------------------------
  905.    {EncBytes4,EncLen4} =  case Cindex4 of
  906.          asn1_NOVALUE -> {<<>>,0};
  907.          _ ->
  908.             'enc_Referral'(Cindex4, [<<163>>])
  909.        end,
  910.  
  911.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4],
  912. LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4,
  913. encode_tags(TagIn, BytesSoFar, LenSoFar).
  914.  
  915.  
  916. dec_LDAPResult(Tlv) ->
  917.    dec_LDAPResult(Tlv, [16]).
  918.  
  919. dec_LDAPResult(Tlv, TagIn) ->
  920.    %%-------------------------------------------------
  921.    %% decode tag and length
  922.    %%-------------------------------------------------
  923. Tlv1 = match_tags(Tlv, TagIn),
  924.  
  925. %%-------------------------------------------------
  926. %% attribute resultCode(1) with type ENUMERATED
  927. %%-------------------------------------------------
  928. [V1|Tlv2] = Tlv1,
  929. Term1 = case decode_integer(V1, [10]) of
  930. 0 -> success;
  931. 1 -> operationsError;
  932. 2 -> protocolError;
  933. 3 -> timeLimitExceeded;
  934. 4 -> sizeLimitExceeded;
  935. 5 -> compareFalse;
  936. 6 -> compareTrue;
  937. 7 -> authMethodNotSupported;
  938. 8 -> strongerAuthRequired;
  939. 10 -> referral;
  940. 11 -> adminLimitExceeded;
  941. 12 -> unavailableCriticalExtension;
  942. 13 -> confidentialityRequired;
  943. 14 -> saslBindInProgress;
  944. 16 -> noSuchAttribute;
  945. 17 -> undefinedAttributeType;
  946. 18 -> inappropriateMatching;
  947. 19 -> constraintViolation;
  948. 20 -> attributeOrValueExists;
  949. 21 -> invalidAttributeSyntax;
  950. 32 -> noSuchObject;
  951. 33 -> aliasProblem;
  952. 34 -> invalidDNSyntax;
  953. 36 -> aliasDereferencingProblem;
  954. 48 -> inappropriateAuthentication;
  955. 49 -> invalidCredentials;
  956. 50 -> insufficientAccessRights;
  957. 51 -> busy;
  958. 52 -> unavailable;
  959. 53 -> unwillingToPerform;
  960. 54 -> loopDetect;
  961. 64 -> namingViolation;
  962. 65 -> objectClassViolation;
  963. 66 -> notAllowedOnNonLeaf;
  964. 67 -> notAllowedOnRDN;
  965. 68 -> entryAlreadyExists;
  966. 69 -> objectClassModsProhibited;
  967. 71 -> affectsMultipleDSAs;
  968. 80 -> other;
  969. Default1 -> {asn1_enum,Default1}
  970. end,
  971.  
  972. %%-------------------------------------------------
  973. %% attribute matchedDN(2) with type OCTET STRING
  974. %%-------------------------------------------------
  975. [V2|Tlv3] = Tlv2,
  976. Term2 = decode_octet_string(V2, [4]),
  977.  
  978. %%-------------------------------------------------
  979. %% attribute diagnosticMessage(3) with type OCTET STRING
  980. %%-------------------------------------------------
  981. [V3|Tlv4] = Tlv3,
  982. Term3 = decode_octet_string(V3, [4]),
  983.  
  984. %%-------------------------------------------------
  985. %% attribute referral(4)   External Lightweight-Directory-Access-Protocol-V3:Referral OPTIONAL
  986. %%-------------------------------------------------
  987. {Term4,Tlv5} = case Tlv4 of
  988. [{131075,V4}|TempTlv5] ->
  989.     {'dec_Referral'(V4, []), TempTlv5};
  990.     _ ->
  991.         { asn1_NOVALUE, Tlv4}
  992. end,
  993.  
  994. case Tlv5 of [] -> true; _ -> true end, % ... extra fields skipped
  995. Res1 = {'LDAPResult',Term1,Term2,Term3,Term4},
  996. Res1.
  997.  
  998.  
  999. %%================================
  1000. %%  Referral
  1001. %%================================
  1002. enc_Referral(Val) ->
  1003.     enc_Referral(Val, [<<48>>]).
  1004.  
  1005. enc_Referral(Val, TagIn) ->
  1006.    {EncBytes,EncLen} = 'enc_Referral_components'(Val,[],0),
  1007.    encode_tags(TagIn, EncBytes, EncLen).
  1008.  
  1009. 'enc_Referral_components'([], AccBytes, AccLen) ->
  1010.    {lists:reverse(AccBytes),AccLen};
  1011.  
  1012. 'enc_Referral_components'([H|T],AccBytes, AccLen) ->
  1013.    {EncBytes,EncLen} = encode_restricted_string(H, [<<4>>]),
  1014.    'enc_Referral_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  1015.  
  1016.  
  1017.  
  1018. dec_Referral(Tlv) ->
  1019.    dec_Referral(Tlv, [16]).
  1020.  
  1021. dec_Referral(Tlv, TagIn) ->
  1022.    %%-------------------------------------------------
  1023.    %% decode tag and length
  1024.    %%-------------------------------------------------
  1025. Tlv1 = match_tags(Tlv, TagIn),
  1026. [decode_octet_string(V1, [4]) || V1 <- Tlv1].
  1027.  
  1028.  
  1029.  
  1030.  
  1031. %%================================
  1032. %%  URI
  1033. %%================================
  1034. enc_URI(Val) ->
  1035.     enc_URI(Val, [<<4>>]).
  1036.  
  1037. enc_URI(Val, TagIn) ->
  1038. encode_restricted_string(Val, TagIn).
  1039.  
  1040.  
  1041. dec_URI(Tlv) ->
  1042.    dec_URI(Tlv, [4]).
  1043.  
  1044. dec_URI(Tlv, TagIn) ->
  1045. decode_octet_string(Tlv, TagIn).
  1046.  
  1047.  
  1048.  
  1049. %%================================
  1050. %%  Controls
  1051. %%================================
  1052. enc_Controls(Val) ->
  1053.     enc_Controls(Val, [<<48>>]).
  1054.  
  1055. enc_Controls(Val, TagIn) ->
  1056.    {EncBytes,EncLen} = 'enc_Controls_components'(Val,[],0),
  1057.    encode_tags(TagIn, EncBytes, EncLen).
  1058.  
  1059. 'enc_Controls_components'([], AccBytes, AccLen) ->
  1060.    {lists:reverse(AccBytes),AccLen};
  1061.  
  1062. 'enc_Controls_components'([H|T],AccBytes, AccLen) ->
  1063.    {EncBytes,EncLen} = 'enc_Control'(H, [<<48>>]),
  1064.    'enc_Controls_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  1065.  
  1066.  
  1067.  
  1068. dec_Controls(Tlv) ->
  1069.    dec_Controls(Tlv, [16]).
  1070.  
  1071. dec_Controls(Tlv, TagIn) ->
  1072.    %%-------------------------------------------------
  1073.    %% decode tag and length
  1074.    %%-------------------------------------------------
  1075. Tlv1 = match_tags(Tlv, TagIn),
  1076. ['dec_Control'(V1, [16]) || V1 <- Tlv1].
  1077.  
  1078.  
  1079.  
  1080.  
  1081. %%================================
  1082. %%  Control
  1083. %%================================
  1084. enc_Control(Val) ->
  1085.     enc_Control(Val, [<<48>>]).
  1086.  
  1087. enc_Control(Val, TagIn) ->
  1088. {_,Cindex1,Cindex2,Cindex3} = Val,
  1089.  
  1090. %%-------------------------------------------------
  1091. %% attribute controlType(1) with type OCTET STRING
  1092. %%-------------------------------------------------
  1093.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  1094.  
  1095. %%-------------------------------------------------
  1096. %% attribute criticality(2) with type BOOLEAN DEFAULT = false
  1097. %%-------------------------------------------------
  1098.    {EncBytes2,EncLen2} =  case Cindex2 of
  1099.          asn1_DEFAULT ->
  1100.             {<<>>,0};
  1101.          _ when Cindex2 =:= false ->
  1102.             {<<>>,0};
  1103.          _ ->
  1104.             encode_boolean(Cindex2, [<<1>>])
  1105.        end,
  1106.  
  1107. %%-------------------------------------------------
  1108. %% attribute controlValue(3) with type OCTET STRING OPTIONAL
  1109. %%-------------------------------------------------
  1110.    {EncBytes3,EncLen3} =  case Cindex3 of
  1111.          asn1_NOVALUE -> {<<>>,0};
  1112.          _ ->
  1113.             encode_restricted_string(Cindex3, [<<4>>])
  1114.        end,
  1115.  
  1116.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
  1117. LenSoFar = EncLen1 + EncLen2 + EncLen3,
  1118. encode_tags(TagIn, BytesSoFar, LenSoFar).
  1119.  
  1120.  
  1121. dec_Control(Tlv) ->
  1122.    dec_Control(Tlv, [16]).
  1123.  
  1124. dec_Control(Tlv, TagIn) ->
  1125.    %%-------------------------------------------------
  1126.    %% decode tag and length
  1127.    %%-------------------------------------------------
  1128. Tlv1 = match_tags(Tlv, TagIn),
  1129.  
  1130. %%-------------------------------------------------
  1131. %% attribute controlType(1) with type OCTET STRING
  1132. %%-------------------------------------------------
  1133. [V1|Tlv2] = Tlv1,
  1134. Term1 = decode_octet_string(V1, [4]),
  1135.  
  1136. %%-------------------------------------------------
  1137. %% attribute criticality(2) with type BOOLEAN DEFAULT = false
  1138. %%-------------------------------------------------
  1139. {Term2,Tlv3} = case Tlv2 of
  1140. [{1,V2}|TempTlv3] ->
  1141.     {decode_boolean(V2, []), TempTlv3};
  1142.     _ ->
  1143.         {false,Tlv2}
  1144. end,
  1145.  
  1146. %%-------------------------------------------------
  1147. %% attribute controlValue(3) with type OCTET STRING OPTIONAL
  1148. %%-------------------------------------------------
  1149. {Term3,Tlv4} = case Tlv3 of
  1150. [{4,V3}|TempTlv4] ->
  1151.     {decode_octet_string(V3, []), TempTlv4};
  1152.     _ ->
  1153.         { asn1_NOVALUE, Tlv3}
  1154. end,
  1155.  
  1156. case Tlv4 of [] -> true; _ -> true end, % ... extra fields skipped
  1157. Res1 = {'Control',Term1,Term2,Term3},
  1158. Res1.
  1159.  
  1160.  
  1161. %%================================
  1162. %%  BindRequest
  1163. %%================================
  1164. enc_BindRequest(Val) ->
  1165.     enc_BindRequest(Val, [<<96>>]).
  1166.  
  1167. enc_BindRequest(Val, TagIn) ->
  1168. {_,Cindex1,Cindex2,Cindex3} = Val,
  1169.  
  1170. %%-------------------------------------------------
  1171. %% attribute version(1) with type INTEGER
  1172. %%-------------------------------------------------
  1173.    {EncBytes1,EncLen1} = encode_integer(Cindex1, [<<2>>]),
  1174.  
  1175. %%-------------------------------------------------
  1176. %% attribute name(2) with type OCTET STRING
  1177. %%-------------------------------------------------
  1178.    {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]),
  1179.  
  1180. %%-------------------------------------------------
  1181. %% attribute authentication(3)   External Lightweight-Directory-Access-Protocol-V3:AuthenticationChoice
  1182. %%-------------------------------------------------
  1183.    {EncBytes3,EncLen3} = 'enc_AuthenticationChoice'(Cindex3, []),
  1184.  
  1185.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
  1186. LenSoFar = EncLen1 + EncLen2 + EncLen3,
  1187. encode_tags(TagIn, BytesSoFar, LenSoFar).
  1188.  
  1189.  
  1190. dec_BindRequest(Tlv) ->
  1191.    dec_BindRequest(Tlv, [65536]).
  1192.  
  1193. dec_BindRequest(Tlv, TagIn) ->
  1194.    %%-------------------------------------------------
  1195.    %% decode tag and length
  1196.    %%-------------------------------------------------
  1197. Tlv1 = match_tags(Tlv, TagIn),
  1198.  
  1199. %%-------------------------------------------------
  1200. %% attribute version(1) with type INTEGER
  1201. %%-------------------------------------------------
  1202. [V1|Tlv2] = Tlv1,
  1203. Term1 = begin
  1204. Val1 = decode_integer(V1, [2]),
  1205. if 1 =< Val1, Val1 =< 127 ->
  1206. Val1;
  1207. true ->
  1208. exit({error,{asn1,bad_range}})
  1209. end
  1210. end,
  1211.  
  1212. %%-------------------------------------------------
  1213. %% attribute name(2) with type OCTET STRING
  1214. %%-------------------------------------------------
  1215. [V2|Tlv3] = Tlv2,
  1216. Term2 = decode_octet_string(V2, [4]),
  1217.  
  1218. %%-------------------------------------------------
  1219. %% attribute authentication(3)   External Lightweight-Directory-Access-Protocol-V3:AuthenticationChoice
  1220. %%-------------------------------------------------
  1221. [V3|Tlv4] = Tlv3,
  1222. Term3 = 'dec_AuthenticationChoice'(V3, []),
  1223.  
  1224. case Tlv4 of [] -> true; _ -> true end, % ... extra fields skipped
  1225. Res1 = {'BindRequest',Term1,Term2,Term3},
  1226. Res1.
  1227.  
  1228.  
  1229. %%================================
  1230. %%  AuthenticationChoice
  1231. %%================================
  1232. enc_AuthenticationChoice(Val) ->
  1233.     enc_AuthenticationChoice(Val, []).
  1234.  
  1235. enc_AuthenticationChoice(Val, TagIn) ->
  1236.    {EncBytes,EncLen} = case element(1,Val) of
  1237.       simple ->
  1238.          encode_restricted_string(element(2,Val), [<<128>>]);
  1239.       sasl ->
  1240.          'enc_SaslCredentials'(element(2,Val), [<<163>>]);
  1241.       Else ->
  1242.          exit({error,{asn1,{invalid_choice_type,Else}}})
  1243.    end,
  1244.  
  1245. encode_tags(TagIn, EncBytes, EncLen).
  1246.  
  1247.  
  1248.  
  1249.  
  1250. dec_AuthenticationChoice(Tlv) ->
  1251.    dec_AuthenticationChoice(Tlv, []).
  1252.  
  1253. dec_AuthenticationChoice(Tlv, TagIn) ->
  1254. Tlv1 = match_tags(Tlv, TagIn),
  1255. case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
  1256.  
  1257. %% 'simple'
  1258.     {131072, V1} ->
  1259.         {simple, decode_octet_string(V1, [])};
  1260.  
  1261.  
  1262. %% 'sasl'
  1263.     {131075, V1} ->
  1264.         {sasl, 'dec_SaslCredentials'(V1, [])};
  1265.  
  1266.       Else ->
  1267.          {asn1_ExtAlt,ber_encode(Else)}
  1268.    end
  1269. .
  1270.  
  1271.  
  1272. %%================================
  1273. %%  SaslCredentials
  1274. %%================================
  1275. enc_SaslCredentials(Val) ->
  1276.     enc_SaslCredentials(Val, [<<48>>]).
  1277.  
  1278. enc_SaslCredentials(Val, TagIn) ->
  1279. {_,Cindex1,Cindex2} = Val,
  1280.  
  1281. %%-------------------------------------------------
  1282. %% attribute mechanism(1) with type OCTET STRING
  1283. %%-------------------------------------------------
  1284.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  1285.  
  1286. %%-------------------------------------------------
  1287. %% attribute credentials(2) with type OCTET STRING OPTIONAL
  1288. %%-------------------------------------------------
  1289.    {EncBytes2,EncLen2} =  case Cindex2 of
  1290.          asn1_NOVALUE -> {<<>>,0};
  1291.          _ ->
  1292.             encode_restricted_string(Cindex2, [<<4>>])
  1293.        end,
  1294.  
  1295.    BytesSoFar = [EncBytes1, EncBytes2],
  1296. LenSoFar = EncLen1 + EncLen2,
  1297. encode_tags(TagIn, BytesSoFar, LenSoFar).
  1298.  
  1299.  
  1300. dec_SaslCredentials(Tlv) ->
  1301.    dec_SaslCredentials(Tlv, [16]).
  1302.  
  1303. dec_SaslCredentials(Tlv, TagIn) ->
  1304.    %%-------------------------------------------------
  1305.    %% decode tag and length
  1306.    %%-------------------------------------------------
  1307. Tlv1 = match_tags(Tlv, TagIn),
  1308.  
  1309. %%-------------------------------------------------
  1310. %% attribute mechanism(1) with type OCTET STRING
  1311. %%-------------------------------------------------
  1312. [V1|Tlv2] = Tlv1,
  1313. Term1 = decode_octet_string(V1, [4]),
  1314.  
  1315. %%-------------------------------------------------
  1316. %% attribute credentials(2) with type OCTET STRING OPTIONAL
  1317. %%-------------------------------------------------
  1318. {Term2,Tlv3} = case Tlv2 of
  1319. [{4,V2}|TempTlv3] ->
  1320.     {decode_octet_string(V2, []), TempTlv3};
  1321.     _ ->
  1322.         { asn1_NOVALUE, Tlv2}
  1323. end,
  1324.  
  1325. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  1326. Res1 = {'SaslCredentials',Term1,Term2},
  1327. Res1.
  1328.  
  1329.  
  1330. %%================================
  1331. %%  BindResponse
  1332. %%================================
  1333. enc_BindResponse(Val) ->
  1334.     enc_BindResponse(Val, [<<97>>]).
  1335.  
  1336. enc_BindResponse(Val, TagIn) ->
  1337. {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5} = Val,
  1338.  
  1339. %%-------------------------------------------------
  1340. %% attribute resultCode(1) with type ENUMERATED
  1341. %%-------------------------------------------------
  1342.    {EncBytes1,EncLen1} = case Cindex1 of
  1343. success -> encode_tags([<<10>>], [0], 1);
  1344. operationsError -> encode_tags([<<10>>], [1], 1);
  1345. protocolError -> encode_tags([<<10>>], [2], 1);
  1346. timeLimitExceeded -> encode_tags([<<10>>], [3], 1);
  1347. sizeLimitExceeded -> encode_tags([<<10>>], [4], 1);
  1348. compareFalse -> encode_tags([<<10>>], [5], 1);
  1349. compareTrue -> encode_tags([<<10>>], [6], 1);
  1350. authMethodNotSupported -> encode_tags([<<10>>], [7], 1);
  1351. strongerAuthRequired -> encode_tags([<<10>>], [8], 1);
  1352. referral -> encode_tags([<<10>>], [10], 1);
  1353. adminLimitExceeded -> encode_tags([<<10>>], [11], 1);
  1354. unavailableCriticalExtension -> encode_tags([<<10>>], [12], 1);
  1355. confidentialityRequired -> encode_tags([<<10>>], [13], 1);
  1356. saslBindInProgress -> encode_tags([<<10>>], [14], 1);
  1357. noSuchAttribute -> encode_tags([<<10>>], [16], 1);
  1358. undefinedAttributeType -> encode_tags([<<10>>], [17], 1);
  1359. inappropriateMatching -> encode_tags([<<10>>], [18], 1);
  1360. constraintViolation -> encode_tags([<<10>>], [19], 1);
  1361. attributeOrValueExists -> encode_tags([<<10>>], [20], 1);
  1362. invalidAttributeSyntax -> encode_tags([<<10>>], [21], 1);
  1363. noSuchObject -> encode_tags([<<10>>], [32], 1);
  1364. aliasProblem -> encode_tags([<<10>>], [33], 1);
  1365. invalidDNSyntax -> encode_tags([<<10>>], [34], 1);
  1366. aliasDereferencingProblem -> encode_tags([<<10>>], [36], 1);
  1367. inappropriateAuthentication -> encode_tags([<<10>>], [48], 1);
  1368. invalidCredentials -> encode_tags([<<10>>], [49], 1);
  1369. insufficientAccessRights -> encode_tags([<<10>>], [50], 1);
  1370. busy -> encode_tags([<<10>>], [51], 1);
  1371. unavailable -> encode_tags([<<10>>], [52], 1);
  1372. unwillingToPerform -> encode_tags([<<10>>], [53], 1);
  1373. loopDetect -> encode_tags([<<10>>], [54], 1);
  1374. namingViolation -> encode_tags([<<10>>], [64], 1);
  1375. objectClassViolation -> encode_tags([<<10>>], [65], 1);
  1376. notAllowedOnNonLeaf -> encode_tags([<<10>>], [66], 1);
  1377. notAllowedOnRDN -> encode_tags([<<10>>], [67], 1);
  1378. entryAlreadyExists -> encode_tags([<<10>>], [68], 1);
  1379. objectClassModsProhibited -> encode_tags([<<10>>], [69], 1);
  1380. affectsMultipleDSAs -> encode_tags([<<10>>], [71], 1);
  1381. other -> encode_tags([<<10>>], [80], 1);
  1382. Enumval1 -> exit({error,{asn1, {enumerated_not_in_range,Enumval1}}})
  1383. end,
  1384.  
  1385. %%-------------------------------------------------
  1386. %% attribute matchedDN(2) with type OCTET STRING
  1387. %%-------------------------------------------------
  1388.    {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]),
  1389.  
  1390. %%-------------------------------------------------
  1391. %% attribute diagnosticMessage(3) with type OCTET STRING
  1392. %%-------------------------------------------------
  1393.    {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<4>>]),
  1394.  
  1395. %%-------------------------------------------------
  1396. %% attribute referral(4)   External Lightweight-Directory-Access-Protocol-V3:Referral OPTIONAL
  1397. %%-------------------------------------------------
  1398.    {EncBytes4,EncLen4} =  case Cindex4 of
  1399.          asn1_NOVALUE -> {<<>>,0};
  1400.          _ ->
  1401.             'enc_Referral'(Cindex4, [<<163>>])
  1402.        end,
  1403.  
  1404. %%-------------------------------------------------
  1405. %% attribute serverSaslCreds(5) with type OCTET STRING OPTIONAL
  1406. %%-------------------------------------------------
  1407.    {EncBytes5,EncLen5} =  case Cindex5 of
  1408.          asn1_NOVALUE -> {<<>>,0};
  1409.          _ ->
  1410.             encode_restricted_string(Cindex5, [<<135>>])
  1411.        end,
  1412.  
  1413.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5],
  1414. LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5,
  1415. encode_tags(TagIn, BytesSoFar, LenSoFar).
  1416.  
  1417.  
  1418. dec_BindResponse(Tlv) ->
  1419.    dec_BindResponse(Tlv, [65537]).
  1420.  
  1421. dec_BindResponse(Tlv, TagIn) ->
  1422.    %%-------------------------------------------------
  1423.    %% decode tag and length
  1424.    %%-------------------------------------------------
  1425. Tlv1 = match_tags(Tlv, TagIn),
  1426.  
  1427. %%-------------------------------------------------
  1428. %% attribute resultCode(1) with type ENUMERATED
  1429. %%-------------------------------------------------
  1430. [V1|Tlv2] = Tlv1,
  1431. Term1 = case decode_integer(V1, [10]) of
  1432. 0 -> success;
  1433. 1 -> operationsError;
  1434. 2 -> protocolError;
  1435. 3 -> timeLimitExceeded;
  1436. 4 -> sizeLimitExceeded;
  1437. 5 -> compareFalse;
  1438. 6 -> compareTrue;
  1439. 7 -> authMethodNotSupported;
  1440. 8 -> strongerAuthRequired;
  1441. 10 -> referral;
  1442. 11 -> adminLimitExceeded;
  1443. 12 -> unavailableCriticalExtension;
  1444. 13 -> confidentialityRequired;
  1445. 14 -> saslBindInProgress;
  1446. 16 -> noSuchAttribute;
  1447. 17 -> undefinedAttributeType;
  1448. 18 -> inappropriateMatching;
  1449. 19 -> constraintViolation;
  1450. 20 -> attributeOrValueExists;
  1451. 21 -> invalidAttributeSyntax;
  1452. 32 -> noSuchObject;
  1453. 33 -> aliasProblem;
  1454. 34 -> invalidDNSyntax;
  1455. 36 -> aliasDereferencingProblem;
  1456. 48 -> inappropriateAuthentication;
  1457. 49 -> invalidCredentials;
  1458. 50 -> insufficientAccessRights;
  1459. 51 -> busy;
  1460. 52 -> unavailable;
  1461. 53 -> unwillingToPerform;
  1462. 54 -> loopDetect;
  1463. 64 -> namingViolation;
  1464. 65 -> objectClassViolation;
  1465. 66 -> notAllowedOnNonLeaf;
  1466. 67 -> notAllowedOnRDN;
  1467. 68 -> entryAlreadyExists;
  1468. 69 -> objectClassModsProhibited;
  1469. 71 -> affectsMultipleDSAs;
  1470. 80 -> other;
  1471. Default1 -> {asn1_enum,Default1}
  1472. end,
  1473.  
  1474. %%-------------------------------------------------
  1475. %% attribute matchedDN(2) with type OCTET STRING
  1476. %%-------------------------------------------------
  1477. [V2|Tlv3] = Tlv2,
  1478. Term2 = decode_octet_string(V2, [4]),
  1479.  
  1480. %%-------------------------------------------------
  1481. %% attribute diagnosticMessage(3) with type OCTET STRING
  1482. %%-------------------------------------------------
  1483. [V3|Tlv4] = Tlv3,
  1484. Term3 = decode_octet_string(V3, [4]),
  1485.  
  1486. %%-------------------------------------------------
  1487. %% attribute referral(4)   External Lightweight-Directory-Access-Protocol-V3:Referral OPTIONAL
  1488. %%-------------------------------------------------
  1489. {Term4,Tlv5} = case Tlv4 of
  1490. [{131075,V4}|TempTlv5] ->
  1491.     {'dec_Referral'(V4, []), TempTlv5};
  1492.     _ ->
  1493.         { asn1_NOVALUE, Tlv4}
  1494. end,
  1495.  
  1496. %%-------------------------------------------------
  1497. %% attribute serverSaslCreds(5) with type OCTET STRING OPTIONAL
  1498. %%-------------------------------------------------
  1499. {Term5,Tlv6} = case Tlv5 of
  1500. [{131079,V5}|TempTlv6] ->
  1501.     {decode_octet_string(V5, []), TempTlv6};
  1502.     _ ->
  1503.         { asn1_NOVALUE, Tlv5}
  1504. end,
  1505.  
  1506. case Tlv6 of [] -> true; _ -> true end, % ... extra fields skipped
  1507. Res1 = {'BindResponse',Term1,Term2,Term3,Term4,Term5},
  1508. Res1.
  1509.  
  1510.  
  1511. %%================================
  1512. %%  UnbindRequest
  1513. %%================================
  1514. enc_UnbindRequest(Val) ->
  1515.     enc_UnbindRequest(Val, [<<66>>]).
  1516.  
  1517. enc_UnbindRequest(Val, TagIn) ->
  1518. encode_null(Val, TagIn).
  1519.  
  1520.  
  1521. dec_UnbindRequest(Tlv) ->
  1522.    dec_UnbindRequest(Tlv, [65538]).
  1523.  
  1524. dec_UnbindRequest(Tlv, TagIn) ->
  1525. decode_null(Tlv, TagIn).
  1526.  
  1527.  
  1528.  
  1529. %%================================
  1530. %%  SearchRequest
  1531. %%================================
  1532. enc_SearchRequest(Val) ->
  1533.     enc_SearchRequest(Val, [<<99>>]).
  1534.  
  1535. enc_SearchRequest(Val, TagIn) ->
  1536. {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5,Cindex6,Cindex7,Cindex8} = Val,
  1537.  
  1538. %%-------------------------------------------------
  1539. %% attribute baseObject(1) with type OCTET STRING
  1540. %%-------------------------------------------------
  1541.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  1542.  
  1543. %%-------------------------------------------------
  1544. %% attribute scope(2) with type ENUMERATED
  1545. %%-------------------------------------------------
  1546.    {EncBytes2,EncLen2} = case Cindex2 of
  1547. baseObject -> encode_tags([<<10>>], [0], 1);
  1548. singleLevel -> encode_tags([<<10>>], [1], 1);
  1549. wholeSubtree -> encode_tags([<<10>>], [2], 1);
  1550. Enumval2 -> exit({error,{asn1, {enumerated_not_in_range,Enumval2}}})
  1551. end,
  1552.  
  1553. %%-------------------------------------------------
  1554. %% attribute derefAliases(3) with type ENUMERATED
  1555. %%-------------------------------------------------
  1556.    {EncBytes3,EncLen3} = case Cindex3 of
  1557. neverDerefAliases -> encode_tags([<<10>>], [0], 1);
  1558. derefInSearching -> encode_tags([<<10>>], [1], 1);
  1559. derefFindingBaseObj -> encode_tags([<<10>>], [2], 1);
  1560. derefAlways -> encode_tags([<<10>>], [3], 1);
  1561. Enumval3 -> exit({error,{asn1, {enumerated_not_in_range,Enumval3}}})
  1562. end,
  1563.  
  1564. %%-------------------------------------------------
  1565. %% attribute sizeLimit(4) with type INTEGER
  1566. %%-------------------------------------------------
  1567.    {EncBytes4,EncLen4} = encode_integer(Cindex4, [<<2>>]),
  1568.  
  1569. %%-------------------------------------------------
  1570. %% attribute timeLimit(5) with type INTEGER
  1571. %%-------------------------------------------------
  1572.    {EncBytes5,EncLen5} = encode_integer(Cindex5, [<<2>>]),
  1573.  
  1574. %%-------------------------------------------------
  1575. %% attribute typesOnly(6) with type BOOLEAN
  1576. %%-------------------------------------------------
  1577.    {EncBytes6,EncLen6} = encode_boolean(Cindex6, [<<1>>]),
  1578.  
  1579. %%-------------------------------------------------
  1580. %% attribute filter(7)   External Lightweight-Directory-Access-Protocol-V3:Filter
  1581. %%-------------------------------------------------
  1582.    {EncBytes7,EncLen7} = 'enc_Filter'(Cindex7, []),
  1583.  
  1584. %%-------------------------------------------------
  1585. %% attribute attributes(8)   External Lightweight-Directory-Access-Protocol-V3:AttributeSelection
  1586. %%-------------------------------------------------
  1587.    {EncBytes8,EncLen8} = 'enc_AttributeSelection'(Cindex8, [<<48>>]),
  1588.  
  1589.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5, EncBytes6, EncBytes7, EncBytes8],
  1590. LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5 + EncLen6 + EncLen7 + EncLen8,
  1591. encode_tags(TagIn, BytesSoFar, LenSoFar).
  1592.  
  1593.  
  1594. dec_SearchRequest(Tlv) ->
  1595.    dec_SearchRequest(Tlv, [65539]).
  1596.  
  1597. dec_SearchRequest(Tlv, TagIn) ->
  1598.    %%-------------------------------------------------
  1599.    %% decode tag and length
  1600.    %%-------------------------------------------------
  1601. Tlv1 = match_tags(Tlv, TagIn),
  1602.  
  1603. %%-------------------------------------------------
  1604. %% attribute baseObject(1) with type OCTET STRING
  1605. %%-------------------------------------------------
  1606. [V1|Tlv2] = Tlv1,
  1607. Term1 = decode_octet_string(V1, [4]),
  1608.  
  1609. %%-------------------------------------------------
  1610. %% attribute scope(2) with type ENUMERATED
  1611. %%-------------------------------------------------
  1612. [V2|Tlv3] = Tlv2,
  1613. Term2 = case decode_integer(V2, [10]) of
  1614. 0 -> baseObject;
  1615. 1 -> singleLevel;
  1616. 2 -> wholeSubtree;
  1617. Default1 -> {asn1_enum,Default1}
  1618. end,
  1619.  
  1620. %%-------------------------------------------------
  1621. %% attribute derefAliases(3) with type ENUMERATED
  1622. %%-------------------------------------------------
  1623. [V3|Tlv4] = Tlv3,
  1624. Term3 = case decode_integer(V3, [10]) of
  1625. 0 -> neverDerefAliases;
  1626. 1 -> derefInSearching;
  1627. 2 -> derefFindingBaseObj;
  1628. 3 -> derefAlways;
  1629. Default2 -> {asn1_enum,Default2}
  1630. end,
  1631.  
  1632. %%-------------------------------------------------
  1633. %% attribute sizeLimit(4) with type INTEGER
  1634. %%-------------------------------------------------
  1635. [V4|Tlv5] = Tlv4,
  1636. Term4 = begin
  1637. Val1 = decode_integer(V4, [2]),
  1638. if 0 =< Val1, Val1 =< 2147483647 ->
  1639. Val1;
  1640. true ->
  1641. exit({error,{asn1,bad_range}})
  1642. end
  1643. end,
  1644.  
  1645. %%-------------------------------------------------
  1646. %% attribute timeLimit(5) with type INTEGER
  1647. %%-------------------------------------------------
  1648. [V5|Tlv6] = Tlv5,
  1649. Term5 = begin
  1650. Val2 = decode_integer(V5, [2]),
  1651. if 0 =< Val2, Val2 =< 2147483647 ->
  1652. Val2;
  1653. true ->
  1654. exit({error,{asn1,bad_range}})
  1655. end
  1656. end,
  1657.  
  1658. %%-------------------------------------------------
  1659. %% attribute typesOnly(6) with type BOOLEAN
  1660. %%-------------------------------------------------
  1661. [V6|Tlv7] = Tlv6,
  1662. Term6 = decode_boolean(V6, [1]),
  1663.  
  1664. %%-------------------------------------------------
  1665. %% attribute filter(7)   External Lightweight-Directory-Access-Protocol-V3:Filter
  1666. %%-------------------------------------------------
  1667. [V7|Tlv8] = Tlv7,
  1668. Term7 = 'dec_Filter'(V7, []),
  1669.  
  1670. %%-------------------------------------------------
  1671. %% attribute attributes(8)   External Lightweight-Directory-Access-Protocol-V3:AttributeSelection
  1672. %%-------------------------------------------------
  1673. [V8|Tlv9] = Tlv8,
  1674. Term8 = 'dec_AttributeSelection'(V8, [16]),
  1675.  
  1676. case Tlv9 of [] -> true; _ -> true end, % ... extra fields skipped
  1677. Res1 = {'SearchRequest',Term1,Term2,Term3,Term4,Term5,Term6,Term7,Term8},
  1678. Res1.
  1679.  
  1680.  
  1681. %%================================
  1682. %%  AttributeSelection
  1683. %%================================
  1684. enc_AttributeSelection(Val) ->
  1685.     enc_AttributeSelection(Val, [<<48>>]).
  1686.  
  1687. enc_AttributeSelection(Val, TagIn) ->
  1688.    {EncBytes,EncLen} = 'enc_AttributeSelection_components'(Val,[],0),
  1689.    encode_tags(TagIn, EncBytes, EncLen).
  1690.  
  1691. 'enc_AttributeSelection_components'([], AccBytes, AccLen) ->
  1692.    {lists:reverse(AccBytes),AccLen};
  1693.  
  1694. 'enc_AttributeSelection_components'([H|T],AccBytes, AccLen) ->
  1695.    {EncBytes,EncLen} = encode_restricted_string(H, [<<4>>]),
  1696.    'enc_AttributeSelection_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  1697.  
  1698.  
  1699.  
  1700. dec_AttributeSelection(Tlv) ->
  1701.    dec_AttributeSelection(Tlv, [16]).
  1702.  
  1703. dec_AttributeSelection(Tlv, TagIn) ->
  1704.    %%-------------------------------------------------
  1705.    %% decode tag and length
  1706.    %%-------------------------------------------------
  1707. Tlv1 = match_tags(Tlv, TagIn),
  1708. [decode_octet_string(V1, [4]) || V1 <- Tlv1].
  1709.  
  1710.  
  1711.  
  1712.  
  1713. %%================================
  1714. %%  Filter
  1715. %%================================
  1716. enc_Filter(Val) ->
  1717.     enc_Filter(Val, []).
  1718.  
  1719. enc_Filter(Val, TagIn) ->
  1720.    {EncBytes,EncLen} = case element(1,Val) of
  1721.       'and' ->
  1722.          'enc_Filter_and'(element(2,Val), [<<160>>]);
  1723.       'or' ->
  1724.          'enc_Filter_or'(element(2,Val), [<<161>>]);
  1725.       'not' ->
  1726.          'enc_Filter'(element(2,Val), [<<162>>]);
  1727.       equalityMatch ->
  1728.          'enc_AttributeValueAssertion'(element(2,Val), [<<163>>]);
  1729.       substrings ->
  1730.          'enc_SubstringFilter'(element(2,Val), [<<164>>]);
  1731.       greaterOrEqual ->
  1732.          'enc_AttributeValueAssertion'(element(2,Val), [<<165>>]);
  1733.       lessOrEqual ->
  1734.          'enc_AttributeValueAssertion'(element(2,Val), [<<166>>]);
  1735.       present ->
  1736.          encode_restricted_string(element(2,Val), [<<135>>]);
  1737.       approxMatch ->
  1738.          'enc_AttributeValueAssertion'(element(2,Val), [<<168>>]);
  1739.       extensibleMatch ->
  1740.          'enc_MatchingRuleAssertion'(element(2,Val), [<<169>>]);
  1741.       Else ->
  1742.          exit({error,{asn1,{invalid_choice_type,Else}}})
  1743.    end,
  1744.  
  1745. encode_tags(TagIn, EncBytes, EncLen).
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751. %%================================
  1752. %%  Filter_and
  1753. %%================================
  1754. enc_Filter_and(Val, TagIn) ->
  1755.       {EncBytes,EncLen} = 'enc_Filter_and_components'(Val,[],0),
  1756.    encode_tags(TagIn, EncBytes, EncLen).
  1757.  
  1758. 'enc_Filter_and_components'([], AccBytes, AccLen) ->
  1759.    {lists:reverse(AccBytes),AccLen};
  1760.  
  1761. 'enc_Filter_and_components'([H|T],AccBytes, AccLen) ->
  1762.    {EncBytes,EncLen} = 'enc_Filter'(H, []),
  1763.    'enc_Filter_and_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  1764.  
  1765.  
  1766.  
  1767.  
  1768. %%================================
  1769. %%  Filter_or
  1770. %%================================
  1771. enc_Filter_or(Val, TagIn) ->
  1772.       {EncBytes,EncLen} = 'enc_Filter_or_components'(Val,[],0),
  1773.    encode_tags(TagIn, EncBytes, EncLen).
  1774.  
  1775. 'enc_Filter_or_components'([], AccBytes, AccLen) ->
  1776.    {lists:reverse(AccBytes),AccLen};
  1777.  
  1778. 'enc_Filter_or_components'([H|T],AccBytes, AccLen) ->
  1779.    {EncBytes,EncLen} = 'enc_Filter'(H, []),
  1780.    'enc_Filter_or_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  1781.  
  1782.  
  1783.  
  1784. dec_Filter(Tlv) ->
  1785.    dec_Filter(Tlv, []).
  1786.  
  1787. dec_Filter(Tlv, TagIn) ->
  1788. Tlv1 = match_tags(Tlv, TagIn),
  1789. case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
  1790.  
  1791. %% 'and'
  1792.     {131072, V1} ->
  1793.         {'and', 'dec_Filter_and'(V1, [])};
  1794.  
  1795.  
  1796. %% 'or'
  1797.     {131073, V1} ->
  1798.         {'or', 'dec_Filter_or'(V1, [])};
  1799.  
  1800.  
  1801. %% 'not'
  1802.     {131074, V1} ->
  1803.         {'not', 'dec_Filter'(V1, [])};
  1804.  
  1805.  
  1806. %% 'equalityMatch'
  1807.     {131075, V1} ->
  1808.         {equalityMatch, 'dec_AttributeValueAssertion'(V1, [])};
  1809.  
  1810.  
  1811. %% 'substrings'
  1812.     {131076, V1} ->
  1813.         {substrings, 'dec_SubstringFilter'(V1, [])};
  1814.  
  1815.  
  1816. %% 'greaterOrEqual'
  1817.     {131077, V1} ->
  1818.         {greaterOrEqual, 'dec_AttributeValueAssertion'(V1, [])};
  1819.  
  1820.  
  1821. %% 'lessOrEqual'
  1822.     {131078, V1} ->
  1823.         {lessOrEqual, 'dec_AttributeValueAssertion'(V1, [])};
  1824.  
  1825.  
  1826. %% 'present'
  1827.     {131079, V1} ->
  1828.         {present, decode_octet_string(V1, [])};
  1829.  
  1830.  
  1831. %% 'approxMatch'
  1832.     {131080, V1} ->
  1833.         {approxMatch, 'dec_AttributeValueAssertion'(V1, [])};
  1834.  
  1835.  
  1836. %% 'extensibleMatch'
  1837.     {131081, V1} ->
  1838.         {extensibleMatch, 'dec_MatchingRuleAssertion'(V1, [])};
  1839.  
  1840.       Else ->
  1841.          {asn1_ExtAlt,ber_encode(Else)}
  1842.    end
  1843. .
  1844. 'dec_Filter_and'(Tlv, TagIn) ->
  1845.    %%-------------------------------------------------
  1846.    %% decode tag and length
  1847.    %%-------------------------------------------------
  1848. Tlv1 = match_tags(Tlv, TagIn),
  1849. ['dec_Filter'(V1, []) || V1 <- Tlv1].
  1850.  
  1851.  
  1852. 'dec_Filter_or'(Tlv, TagIn) ->
  1853.    %%-------------------------------------------------
  1854.    %% decode tag and length
  1855.    %%-------------------------------------------------
  1856. Tlv1 = match_tags(Tlv, TagIn),
  1857. ['dec_Filter'(V1, []) || V1 <- Tlv1].
  1858.  
  1859.  
  1860.  
  1861.  
  1862. %%================================
  1863. %%  SubstringFilter
  1864. %%================================
  1865. enc_SubstringFilter(Val) ->
  1866.     enc_SubstringFilter(Val, [<<48>>]).
  1867.  
  1868. enc_SubstringFilter(Val, TagIn) ->
  1869. {_,Cindex1,Cindex2} = Val,
  1870.  
  1871. %%-------------------------------------------------
  1872. %% attribute type(1) with type OCTET STRING
  1873. %%-------------------------------------------------
  1874.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  1875.  
  1876. %%-------------------------------------------------
  1877. %% attribute substrings(2) with type SEQUENCE OF
  1878. %%-------------------------------------------------
  1879.    {EncBytes2,EncLen2} = 'enc_SubstringFilter_substrings'(Cindex2, [<<48>>]),
  1880.  
  1881.    BytesSoFar = [EncBytes1, EncBytes2],
  1882. LenSoFar = EncLen1 + EncLen2,
  1883. encode_tags(TagIn, BytesSoFar, LenSoFar).
  1884.  
  1885.  
  1886.  
  1887. %%================================
  1888. %%  SubstringFilter_substrings
  1889. %%================================
  1890. enc_SubstringFilter_substrings(Val, TagIn) ->
  1891.       {EncBytes,EncLen} = 'enc_SubstringFilter_substrings_components'(Val,[],0),
  1892.    encode_tags(TagIn, EncBytes, EncLen).
  1893.  
  1894. 'enc_SubstringFilter_substrings_components'([], AccBytes, AccLen) ->
  1895.    {lists:reverse(AccBytes),AccLen};
  1896.  
  1897. 'enc_SubstringFilter_substrings_components'([H|T],AccBytes, AccLen) ->
  1898.    {EncBytes,EncLen} = 'enc_SubstringFilter_substrings_SEQOF'(H, []),
  1899.    'enc_SubstringFilter_substrings_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  1900.  
  1901.  
  1902.  
  1903.  
  1904. %%================================
  1905. %%  SubstringFilter_substrings_SEQOF
  1906. %%================================
  1907. enc_SubstringFilter_substrings_SEQOF(Val, TagIn) ->
  1908.       {EncBytes,EncLen} = case element(1,Val) of
  1909.       initial ->
  1910.          encode_restricted_string(element(2,Val), [<<128>>]);
  1911.       any ->
  1912.          encode_restricted_string(element(2,Val), [<<129>>]);
  1913.       final ->
  1914.          encode_restricted_string(element(2,Val), [<<130>>]);
  1915.       Else ->
  1916.          exit({error,{asn1,{invalid_choice_type,Else}}})
  1917.    end,
  1918.  
  1919. encode_tags(TagIn, EncBytes, EncLen).
  1920.  
  1921.  
  1922.  
  1923.  
  1924. dec_SubstringFilter(Tlv) ->
  1925.    dec_SubstringFilter(Tlv, [16]).
  1926.  
  1927. dec_SubstringFilter(Tlv, TagIn) ->
  1928.    %%-------------------------------------------------
  1929.    %% decode tag and length
  1930.    %%-------------------------------------------------
  1931. Tlv1 = match_tags(Tlv, TagIn),
  1932.  
  1933. %%-------------------------------------------------
  1934. %% attribute type(1) with type OCTET STRING
  1935. %%-------------------------------------------------
  1936. [V1|Tlv2] = Tlv1,
  1937. Term1 = decode_octet_string(V1, [4]),
  1938.  
  1939. %%-------------------------------------------------
  1940. %% attribute substrings(2) with type SEQUENCE OF
  1941. %%-------------------------------------------------
  1942. [V2|Tlv3] = Tlv2,
  1943. Term2 = 'dec_SubstringFilter_substrings'(V2, [16]),
  1944.  
  1945. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  1946. Res1 = {'SubstringFilter',Term1,Term2},
  1947. Res1.
  1948. 'dec_SubstringFilter_substrings'(Tlv, TagIn) ->
  1949.    %%-------------------------------------------------
  1950.    %% decode tag and length
  1951.    %%-------------------------------------------------
  1952. Tlv1 = match_tags(Tlv, TagIn),
  1953. ['dec_SubstringFilter_substrings_SEQOF'(V1, []) || V1 <- Tlv1].
  1954.  
  1955.  
  1956. 'dec_SubstringFilter_substrings_SEQOF'(Tlv, TagIn) ->
  1957. Tlv1 = match_tags(Tlv, TagIn),
  1958. case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
  1959.  
  1960. %% 'initial'
  1961.     {131072, V1} ->
  1962.         {initial, decode_octet_string(V1, [])};
  1963.  
  1964.  
  1965. %% 'any'
  1966.     {131073, V1} ->
  1967.         {any, decode_octet_string(V1, [])};
  1968.  
  1969.  
  1970. %% 'final'
  1971.     {131074, V1} ->
  1972.         {final, decode_octet_string(V1, [])};
  1973.  
  1974.       Else ->
  1975.          {asn1_ExtAlt,ber_encode(Else)}
  1976.    end
  1977. .
  1978.  
  1979.  
  1980. %%================================
  1981. %%  MatchingRuleAssertion
  1982. %%================================
  1983. enc_MatchingRuleAssertion(Val) ->
  1984.     enc_MatchingRuleAssertion(Val, [<<48>>]).
  1985.  
  1986. enc_MatchingRuleAssertion(Val, TagIn) ->
  1987. {_,Cindex1,Cindex2,Cindex3,Cindex4} = Val,
  1988.  
  1989. %%-------------------------------------------------
  1990. %% attribute matchingRule(1) with type OCTET STRING OPTIONAL
  1991. %%-------------------------------------------------
  1992.    {EncBytes1,EncLen1} =  case Cindex1 of
  1993.          asn1_NOVALUE -> {<<>>,0};
  1994.          _ ->
  1995.             encode_restricted_string(Cindex1, [<<129>>])
  1996.        end,
  1997.  
  1998. %%-------------------------------------------------
  1999. %% attribute type(2) with type OCTET STRING OPTIONAL
  2000. %%-------------------------------------------------
  2001.    {EncBytes2,EncLen2} =  case Cindex2 of
  2002.          asn1_NOVALUE -> {<<>>,0};
  2003.          _ ->
  2004.             encode_restricted_string(Cindex2, [<<130>>])
  2005.        end,
  2006.  
  2007. %%-------------------------------------------------
  2008. %% attribute matchValue(3) with type OCTET STRING
  2009. %%-------------------------------------------------
  2010.    {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<131>>]),
  2011.  
  2012. %%-------------------------------------------------
  2013. %% attribute dnAttributes(4) with type BOOLEAN DEFAULT = false
  2014. %%-------------------------------------------------
  2015.    {EncBytes4,EncLen4} =  case Cindex4 of
  2016.          asn1_DEFAULT ->
  2017.             {<<>>,0};
  2018.          _ when Cindex4 =:= false ->
  2019.             {<<>>,0};
  2020.          _ ->
  2021.             encode_boolean(Cindex4, [<<132>>])
  2022.        end,
  2023.  
  2024.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4],
  2025. LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4,
  2026. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2027.  
  2028.  
  2029. dec_MatchingRuleAssertion(Tlv) ->
  2030.    dec_MatchingRuleAssertion(Tlv, [16]).
  2031.  
  2032. dec_MatchingRuleAssertion(Tlv, TagIn) ->
  2033.    %%-------------------------------------------------
  2034.    %% decode tag and length
  2035.    %%-------------------------------------------------
  2036. Tlv1 = match_tags(Tlv, TagIn),
  2037.  
  2038. %%-------------------------------------------------
  2039. %% attribute matchingRule(1) with type OCTET STRING OPTIONAL
  2040. %%-------------------------------------------------
  2041. {Term1,Tlv2} = case Tlv1 of
  2042. [{131073,V1}|TempTlv2] ->
  2043.     {decode_octet_string(V1, []), TempTlv2};
  2044.     _ ->
  2045.         { asn1_NOVALUE, Tlv1}
  2046. end,
  2047.  
  2048. %%-------------------------------------------------
  2049. %% attribute type(2) with type OCTET STRING OPTIONAL
  2050. %%-------------------------------------------------
  2051. {Term2,Tlv3} = case Tlv2 of
  2052. [{131074,V2}|TempTlv3] ->
  2053.     {decode_octet_string(V2, []), TempTlv3};
  2054.     _ ->
  2055.         { asn1_NOVALUE, Tlv2}
  2056. end,
  2057.  
  2058. %%-------------------------------------------------
  2059. %% attribute matchValue(3) with type OCTET STRING
  2060. %%-------------------------------------------------
  2061. [V3|Tlv4] = Tlv3,
  2062. Term3 = decode_octet_string(V3, [131075]),
  2063.  
  2064. %%-------------------------------------------------
  2065. %% attribute dnAttributes(4) with type BOOLEAN DEFAULT = false
  2066. %%-------------------------------------------------
  2067. {Term4,Tlv5} = case Tlv4 of
  2068. [{131076,V4}|TempTlv5] ->
  2069.     {decode_boolean(V4, []), TempTlv5};
  2070.     _ ->
  2071.         {false,Tlv4}
  2072. end,
  2073.  
  2074. case Tlv5 of [] -> true; _ -> true end, % ... extra fields skipped
  2075. Res1 = {'MatchingRuleAssertion',Term1,Term2,Term3,Term4},
  2076. Res1.
  2077.  
  2078.  
  2079. %%================================
  2080. %%  SearchResultEntry
  2081. %%================================
  2082. enc_SearchResultEntry(Val) ->
  2083.     enc_SearchResultEntry(Val, [<<100>>]).
  2084.  
  2085. enc_SearchResultEntry(Val, TagIn) ->
  2086. {_,Cindex1,Cindex2} = Val,
  2087.  
  2088. %%-------------------------------------------------
  2089. %% attribute objectName(1) with type OCTET STRING
  2090. %%-------------------------------------------------
  2091.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  2092.  
  2093. %%-------------------------------------------------
  2094. %% attribute attributes(2)   External Lightweight-Directory-Access-Protocol-V3:PartialAttributeList
  2095. %%-------------------------------------------------
  2096.    {EncBytes2,EncLen2} = 'enc_PartialAttributeList'(Cindex2, [<<48>>]),
  2097.  
  2098.    BytesSoFar = [EncBytes1, EncBytes2],
  2099. LenSoFar = EncLen1 + EncLen2,
  2100. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2101.  
  2102.  
  2103. dec_SearchResultEntry(Tlv) ->
  2104.    dec_SearchResultEntry(Tlv, [65540]).
  2105.  
  2106. dec_SearchResultEntry(Tlv, TagIn) ->
  2107.    %%-------------------------------------------------
  2108.    %% decode tag and length
  2109.    %%-------------------------------------------------
  2110. Tlv1 = match_tags(Tlv, TagIn),
  2111.  
  2112. %%-------------------------------------------------
  2113. %% attribute objectName(1) with type OCTET STRING
  2114. %%-------------------------------------------------
  2115. [V1|Tlv2] = Tlv1,
  2116. Term1 = decode_octet_string(V1, [4]),
  2117.  
  2118. %%-------------------------------------------------
  2119. %% attribute attributes(2)   External Lightweight-Directory-Access-Protocol-V3:PartialAttributeList
  2120. %%-------------------------------------------------
  2121. [V2|Tlv3] = Tlv2,
  2122. Term2 = 'dec_PartialAttributeList'(V2, [16]),
  2123.  
  2124. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  2125. Res1 = {'SearchResultEntry',Term1,Term2},
  2126. Res1.
  2127.  
  2128.  
  2129. %%================================
  2130. %%  PartialAttributeList
  2131. %%================================
  2132. enc_PartialAttributeList(Val) ->
  2133.     enc_PartialAttributeList(Val, [<<48>>]).
  2134.  
  2135. enc_PartialAttributeList(Val, TagIn) ->
  2136.    {EncBytes,EncLen} = 'enc_PartialAttributeList_components'(Val,[],0),
  2137.    encode_tags(TagIn, EncBytes, EncLen).
  2138.  
  2139. 'enc_PartialAttributeList_components'([], AccBytes, AccLen) ->
  2140.    {lists:reverse(AccBytes),AccLen};
  2141.  
  2142. 'enc_PartialAttributeList_components'([H|T],AccBytes, AccLen) ->
  2143.    {EncBytes,EncLen} = 'enc_PartialAttribute'(H, [<<48>>]),
  2144.    'enc_PartialAttributeList_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  2145.  
  2146.  
  2147.  
  2148. dec_PartialAttributeList(Tlv) ->
  2149.    dec_PartialAttributeList(Tlv, [16]).
  2150.  
  2151. dec_PartialAttributeList(Tlv, TagIn) ->
  2152.    %%-------------------------------------------------
  2153.    %% decode tag and length
  2154.    %%-------------------------------------------------
  2155. Tlv1 = match_tags(Tlv, TagIn),
  2156. ['dec_PartialAttribute'(V1, [16]) || V1 <- Tlv1].
  2157.  
  2158.  
  2159.  
  2160.  
  2161. %%================================
  2162. %%  SearchResultReference
  2163. %%================================
  2164. enc_SearchResultReference(Val) ->
  2165.     enc_SearchResultReference(Val, [<<115>>]).
  2166.  
  2167. enc_SearchResultReference(Val, TagIn) ->
  2168.    {EncBytes,EncLen} = 'enc_SearchResultReference_components'(Val,[],0),
  2169.    encode_tags(TagIn, EncBytes, EncLen).
  2170.  
  2171. 'enc_SearchResultReference_components'([], AccBytes, AccLen) ->
  2172.    {lists:reverse(AccBytes),AccLen};
  2173.  
  2174. 'enc_SearchResultReference_components'([H|T],AccBytes, AccLen) ->
  2175.    {EncBytes,EncLen} = encode_restricted_string(H, [<<4>>]),
  2176.    'enc_SearchResultReference_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  2177.  
  2178.  
  2179.  
  2180. dec_SearchResultReference(Tlv) ->
  2181.    dec_SearchResultReference(Tlv, [65555]).
  2182.  
  2183. dec_SearchResultReference(Tlv, TagIn) ->
  2184.    %%-------------------------------------------------
  2185.    %% decode tag and length
  2186.    %%-------------------------------------------------
  2187. Tlv1 = match_tags(Tlv, TagIn),
  2188. [decode_octet_string(V1, [4]) || V1 <- Tlv1].
  2189.  
  2190.  
  2191.  
  2192.  
  2193. %%================================
  2194. %%  SearchResultDone
  2195. %%================================
  2196. enc_SearchResultDone(Val) ->
  2197.     enc_SearchResultDone(Val, [<<101>>]).
  2198.  
  2199. enc_SearchResultDone(Val, TagIn) ->
  2200.    enc_LDAPResult(Val, TagIn).
  2201.  
  2202.  
  2203. dec_SearchResultDone(Tlv) ->
  2204.    dec_SearchResultDone(Tlv, [65541]).
  2205.  
  2206. dec_SearchResultDone(Tlv, TagIn) ->
  2207. 'dec_LDAPResult'(Tlv, TagIn).
  2208.  
  2209.  
  2210.  
  2211. %%================================
  2212. %%  ModifyRequest
  2213. %%================================
  2214. enc_ModifyRequest(Val) ->
  2215.     enc_ModifyRequest(Val, [<<102>>]).
  2216.  
  2217. enc_ModifyRequest(Val, TagIn) ->
  2218. {_,Cindex1,Cindex2} = Val,
  2219.  
  2220. %%-------------------------------------------------
  2221. %% attribute object(1) with type OCTET STRING
  2222. %%-------------------------------------------------
  2223.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  2224.  
  2225. %%-------------------------------------------------
  2226. %% attribute changes(2) with type SEQUENCE OF
  2227. %%-------------------------------------------------
  2228.    {EncBytes2,EncLen2} = 'enc_ModifyRequest_changes'(Cindex2, [<<48>>]),
  2229.  
  2230.    BytesSoFar = [EncBytes1, EncBytes2],
  2231. LenSoFar = EncLen1 + EncLen2,
  2232. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2233.  
  2234.  
  2235.  
  2236. %%================================
  2237. %%  ModifyRequest_changes
  2238. %%================================
  2239. enc_ModifyRequest_changes(Val, TagIn) ->
  2240.       {EncBytes,EncLen} = 'enc_ModifyRequest_changes_components'(Val,[],0),
  2241.    encode_tags(TagIn, EncBytes, EncLen).
  2242.  
  2243. 'enc_ModifyRequest_changes_components'([], AccBytes, AccLen) ->
  2244.    {lists:reverse(AccBytes),AccLen};
  2245.  
  2246. 'enc_ModifyRequest_changes_components'([H|T],AccBytes, AccLen) ->
  2247.    {EncBytes,EncLen} = 'enc_ModifyRequest_changes_SEQOF'(H, [<<48>>]),
  2248.    'enc_ModifyRequest_changes_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  2249.  
  2250.  
  2251.  
  2252.  
  2253. %%================================
  2254. %%  ModifyRequest_changes_SEQOF
  2255. %%================================
  2256. enc_ModifyRequest_changes_SEQOF(Val, TagIn) ->
  2257.    {_,Cindex1,Cindex2} = Val,
  2258.  
  2259. %%-------------------------------------------------
  2260. %% attribute operation(1) with type ENUMERATED
  2261. %%-------------------------------------------------
  2262.    {EncBytes1,EncLen1} = case Cindex1 of
  2263. add -> encode_tags([<<10>>], [0], 1);
  2264. delete -> encode_tags([<<10>>], [1], 1);
  2265. replace -> encode_tags([<<10>>], [2], 1);
  2266. Enumval1 -> exit({error,{asn1, {enumerated_not_in_range,Enumval1}}})
  2267. end,
  2268.  
  2269. %%-------------------------------------------------
  2270. %% attribute modification(2)   External Lightweight-Directory-Access-Protocol-V3:PartialAttribute
  2271. %%-------------------------------------------------
  2272.    {EncBytes2,EncLen2} = 'enc_PartialAttribute'(Cindex2, [<<48>>]),
  2273.  
  2274.    BytesSoFar = [EncBytes1, EncBytes2],
  2275. LenSoFar = EncLen1 + EncLen2,
  2276. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2277.  
  2278.  
  2279. dec_ModifyRequest(Tlv) ->
  2280.    dec_ModifyRequest(Tlv, [65542]).
  2281.  
  2282. dec_ModifyRequest(Tlv, TagIn) ->
  2283.    %%-------------------------------------------------
  2284.    %% decode tag and length
  2285.    %%-------------------------------------------------
  2286. Tlv1 = match_tags(Tlv, TagIn),
  2287.  
  2288. %%-------------------------------------------------
  2289. %% attribute object(1) with type OCTET STRING
  2290. %%-------------------------------------------------
  2291. [V1|Tlv2] = Tlv1,
  2292. Term1 = decode_octet_string(V1, [4]),
  2293.  
  2294. %%-------------------------------------------------
  2295. %% attribute changes(2) with type SEQUENCE OF
  2296. %%-------------------------------------------------
  2297. [V2|Tlv3] = Tlv2,
  2298. Term2 = 'dec_ModifyRequest_changes'(V2, [16]),
  2299.  
  2300. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  2301. Res1 = {'ModifyRequest',Term1,Term2},
  2302. Res1.
  2303. 'dec_ModifyRequest_changes'(Tlv, TagIn) ->
  2304.    %%-------------------------------------------------
  2305.    %% decode tag and length
  2306.    %%-------------------------------------------------
  2307. Tlv1 = match_tags(Tlv, TagIn),
  2308. ['dec_ModifyRequest_changes_SEQOF'(V1, [16]) || V1 <- Tlv1].
  2309.  
  2310.  
  2311. 'dec_ModifyRequest_changes_SEQOF'(Tlv, TagIn) ->
  2312.    %%-------------------------------------------------
  2313.    %% decode tag and length
  2314.    %%-------------------------------------------------
  2315. Tlv1 = match_tags(Tlv, TagIn),
  2316.  
  2317. %%-------------------------------------------------
  2318. %% attribute operation(1) with type ENUMERATED
  2319. %%-------------------------------------------------
  2320. [V1|Tlv2] = Tlv1,
  2321. Term1 = case decode_integer(V1, [10]) of
  2322. 0 -> add;
  2323. 1 -> delete;
  2324. 2 -> replace;
  2325. Default1 -> {asn1_enum,Default1}
  2326. end,
  2327.  
  2328. %%-------------------------------------------------
  2329. %% attribute modification(2)   External Lightweight-Directory-Access-Protocol-V3:PartialAttribute
  2330. %%-------------------------------------------------
  2331. [V2|Tlv3] = Tlv2,
  2332. Term2 = 'dec_PartialAttribute'(V2, [16]),
  2333.  
  2334. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  2335. Res1 = {'ModifyRequest_changes_SEQOF',Term1,Term2},
  2336. Res1.
  2337.  
  2338.  
  2339. %%================================
  2340. %%  ModifyResponse
  2341. %%================================
  2342. enc_ModifyResponse(Val) ->
  2343.     enc_ModifyResponse(Val, [<<103>>]).
  2344.  
  2345. enc_ModifyResponse(Val, TagIn) ->
  2346.    enc_LDAPResult(Val, TagIn).
  2347.  
  2348.  
  2349. dec_ModifyResponse(Tlv) ->
  2350.    dec_ModifyResponse(Tlv, [65543]).
  2351.  
  2352. dec_ModifyResponse(Tlv, TagIn) ->
  2353. 'dec_LDAPResult'(Tlv, TagIn).
  2354.  
  2355.  
  2356.  
  2357. %%================================
  2358. %%  AddRequest
  2359. %%================================
  2360. enc_AddRequest(Val) ->
  2361.     enc_AddRequest(Val, [<<104>>]).
  2362.  
  2363. enc_AddRequest(Val, TagIn) ->
  2364. {_,Cindex1,Cindex2} = Val,
  2365.  
  2366. %%-------------------------------------------------
  2367. %% attribute entry(1) with type OCTET STRING
  2368. %%-------------------------------------------------
  2369.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  2370.  
  2371. %%-------------------------------------------------
  2372. %% attribute attributes(2)   External Lightweight-Directory-Access-Protocol-V3:AttributeList
  2373. %%-------------------------------------------------
  2374.    {EncBytes2,EncLen2} = 'enc_AttributeList'(Cindex2, [<<48>>]),
  2375.  
  2376.    BytesSoFar = [EncBytes1, EncBytes2],
  2377. LenSoFar = EncLen1 + EncLen2,
  2378. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2379.  
  2380.  
  2381. dec_AddRequest(Tlv) ->
  2382.    dec_AddRequest(Tlv, [65544]).
  2383.  
  2384. dec_AddRequest(Tlv, TagIn) ->
  2385.    %%-------------------------------------------------
  2386.    %% decode tag and length
  2387.    %%-------------------------------------------------
  2388. Tlv1 = match_tags(Tlv, TagIn),
  2389.  
  2390. %%-------------------------------------------------
  2391. %% attribute entry(1) with type OCTET STRING
  2392. %%-------------------------------------------------
  2393. [V1|Tlv2] = Tlv1,
  2394. Term1 = decode_octet_string(V1, [4]),
  2395.  
  2396. %%-------------------------------------------------
  2397. %% attribute attributes(2)   External Lightweight-Directory-Access-Protocol-V3:AttributeList
  2398. %%-------------------------------------------------
  2399. [V2|Tlv3] = Tlv2,
  2400. Term2 = 'dec_AttributeList'(V2, [16]),
  2401.  
  2402. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  2403. Res1 = {'AddRequest',Term1,Term2},
  2404. Res1.
  2405.  
  2406.  
  2407. %%================================
  2408. %%  AttributeList
  2409. %%================================
  2410. enc_AttributeList(Val) ->
  2411.     enc_AttributeList(Val, [<<48>>]).
  2412.  
  2413. enc_AttributeList(Val, TagIn) ->
  2414.    {EncBytes,EncLen} = 'enc_AttributeList_components'(Val,[],0),
  2415.    encode_tags(TagIn, EncBytes, EncLen).
  2416.  
  2417. 'enc_AttributeList_components'([], AccBytes, AccLen) ->
  2418.    {lists:reverse(AccBytes),AccLen};
  2419.  
  2420. 'enc_AttributeList_components'([H|T],AccBytes, AccLen) ->
  2421.    {EncBytes,EncLen} = 'enc_Attribute'(H, [<<48>>]),
  2422.    'enc_AttributeList_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
  2423.  
  2424.  
  2425.  
  2426. dec_AttributeList(Tlv) ->
  2427.    dec_AttributeList(Tlv, [16]).
  2428.  
  2429. dec_AttributeList(Tlv, TagIn) ->
  2430.    %%-------------------------------------------------
  2431.    %% decode tag and length
  2432.    %%-------------------------------------------------
  2433. Tlv1 = match_tags(Tlv, TagIn),
  2434. ['dec_Attribute'(V1, [16]) || V1 <- Tlv1].
  2435.  
  2436.  
  2437.  
  2438.  
  2439. %%================================
  2440. %%  AddResponse
  2441. %%================================
  2442. enc_AddResponse(Val) ->
  2443.     enc_AddResponse(Val, [<<105>>]).
  2444.  
  2445. enc_AddResponse(Val, TagIn) ->
  2446.    enc_LDAPResult(Val, TagIn).
  2447.  
  2448.  
  2449. dec_AddResponse(Tlv) ->
  2450.    dec_AddResponse(Tlv, [65545]).
  2451.  
  2452. dec_AddResponse(Tlv, TagIn) ->
  2453. 'dec_LDAPResult'(Tlv, TagIn).
  2454.  
  2455.  
  2456.  
  2457. %%================================
  2458. %%  DelRequest
  2459. %%================================
  2460. enc_DelRequest(Val) ->
  2461.     enc_DelRequest(Val, [<<74>>]).
  2462.  
  2463. enc_DelRequest(Val, TagIn) ->
  2464. encode_restricted_string(Val, TagIn).
  2465.  
  2466.  
  2467. dec_DelRequest(Tlv) ->
  2468.    dec_DelRequest(Tlv, [65546]).
  2469.  
  2470. dec_DelRequest(Tlv, TagIn) ->
  2471. decode_octet_string(Tlv, TagIn).
  2472.  
  2473.  
  2474.  
  2475. %%================================
  2476. %%  DelResponse
  2477. %%================================
  2478. enc_DelResponse(Val) ->
  2479.     enc_DelResponse(Val, [<<107>>]).
  2480.  
  2481. enc_DelResponse(Val, TagIn) ->
  2482.    enc_LDAPResult(Val, TagIn).
  2483.  
  2484.  
  2485. dec_DelResponse(Tlv) ->
  2486.    dec_DelResponse(Tlv, [65547]).
  2487.  
  2488. dec_DelResponse(Tlv, TagIn) ->
  2489. 'dec_LDAPResult'(Tlv, TagIn).
  2490.  
  2491.  
  2492.  
  2493. %%================================
  2494. %%  ModifyDNRequest
  2495. %%================================
  2496. enc_ModifyDNRequest(Val) ->
  2497.     enc_ModifyDNRequest(Val, [<<108>>]).
  2498.  
  2499. enc_ModifyDNRequest(Val, TagIn) ->
  2500. {_,Cindex1,Cindex2,Cindex3,Cindex4} = Val,
  2501.  
  2502. %%-------------------------------------------------
  2503. %% attribute entry(1) with type OCTET STRING
  2504. %%-------------------------------------------------
  2505.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  2506.  
  2507. %%-------------------------------------------------
  2508. %% attribute newrdn(2) with type OCTET STRING
  2509. %%-------------------------------------------------
  2510.    {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]),
  2511.  
  2512. %%-------------------------------------------------
  2513. %% attribute deleteoldrdn(3) with type BOOLEAN
  2514. %%-------------------------------------------------
  2515.    {EncBytes3,EncLen3} = encode_boolean(Cindex3, [<<1>>]),
  2516.  
  2517. %%-------------------------------------------------
  2518. %% attribute newSuperior(4) with type OCTET STRING OPTIONAL
  2519. %%-------------------------------------------------
  2520.    {EncBytes4,EncLen4} =  case Cindex4 of
  2521.          asn1_NOVALUE -> {<<>>,0};
  2522.          _ ->
  2523.             encode_restricted_string(Cindex4, [<<128>>])
  2524.        end,
  2525.  
  2526.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4],
  2527. LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4,
  2528. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2529.  
  2530.  
  2531. dec_ModifyDNRequest(Tlv) ->
  2532.    dec_ModifyDNRequest(Tlv, [65548]).
  2533.  
  2534. dec_ModifyDNRequest(Tlv, TagIn) ->
  2535.    %%-------------------------------------------------
  2536.    %% decode tag and length
  2537.    %%-------------------------------------------------
  2538. Tlv1 = match_tags(Tlv, TagIn),
  2539.  
  2540. %%-------------------------------------------------
  2541. %% attribute entry(1) with type OCTET STRING
  2542. %%-------------------------------------------------
  2543. [V1|Tlv2] = Tlv1,
  2544. Term1 = decode_octet_string(V1, [4]),
  2545.  
  2546. %%-------------------------------------------------
  2547. %% attribute newrdn(2) with type OCTET STRING
  2548. %%-------------------------------------------------
  2549. [V2|Tlv3] = Tlv2,
  2550. Term2 = decode_octet_string(V2, [4]),
  2551.  
  2552. %%-------------------------------------------------
  2553. %% attribute deleteoldrdn(3) with type BOOLEAN
  2554. %%-------------------------------------------------
  2555. [V3|Tlv4] = Tlv3,
  2556. Term3 = decode_boolean(V3, [1]),
  2557.  
  2558. %%-------------------------------------------------
  2559. %% attribute newSuperior(4) with type OCTET STRING OPTIONAL
  2560. %%-------------------------------------------------
  2561. {Term4,Tlv5} = case Tlv4 of
  2562. [{131072,V4}|TempTlv5] ->
  2563.     {decode_octet_string(V4, []), TempTlv5};
  2564.     _ ->
  2565.         { asn1_NOVALUE, Tlv4}
  2566. end,
  2567.  
  2568. case Tlv5 of [] -> true; _ -> true end, % ... extra fields skipped
  2569. Res1 = {'ModifyDNRequest',Term1,Term2,Term3,Term4},
  2570. Res1.
  2571.  
  2572.  
  2573. %%================================
  2574. %%  ModifyDNResponse
  2575. %%================================
  2576. enc_ModifyDNResponse(Val) ->
  2577.     enc_ModifyDNResponse(Val, [<<109>>]).
  2578.  
  2579. enc_ModifyDNResponse(Val, TagIn) ->
  2580.    enc_LDAPResult(Val, TagIn).
  2581.  
  2582.  
  2583. dec_ModifyDNResponse(Tlv) ->
  2584.    dec_ModifyDNResponse(Tlv, [65549]).
  2585.  
  2586. dec_ModifyDNResponse(Tlv, TagIn) ->
  2587. 'dec_LDAPResult'(Tlv, TagIn).
  2588.  
  2589.  
  2590.  
  2591. %%================================
  2592. %%  CompareRequest
  2593. %%================================
  2594. enc_CompareRequest(Val) ->
  2595.     enc_CompareRequest(Val, [<<110>>]).
  2596.  
  2597. enc_CompareRequest(Val, TagIn) ->
  2598. {_,Cindex1,Cindex2} = Val,
  2599.  
  2600. %%-------------------------------------------------
  2601. %% attribute entry(1) with type OCTET STRING
  2602. %%-------------------------------------------------
  2603.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<4>>]),
  2604.  
  2605. %%-------------------------------------------------
  2606. %% attribute ava(2)   External Lightweight-Directory-Access-Protocol-V3:AttributeValueAssertion
  2607. %%-------------------------------------------------
  2608.    {EncBytes2,EncLen2} = 'enc_AttributeValueAssertion'(Cindex2, [<<48>>]),
  2609.  
  2610.    BytesSoFar = [EncBytes1, EncBytes2],
  2611. LenSoFar = EncLen1 + EncLen2,
  2612. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2613.  
  2614.  
  2615. dec_CompareRequest(Tlv) ->
  2616.    dec_CompareRequest(Tlv, [65550]).
  2617.  
  2618. dec_CompareRequest(Tlv, TagIn) ->
  2619.    %%-------------------------------------------------
  2620.    %% decode tag and length
  2621.    %%-------------------------------------------------
  2622. Tlv1 = match_tags(Tlv, TagIn),
  2623.  
  2624. %%-------------------------------------------------
  2625. %% attribute entry(1) with type OCTET STRING
  2626. %%-------------------------------------------------
  2627. [V1|Tlv2] = Tlv1,
  2628. Term1 = decode_octet_string(V1, [4]),
  2629.  
  2630. %%-------------------------------------------------
  2631. %% attribute ava(2)   External Lightweight-Directory-Access-Protocol-V3:AttributeValueAssertion
  2632. %%-------------------------------------------------
  2633. [V2|Tlv3] = Tlv2,
  2634. Term2 = 'dec_AttributeValueAssertion'(V2, [16]),
  2635.  
  2636. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  2637. Res1 = {'CompareRequest',Term1,Term2},
  2638. Res1.
  2639.  
  2640.  
  2641. %%================================
  2642. %%  CompareResponse
  2643. %%================================
  2644. enc_CompareResponse(Val) ->
  2645.     enc_CompareResponse(Val, [<<111>>]).
  2646.  
  2647. enc_CompareResponse(Val, TagIn) ->
  2648.    enc_LDAPResult(Val, TagIn).
  2649.  
  2650.  
  2651. dec_CompareResponse(Tlv) ->
  2652.    dec_CompareResponse(Tlv, [65551]).
  2653.  
  2654. dec_CompareResponse(Tlv, TagIn) ->
  2655. 'dec_LDAPResult'(Tlv, TagIn).
  2656.  
  2657.  
  2658.  
  2659. %%================================
  2660. %%  AbandonRequest
  2661. %%================================
  2662. enc_AbandonRequest(Val) ->
  2663.     enc_AbandonRequest(Val, [<<80>>]).
  2664.  
  2665. enc_AbandonRequest(Val, TagIn) ->
  2666. encode_integer(Val, TagIn).
  2667.  
  2668.  
  2669. dec_AbandonRequest(Tlv) ->
  2670.    dec_AbandonRequest(Tlv, [65552]).
  2671.  
  2672. dec_AbandonRequest(Tlv, TagIn) ->
  2673. begin
  2674. Val1 = decode_integer(Tlv, TagIn),
  2675. if 0 =< Val1, Val1 =< 2147483647 ->
  2676. Val1;
  2677. true ->
  2678. exit({error,{asn1,bad_range}})
  2679. end
  2680. end.
  2681.  
  2682.  
  2683.  
  2684. %%================================
  2685. %%  ExtendedRequest
  2686. %%================================
  2687. enc_ExtendedRequest(Val) ->
  2688.     enc_ExtendedRequest(Val, [<<119>>]).
  2689.  
  2690. enc_ExtendedRequest(Val, TagIn) ->
  2691. {_,Cindex1,Cindex2} = Val,
  2692.  
  2693. %%-------------------------------------------------
  2694. %% attribute requestName(1) with type OCTET STRING
  2695. %%-------------------------------------------------
  2696.    {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<128>>]),
  2697.  
  2698. %%-------------------------------------------------
  2699. %% attribute requestValue(2) with type OCTET STRING OPTIONAL
  2700. %%-------------------------------------------------
  2701.    {EncBytes2,EncLen2} =  case Cindex2 of
  2702.          asn1_NOVALUE -> {<<>>,0};
  2703.          _ ->
  2704.             encode_restricted_string(Cindex2, [<<129>>])
  2705.        end,
  2706.  
  2707.    BytesSoFar = [EncBytes1, EncBytes2],
  2708. LenSoFar = EncLen1 + EncLen2,
  2709. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2710.  
  2711.  
  2712. dec_ExtendedRequest(Tlv) ->
  2713.    dec_ExtendedRequest(Tlv, [65559]).
  2714.  
  2715. dec_ExtendedRequest(Tlv, TagIn) ->
  2716.    %%-------------------------------------------------
  2717.    %% decode tag and length
  2718.    %%-------------------------------------------------
  2719. Tlv1 = match_tags(Tlv, TagIn),
  2720.  
  2721. %%-------------------------------------------------
  2722. %% attribute requestName(1) with type OCTET STRING
  2723. %%-------------------------------------------------
  2724. [V1|Tlv2] = Tlv1,
  2725. Term1 = decode_octet_string(V1, [131072]),
  2726.  
  2727. %%-------------------------------------------------
  2728. %% attribute requestValue(2) with type OCTET STRING OPTIONAL
  2729. %%-------------------------------------------------
  2730. {Term2,Tlv3} = case Tlv2 of
  2731. [{131073,V2}|TempTlv3] ->
  2732.     {decode_octet_string(V2, []), TempTlv3};
  2733.     _ ->
  2734.         { asn1_NOVALUE, Tlv2}
  2735. end,
  2736.  
  2737. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  2738. Res1 = {'ExtendedRequest',Term1,Term2},
  2739. Res1.
  2740.  
  2741.  
  2742. %%================================
  2743. %%  ExtendedResponse
  2744. %%================================
  2745. enc_ExtendedResponse(Val) ->
  2746.     enc_ExtendedResponse(Val, [<<120>>]).
  2747.  
  2748. enc_ExtendedResponse(Val, TagIn) ->
  2749. {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5,Cindex6} = Val,
  2750.  
  2751. %%-------------------------------------------------
  2752. %% attribute resultCode(1) with type ENUMERATED
  2753. %%-------------------------------------------------
  2754.    {EncBytes1,EncLen1} = case Cindex1 of
  2755. success -> encode_tags([<<10>>], [0], 1);
  2756. operationsError -> encode_tags([<<10>>], [1], 1);
  2757. protocolError -> encode_tags([<<10>>], [2], 1);
  2758. timeLimitExceeded -> encode_tags([<<10>>], [3], 1);
  2759. sizeLimitExceeded -> encode_tags([<<10>>], [4], 1);
  2760. compareFalse -> encode_tags([<<10>>], [5], 1);
  2761. compareTrue -> encode_tags([<<10>>], [6], 1);
  2762. authMethodNotSupported -> encode_tags([<<10>>], [7], 1);
  2763. strongerAuthRequired -> encode_tags([<<10>>], [8], 1);
  2764. referral -> encode_tags([<<10>>], [10], 1);
  2765. adminLimitExceeded -> encode_tags([<<10>>], [11], 1);
  2766. unavailableCriticalExtension -> encode_tags([<<10>>], [12], 1);
  2767. confidentialityRequired -> encode_tags([<<10>>], [13], 1);
  2768. saslBindInProgress -> encode_tags([<<10>>], [14], 1);
  2769. noSuchAttribute -> encode_tags([<<10>>], [16], 1);
  2770. undefinedAttributeType -> encode_tags([<<10>>], [17], 1);
  2771. inappropriateMatching -> encode_tags([<<10>>], [18], 1);
  2772. constraintViolation -> encode_tags([<<10>>], [19], 1);
  2773. attributeOrValueExists -> encode_tags([<<10>>], [20], 1);
  2774. invalidAttributeSyntax -> encode_tags([<<10>>], [21], 1);
  2775. noSuchObject -> encode_tags([<<10>>], [32], 1);
  2776. aliasProblem -> encode_tags([<<10>>], [33], 1);
  2777. invalidDNSyntax -> encode_tags([<<10>>], [34], 1);
  2778. aliasDereferencingProblem -> encode_tags([<<10>>], [36], 1);
  2779. inappropriateAuthentication -> encode_tags([<<10>>], [48], 1);
  2780. invalidCredentials -> encode_tags([<<10>>], [49], 1);
  2781. insufficientAccessRights -> encode_tags([<<10>>], [50], 1);
  2782. busy -> encode_tags([<<10>>], [51], 1);
  2783. unavailable -> encode_tags([<<10>>], [52], 1);
  2784. unwillingToPerform -> encode_tags([<<10>>], [53], 1);
  2785. loopDetect -> encode_tags([<<10>>], [54], 1);
  2786. namingViolation -> encode_tags([<<10>>], [64], 1);
  2787. objectClassViolation -> encode_tags([<<10>>], [65], 1);
  2788. notAllowedOnNonLeaf -> encode_tags([<<10>>], [66], 1);
  2789. notAllowedOnRDN -> encode_tags([<<10>>], [67], 1);
  2790. entryAlreadyExists -> encode_tags([<<10>>], [68], 1);
  2791. objectClassModsProhibited -> encode_tags([<<10>>], [69], 1);
  2792. affectsMultipleDSAs -> encode_tags([<<10>>], [71], 1);
  2793. other -> encode_tags([<<10>>], [80], 1);
  2794. Enumval1 -> exit({error,{asn1, {enumerated_not_in_range,Enumval1}}})
  2795. end,
  2796.  
  2797. %%-------------------------------------------------
  2798. %% attribute matchedDN(2) with type OCTET STRING
  2799. %%-------------------------------------------------
  2800.    {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]),
  2801.  
  2802. %%-------------------------------------------------
  2803. %% attribute diagnosticMessage(3) with type OCTET STRING
  2804. %%-------------------------------------------------
  2805.    {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<4>>]),
  2806.  
  2807. %%-------------------------------------------------
  2808. %% attribute referral(4)   External Lightweight-Directory-Access-Protocol-V3:Referral OPTIONAL
  2809. %%-------------------------------------------------
  2810.    {EncBytes4,EncLen4} =  case Cindex4 of
  2811.          asn1_NOVALUE -> {<<>>,0};
  2812.          _ ->
  2813.             'enc_Referral'(Cindex4, [<<163>>])
  2814.        end,
  2815.  
  2816. %%-------------------------------------------------
  2817. %% attribute responseName(5) with type OCTET STRING OPTIONAL
  2818. %%-------------------------------------------------
  2819.    {EncBytes5,EncLen5} =  case Cindex5 of
  2820.          asn1_NOVALUE -> {<<>>,0};
  2821.          _ ->
  2822.             encode_restricted_string(Cindex5, [<<138>>])
  2823.        end,
  2824.  
  2825. %%-------------------------------------------------
  2826. %% attribute responseValue(6) with type OCTET STRING OPTIONAL
  2827. %%-------------------------------------------------
  2828.    {EncBytes6,EncLen6} =  case Cindex6 of
  2829.          asn1_NOVALUE -> {<<>>,0};
  2830.          _ ->
  2831.             encode_restricted_string(Cindex6, [<<139>>])
  2832.        end,
  2833.  
  2834.    BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5, EncBytes6],
  2835. LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5 + EncLen6,
  2836. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2837.  
  2838.  
  2839. dec_ExtendedResponse(Tlv) ->
  2840.    dec_ExtendedResponse(Tlv, [65560]).
  2841.  
  2842. dec_ExtendedResponse(Tlv, TagIn) ->
  2843.    %%-------------------------------------------------
  2844.    %% decode tag and length
  2845.    %%-------------------------------------------------
  2846. Tlv1 = match_tags(Tlv, TagIn),
  2847.  
  2848. %%-------------------------------------------------
  2849. %% attribute resultCode(1) with type ENUMERATED
  2850. %%-------------------------------------------------
  2851. [V1|Tlv2] = Tlv1,
  2852. Term1 = case decode_integer(V1, [10]) of
  2853. 0 -> success;
  2854. 1 -> operationsError;
  2855. 2 -> protocolError;
  2856. 3 -> timeLimitExceeded;
  2857. 4 -> sizeLimitExceeded;
  2858. 5 -> compareFalse;
  2859. 6 -> compareTrue;
  2860. 7 -> authMethodNotSupported;
  2861. 8 -> strongerAuthRequired;
  2862. 10 -> referral;
  2863. 11 -> adminLimitExceeded;
  2864. 12 -> unavailableCriticalExtension;
  2865. 13 -> confidentialityRequired;
  2866. 14 -> saslBindInProgress;
  2867. 16 -> noSuchAttribute;
  2868. 17 -> undefinedAttributeType;
  2869. 18 -> inappropriateMatching;
  2870. 19 -> constraintViolation;
  2871. 20 -> attributeOrValueExists;
  2872. 21 -> invalidAttributeSyntax;
  2873. 32 -> noSuchObject;
  2874. 33 -> aliasProblem;
  2875. 34 -> invalidDNSyntax;
  2876. 36 -> aliasDereferencingProblem;
  2877. 48 -> inappropriateAuthentication;
  2878. 49 -> invalidCredentials;
  2879. 50 -> insufficientAccessRights;
  2880. 51 -> busy;
  2881. 52 -> unavailable;
  2882. 53 -> unwillingToPerform;
  2883. 54 -> loopDetect;
  2884. 64 -> namingViolation;
  2885. 65 -> objectClassViolation;
  2886. 66 -> notAllowedOnNonLeaf;
  2887. 67 -> notAllowedOnRDN;
  2888. 68 -> entryAlreadyExists;
  2889. 69 -> objectClassModsProhibited;
  2890. 71 -> affectsMultipleDSAs;
  2891. 80 -> other;
  2892. Default1 -> {asn1_enum,Default1}
  2893. end,
  2894.  
  2895. %%-------------------------------------------------
  2896. %% attribute matchedDN(2) with type OCTET STRING
  2897. %%-------------------------------------------------
  2898. [V2|Tlv3] = Tlv2,
  2899. Term2 = decode_octet_string(V2, [4]),
  2900.  
  2901. %%-------------------------------------------------
  2902. %% attribute diagnosticMessage(3) with type OCTET STRING
  2903. %%-------------------------------------------------
  2904. [V3|Tlv4] = Tlv3,
  2905. Term3 = decode_octet_string(V3, [4]),
  2906.  
  2907. %%-------------------------------------------------
  2908. %% attribute referral(4)   External Lightweight-Directory-Access-Protocol-V3:Referral OPTIONAL
  2909. %%-------------------------------------------------
  2910. {Term4,Tlv5} = case Tlv4 of
  2911. [{131075,V4}|TempTlv5] ->
  2912.     {'dec_Referral'(V4, []), TempTlv5};
  2913.     _ ->
  2914.         { asn1_NOVALUE, Tlv4}
  2915. end,
  2916.  
  2917. %%-------------------------------------------------
  2918. %% attribute responseName(5) with type OCTET STRING OPTIONAL
  2919. %%-------------------------------------------------
  2920. {Term5,Tlv6} = case Tlv5 of
  2921. [{131082,V5}|TempTlv6] ->
  2922.     {decode_octet_string(V5, []), TempTlv6};
  2923.     _ ->
  2924.         { asn1_NOVALUE, Tlv5}
  2925. end,
  2926.  
  2927. %%-------------------------------------------------
  2928. %% attribute responseValue(6) with type OCTET STRING OPTIONAL
  2929. %%-------------------------------------------------
  2930. {Term6,Tlv7} = case Tlv6 of
  2931. [{131083,V6}|TempTlv7] ->
  2932.     {decode_octet_string(V6, []), TempTlv7};
  2933.     _ ->
  2934.         { asn1_NOVALUE, Tlv6}
  2935. end,
  2936.  
  2937. case Tlv7 of [] -> true; _ -> true end, % ... extra fields skipped
  2938. Res1 = {'ExtendedResponse',Term1,Term2,Term3,Term4,Term5,Term6},
  2939. Res1.
  2940.  
  2941.  
  2942. %%================================
  2943. %%  IntermediateResponse
  2944. %%================================
  2945. enc_IntermediateResponse(Val) ->
  2946.     enc_IntermediateResponse(Val, [<<121>>]).
  2947.  
  2948. enc_IntermediateResponse(Val, TagIn) ->
  2949. {_,Cindex1,Cindex2} = Val,
  2950.  
  2951. %%-------------------------------------------------
  2952. %% attribute responseName(1) with type OCTET STRING OPTIONAL
  2953. %%-------------------------------------------------
  2954.    {EncBytes1,EncLen1} =  case Cindex1 of
  2955.          asn1_NOVALUE -> {<<>>,0};
  2956.          _ ->
  2957.             encode_restricted_string(Cindex1, [<<128>>])
  2958.        end,
  2959.  
  2960. %%-------------------------------------------------
  2961. %% attribute responseValue(2) with type OCTET STRING OPTIONAL
  2962. %%-------------------------------------------------
  2963.    {EncBytes2,EncLen2} =  case Cindex2 of
  2964.          asn1_NOVALUE -> {<<>>,0};
  2965.          _ ->
  2966.             encode_restricted_string(Cindex2, [<<129>>])
  2967.        end,
  2968.  
  2969.    BytesSoFar = [EncBytes1, EncBytes2],
  2970. LenSoFar = EncLen1 + EncLen2,
  2971. encode_tags(TagIn, BytesSoFar, LenSoFar).
  2972.  
  2973.  
  2974. dec_IntermediateResponse(Tlv) ->
  2975.    dec_IntermediateResponse(Tlv, [65561]).
  2976.  
  2977. dec_IntermediateResponse(Tlv, TagIn) ->
  2978.    %%-------------------------------------------------
  2979.    %% decode tag and length
  2980.    %%-------------------------------------------------
  2981. Tlv1 = match_tags(Tlv, TagIn),
  2982.  
  2983. %%-------------------------------------------------
  2984. %% attribute responseName(1) with type OCTET STRING OPTIONAL
  2985. %%-------------------------------------------------
  2986. {Term1,Tlv2} = case Tlv1 of
  2987. [{131072,V1}|TempTlv2] ->
  2988.     {decode_octet_string(V1, []), TempTlv2};
  2989.     _ ->
  2990.         { asn1_NOVALUE, Tlv1}
  2991. end,
  2992.  
  2993. %%-------------------------------------------------
  2994. %% attribute responseValue(2) with type OCTET STRING OPTIONAL
  2995. %%-------------------------------------------------
  2996. {Term2,Tlv3} = case Tlv2 of
  2997. [{131073,V2}|TempTlv3] ->
  2998.     {decode_octet_string(V2, []), TempTlv3};
  2999.     _ ->
  3000.         { asn1_NOVALUE, Tlv2}
  3001. end,
  3002.  
  3003. case Tlv3 of [] -> true; _ -> true end, % ... extra fields skipped
  3004. Res1 = {'IntermediateResponse',Term1,Term2},
  3005. Res1.
  3006. maxInt() ->
  3007. 2147483647.
  3008.  
  3009.  
  3010. %%%
  3011. %%% Run-time functions.
  3012. %%%
  3013.  
  3014. 'dialyzer-suppressions'(Arg) ->
  3015.     ok.
  3016.  
  3017. ber_decode_nif(B) ->
  3018.     asn1rt_nif:decode_ber_tlv(B).
  3019.  
  3020. ber_encode([Tlv]) ->
  3021.     ber_encode(Tlv);
  3022. ber_encode(Tlv) when is_binary(Tlv) ->
  3023.     Tlv;
  3024. ber_encode(Tlv) ->
  3025.     asn1rt_nif:encode_ber_tlv(Tlv).
  3026.  
  3027. collect_parts(TlvList) ->
  3028.     collect_parts(TlvList, []).
  3029.  
  3030. collect_parts([{_,L}|Rest], Acc) when is_list(L) ->
  3031.     collect_parts(Rest, [collect_parts(L)|Acc]);
  3032. collect_parts([{3,<<Unused,Bits/binary>>}|Rest], _Acc) ->
  3033.     collect_parts_bit(Rest, [Bits], Unused);
  3034. collect_parts([{_T,V}|Rest], Acc) ->
  3035.     collect_parts(Rest, [V|Acc]);
  3036. collect_parts([], Acc) ->
  3037.     list_to_binary(lists:reverse(Acc)).
  3038.  
  3039. collect_parts_bit([{3,<<Unused,Bits/binary>>}|Rest], Acc, Uacc) ->
  3040.     collect_parts_bit(Rest, [Bits|Acc], Unused + Uacc);
  3041. collect_parts_bit([], Acc, Uacc) ->
  3042.     list_to_binary([Uacc|lists:reverse(Acc)]).
  3043.  
  3044. decode_boolean(Tlv, TagIn) ->
  3045.     Val = match_tags(Tlv, TagIn),
  3046.     case Val of
  3047.         <<0:8>> ->
  3048.             false;
  3049.         <<_:8>> ->
  3050.             true;
  3051.         _ ->
  3052.             exit({error,{asn1,{decode_boolean,Val}}})
  3053.     end.
  3054.  
  3055. decode_integer(Tlv, TagIn) ->
  3056.     Bin = match_tags(Tlv, TagIn),
  3057.     Len = byte_size(Bin),
  3058.     <<Int:Len/signed-unit:8>> = Bin,
  3059.     Int.
  3060.  
  3061. decode_null(Tlv, Tags) ->
  3062.     Val = match_tags(Tlv, Tags),
  3063.     case Val of
  3064.         <<>> ->
  3065.             'NULL';
  3066.         _ ->
  3067.             exit({error,{asn1,{decode_null,Val}}})
  3068.     end.
  3069.  
  3070. decode_octet_string(Tlv, TagsIn) ->
  3071.     Bin = match_and_collect(Tlv, TagsIn),
  3072.     binary:copy(Bin).
  3073.  
  3074. encode_boolean(true, TagIn) ->
  3075.     encode_tags(TagIn, [255], 1);
  3076. encode_boolean(false, TagIn) ->
  3077.     encode_tags(TagIn, [0], 1);
  3078. encode_boolean(X, _) ->
  3079.     exit({error,{asn1,{encode_boolean,X}}}).
  3080.  
  3081. encode_integer(Val) ->
  3082.     Bytes =
  3083.         if
  3084.             Val >= 0 ->
  3085.                 encode_integer_pos(Val, []);
  3086.             true ->
  3087.                 encode_integer_neg(Val, [])
  3088.         end,
  3089.     {Bytes,length(Bytes)}.
  3090.  
  3091. encode_integer(Val, Tag) when is_integer(Val) ->
  3092.     encode_tags(Tag, encode_integer(Val));
  3093. encode_integer(Val, _Tag) ->
  3094.     exit({error,{asn1,{encode_integer,Val}}}).
  3095.  
  3096. encode_integer_neg(- 1, [B1|_T] = L) when B1 > 127 ->
  3097.     L;
  3098. encode_integer_neg(N, Acc) ->
  3099.     encode_integer_neg(N bsr 8, [N band 255|Acc]).
  3100.  
  3101. encode_integer_pos(0, [B|_Acc] = L) when B < 128 ->
  3102.     L;
  3103. encode_integer_pos(N, Acc) ->
  3104.     encode_integer_pos(N bsr 8, [N band 255|Acc]).
  3105.  
  3106. encode_length(L) when L =< 127 ->
  3107.     {[L],1};
  3108. encode_length(L) ->
  3109.     Oct = minimum_octets(L),
  3110.     Len = length(Oct),
  3111.     if
  3112.         Len =< 126 ->
  3113.             {[128 bor Len|Oct],Len + 1};
  3114.         true ->
  3115.             exit({error,{asn1,too_long_length_oct,Len}})
  3116.     end.
  3117.  
  3118. encode_null(_Val, TagIn) ->
  3119.     encode_tags(TagIn, [], 0).
  3120.  
  3121. encode_restricted_string(OctetList, TagIn) when is_binary(OctetList) ->
  3122.     encode_tags(TagIn, OctetList, byte_size(OctetList));
  3123. encode_restricted_string(OctetList, TagIn) when is_list(OctetList) ->
  3124.     encode_tags(TagIn, OctetList, length(OctetList)).
  3125.  
  3126. encode_tags(TagIn, {BytesSoFar,LenSoFar}) ->
  3127.     encode_tags(TagIn, BytesSoFar, LenSoFar).
  3128.  
  3129. encode_tags([Tag|Trest], BytesSoFar, LenSoFar) ->
  3130.     {Bytes2,L2} = encode_length(LenSoFar),
  3131.     encode_tags(Trest,
  3132.                 [Tag,Bytes2|BytesSoFar],
  3133.                 LenSoFar + byte_size(Tag) + L2);
  3134. encode_tags([], BytesSoFar, LenSoFar) ->
  3135.     {BytesSoFar,LenSoFar}.
  3136.  
  3137. match_and_collect(Tlv, TagsIn) ->
  3138.     Val = match_tags(Tlv, TagsIn),
  3139.     case Val of
  3140.         [_|_] = PartList ->
  3141.             collect_parts(PartList);
  3142.         Bin when is_binary(Bin) ->
  3143.             Bin
  3144.     end.
  3145.  
  3146. match_tags({T,V}, [T]) ->
  3147.     V;
  3148. match_tags({T,V}, [T|Tt]) ->
  3149.     match_tags(V, Tt);
  3150. match_tags([{T,V}], [T|Tt]) ->
  3151.     match_tags(V, Tt);
  3152. match_tags([{T,_V}|_] = Vlist, [T]) ->
  3153.     Vlist;
  3154. match_tags(Tlv, []) ->
  3155.     Tlv;
  3156. match_tags({Tag,_V} = Tlv, [T|_Tt]) ->
  3157.     exit({error,{asn1,{wrong_tag,{{expected,T},{got,Tag,Tlv}}}}}).
  3158.  
  3159. minimum_octets(0, Acc) ->
  3160.     Acc;
  3161. minimum_octets(Val, Acc) ->
  3162.     minimum_octets(Val bsr 8, [Val band 255|Acc]).
  3163.  
  3164. minimum_octets(Val) ->
  3165.     minimum_octets(Val, []).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement