@@ -208,59 +208,14 @@ defmodule Radius.Packet do
208208 """
209209 @ deprecated "Use encode_request/1-2 or encode_reply/1-2 instead"
210210 def encode ( packet , options \\ [ ] ) do
211- sign? = options |> Keyword . get ( :sign , false )
212- raw? = options |> Keyword . get ( :raw , false )
213-
214- { auth , reply? } =
215- if packet . auth == nil do
216- { :crypto . strong_rand_bytes ( 16 ) , false }
217- else
218- { packet . auth , true }
219- end
220-
221- packet = % { packet | auth: auth }
222-
223211 packet =
224- if sign? do
225- attrs = packet . attrs ++ [ { "Message-Authenticator" , << 0 :: size ( 128 ) >> } ]
226-
227- % { packet | attrs: attrs }
228- else
229- packet
230- end
231-
232- attrs = encode_attrs ( packet )
233-
234- code = encode_code ( packet . code )
235- length = 20 + :erlang . iolist_size ( attrs )
236- header = << code , packet . id , length :: size ( 16 ) , auth :: binary >>
237-
238- attrs =
239- if sign? do
240- signature = :crypto . mac ( :hmac , :md5 , packet . secret , [ header , attrs ] )
241- [ last | attrs ] = attrs |> Enum . reverse ( )
242- crop_len = byte_size ( last ) - 16
243- last = << last :: bytes - size ( crop_len ) , signature :: binary >>
244- [ last | attrs ] |> Enum . reverse ( )
245- else
246- attrs
247- end
248-
249- header =
250- if reply? and raw? == false do
251- resp_auth =
252- :crypto . hash_init ( :md5 )
253- |> :crypto . hash_update ( header )
254- |> :crypto . hash_update ( attrs )
255- |> :crypto . hash_update ( packet . secret )
256- |> :crypto . hash_final ( )
257-
258- << header :: bytes - size ( 4 ) , resp_auth :: binary >>
212+ if packet . auth == nil do
213+ encode_request ( packet , options )
259214 else
260- header
215+ encode_reply ( packet , packet . auth , options )
261216 end
262217
263- [ header , attrs ]
218+ packet . raw
264219 end
265220
266221 @ doc """
0 commit comments