Module Olm.Session
module Message : sig ... end
type t
=
{
buf : char Ctypes.ptr;
ses : C.Types.Session.t Ctypes_static.ptr;
}
val clear : C.Types.Session.t Ctypes_static.ptr -> (int, [> `OlmError ]) Core.result
clear ses
Clear memory backing the given
ses
pointer.
val check_error : t -> Unsigned.size_t -> (int, [> OlmError.t ]) Core.result
check_error t ret
Check whether return code
ret
is equal to `olm_error()` ( -1 ), returning the return value as an int if not, and the `last_error` from the sessiont
if so.
val alloc : unit -> t
alloc ()
Allocate an
C.Types.Session.t
and return the pointers in at
.
val create_inbound : ?identity_key:string -> Account.t -> Message.t -> (t, [> OlmError.t | `ValueError of string ]) Core.result
create_inbound ?identity_key acc msg
Create a new in-bound session with the account
acc
for sending/receiving messages from an incoming prekeymsg
. If an?identity_key
is supplied, it will be used to check whether themsg
was actually sent using it. If the base64 key cannot be decoded, the error will will be`InvalidBase64
.`BadMessageVersion
results if themsg
was for an unsupported protocol. If themsg
could not be decoded,`BadMessageFormat
will result. If the message refers to an unknown one-time key, then the error will be`BadMessageKeyId
.
val create_outbound : Account.t -> string -> string -> (t, [> OlmError.t | `ValueError of string ]) Core.result
create_outbound acc identity_key one_time_key
Creates a new outbound session with the account
acc
for sending messages to a givenidentity_key
andone_time_key
. If the keys couldn't be decoded as base64 then the error message will be "INVALID_BASE64".
val pickle : ?pass:string -> t -> (string, [> OlmError.t ]) Core.result
pickle ?pass t
Stores an session object
t
as a base64 string. Encrypting it using the optionally supplied passphrase?pass
. Returns a base64 encoded string of the pickled session on success.
val from_pickle : ?pass:string -> string -> (t, [> OlmError.t | `ValueError of string ]) Core.result
from_pickle ?pass pickle
Loads an session from a pickled base64-encoded string
pickle
and returns at
, decrypted with the optionally supplied passphrase?pass
. If the passphrase doesn't match the one used to encrypt the session then the error will be`BadAccountKey
. If the base64 couldn't be decoded then the error will be`InvalidBase64
.
val encrypt : t -> string -> (Message.t, [> OlmError.t | `ValueError of string ]) Core.result
encrypt t plaintext
Encrypts a
plaintext
message using the sessiont
. Returns the ciphertext as a base64 encoded string on success.
val decrypt : ?ignore_unicode_errors:bool -> t -> Message.t -> (string, [> OlmError.t | `ValueError of string | `UnicodeError ]) Core.result
decrypt t msg
Decrypts a
msg
using the sessiont
. Invalid unicode characters are replaced withUutf.u_rep
unlessignore_unicode_errors
is set to true. If the base64 cannot be decoded, the error will be`InvalidBase64
.`BadMessageVersion
results if the message was for an unsupported protocol. If themsg
could not be decoded,`BadMessageFormat
will result. If the MAC on the message was invalid then the error message will be "BAD_MESSAGE_MAC".
val id : t -> (string, [> OlmError.t ]) Core.result
id t
Get the identifier for the session
t
. It will be the same for both ends of the conversation.
val matches : ?identity_key:string -> t -> Message.t -> (bool, [> OlmError.t | `ValueError of string ]) Core.result
matches ?identity_key t msg
Checks if the PreKey
msg
(`ValueError if not PreKey) is for the in-bound sessiont
. This can happen if multiple messages are sent tot
before it sends a message in reply. Returns true if the session matches, false if not. Ifidentity_key
is provided, themsg
will be checked against it to ensure it came from the expected sender.
val remove_one_time_keys : t -> Account.t -> (int, [> OlmError.t ]) Core.result
remove_one_time_keys t acc
Removes the one-time keys that the session
t
used from the accountacc
. If the account doesn't have any matching one-time keys then the error will be`BadMessageKeyId
.