Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140846
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/cacophony/message.ex b/lib/cacophony/message.ex
index 55222a2..8092103 100644
--- a/lib/cacophony/message.ex
+++ b/lib/cacophony/message.ex
@@ -1,84 +1,94 @@
defmodule Cacophony.Message do
+ @moduledoc """
+ Encoding and decoding of ASN.1 LDAP messages to high-level types.
+ """
+
require Logger
defmodule BindRequest do
+ @moduledoc "A type representing a BindRequest."
+
defstruct [:id, :version, :cn, :credentials]
end
defmodule BindResponse do
+ @moduledoc "A type representing a BindResponse."
+
defstruct [
:id,
:result_code,
:matched_cn,
{:diagnostic_message, ""},
{:referral, :asn1_NOVALUE},
{:server_sasl_creds, :asn1_NOVALUE}
]
end
defmodule UnbindRequest do
+ @moduledoc "A type representing an UnbindRequest."
+
defstruct [:id]
end
def interpret(:bindRequest, {:BindRequest, vsn, cn, creds}, message_id),
do: {:ok, %BindRequest{id: message_id, version: vsn, cn: cn, credentials: creds}}
def interpret(
:bindResponse,
{:BindResponse, result, matched_cn, diag_msg, referral, sasl_creds},
message_id
),
do:
{:ok,
%BindResponse{
id: message_id,
result_code: result,
matched_cn: matched_cn,
diagnostic_message: diag_msg,
referral: referral,
server_sasl_creds: sasl_creds
}}
def interpret(:unbindRequest, _, message_id), do: {:ok, %UnbindRequest{id: message_id}}
def decode({:LDAPMessage, message_id, {type, payload}, _}),
do: interpret(type, payload, message_id)
def decode({:LDAPMessage, message_id, {type, payload}}),
do: interpret(type, payload, message_id)
def decode(message) when is_binary(message) do
with {:ok, data} <- :LDAP.decode(:LDAPMessage, message),
{:ok, struct} <- decode(data) do
{:ok, struct}
else
e -> {:error, e}
end
end
def decode(_), do: {:error, :badmatch}
def encode({:asn1, message}),
do: :LDAP.encode(:LDAPMessage, message)
def encode({:envelope, message_id, payload}),
do: encode({:asn1, {:LDAPMessage, message_id, payload, :asn1_NOVALUE}})
def encode(%BindRequest{} = msg) do
payload = {:BindRequest, msg.version, msg.cn, msg.credentials}
encode({:envelope, msg.id, {:bindRequest, payload}})
end
def encode(%BindResponse{} = msg) do
payload =
{:BindResponse, msg.result_code, msg.matched_cn, msg.diagnostic_message, msg.referral,
msg.server_sasl_creds}
encode({:envelope, msg.id, {:bindResponse, payload}})
end
def encode(%UnbindRequest{} = msg),
do: encode({:envelope, msg.id, {:unbindRequest, :asn1_NOVALUE}})
def encode(_), do: {:error, :badmatch}
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Jan 22, 1:03 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55774
Default Alt Text
(2 KB)
Attached To
Mode
R11 cacophony
Attached
Detach File
Event Timeline
Log In to Comment