add functions to get the error codes rather than error strings
This commit is contained in:
parent
60be1ca55f
commit
7263c4221b
11 changed files with 140 additions and 14 deletions
|
@ -92,6 +92,7 @@ install(FILES
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/inbound_group_session.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/inbound_group_session.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/pk.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/pk.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/sas.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/sas.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include/olm/error.h
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/olm)
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/olm)
|
||||||
|
|
||||||
if (UNIX AND NOT APPLE)
|
if (UNIX AND NOT APPLE)
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "olm/error.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,6 +45,13 @@ const char *olm_inbound_group_session_last_error(
|
||||||
const OlmInboundGroupSession *session
|
const OlmInboundGroupSession *session
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error code describing the most recent error to happen to a group
|
||||||
|
* session */
|
||||||
|
enum OlmErrorCode olm_inbound_group_session_last_error_code(
|
||||||
|
const OlmInboundGroupSession *session
|
||||||
|
);
|
||||||
|
|
||||||
/** Clears the memory used to back this group session */
|
/** Clears the memory used to back this group session */
|
||||||
size_t olm_clear_inbound_group_session(
|
size_t olm_clear_inbound_group_session(
|
||||||
OlmInboundGroupSession *session
|
OlmInboundGroupSession *session
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "olm/error.h"
|
||||||
#include "olm/inbound_group_session.h"
|
#include "olm/inbound_group_session.h"
|
||||||
#include "olm/outbound_group_session.h"
|
#include "olm/outbound_group_session.h"
|
||||||
|
|
||||||
|
@ -71,19 +72,34 @@ size_t olm_error(void);
|
||||||
/** A null terminated string describing the most recent error to happen to an
|
/** A null terminated string describing the most recent error to happen to an
|
||||||
* account */
|
* account */
|
||||||
const char * olm_account_last_error(
|
const char * olm_account_last_error(
|
||||||
OlmAccount * account
|
const OlmAccount * account
|
||||||
|
);
|
||||||
|
|
||||||
|
/** An error code describing the most recent error to happen to an account */
|
||||||
|
enum OlmErrorCode olm_account_last_error_code(
|
||||||
|
const OlmAccount * account
|
||||||
);
|
);
|
||||||
|
|
||||||
/** A null terminated string describing the most recent error to happen to a
|
/** A null terminated string describing the most recent error to happen to a
|
||||||
* session */
|
* session */
|
||||||
const char * olm_session_last_error(
|
const char * olm_session_last_error(
|
||||||
OlmSession * session
|
const OlmSession * session
|
||||||
|
);
|
||||||
|
|
||||||
|
/** An error code describing the most recent error to happen to a session */
|
||||||
|
enum OlmErrorCode olm_session_last_error_code(
|
||||||
|
const OlmSession * session
|
||||||
);
|
);
|
||||||
|
|
||||||
/** A null terminated string describing the most recent error to happen to a
|
/** A null terminated string describing the most recent error to happen to a
|
||||||
* utility */
|
* utility */
|
||||||
const char * olm_utility_last_error(
|
const char * olm_utility_last_error(
|
||||||
OlmUtility * utility
|
const OlmUtility * utility
|
||||||
|
);
|
||||||
|
|
||||||
|
/** An error code describing the most recent error to happen to a utility */
|
||||||
|
enum OlmErrorCode olm_utility_last_error_code(
|
||||||
|
const OlmUtility * utility
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Clears the memory used to back this account */
|
/** Clears the memory used to back this account */
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "olm/error.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,6 +45,13 @@ const char *olm_outbound_group_session_last_error(
|
||||||
const OlmOutboundGroupSession *session
|
const OlmOutboundGroupSession *session
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error code describing the most recent error to happen to a group
|
||||||
|
* session */
|
||||||
|
enum OlmErrorCode olm_outbound_group_session_last_error_code(
|
||||||
|
const OlmOutboundGroupSession *session
|
||||||
|
);
|
||||||
|
|
||||||
/** Clears the memory used to back this group session */
|
/** Clears the memory used to back this group session */
|
||||||
size_t olm_clear_outbound_group_session(
|
size_t olm_clear_outbound_group_session(
|
||||||
OlmOutboundGroupSession *session
|
OlmOutboundGroupSession *session
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "olm/error.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,7 +39,13 @@ OlmPkEncryption *olm_pk_encryption(
|
||||||
/** A null terminated string describing the most recent error to happen to an
|
/** A null terminated string describing the most recent error to happen to an
|
||||||
* encryption object */
|
* encryption object */
|
||||||
const char * olm_pk_encryption_last_error(
|
const char * olm_pk_encryption_last_error(
|
||||||
OlmPkEncryption * encryption
|
const OlmPkEncryption * encryption
|
||||||
|
);
|
||||||
|
|
||||||
|
/** An error code describing the most recent error to happen to an encryption
|
||||||
|
* object */
|
||||||
|
enum OlmErrorCode olm_pk_encryption_last_error_code(
|
||||||
|
const OlmPkEncryption * encryption
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Clears the memory used to back this encryption object */
|
/** Clears the memory used to back this encryption object */
|
||||||
|
@ -104,7 +112,13 @@ OlmPkDecryption *olm_pk_decryption(
|
||||||
/** A null terminated string describing the most recent error to happen to a
|
/** A null terminated string describing the most recent error to happen to a
|
||||||
* decription object */
|
* decription object */
|
||||||
const char * olm_pk_decryption_last_error(
|
const char * olm_pk_decryption_last_error(
|
||||||
OlmPkDecryption * decryption
|
const OlmPkDecryption * decryption
|
||||||
|
);
|
||||||
|
|
||||||
|
/** An error code describing the most recent error to happen to a decription
|
||||||
|
* object */
|
||||||
|
enum OlmErrorCode olm_pk_decryption_last_error_code(
|
||||||
|
const OlmPkDecryption * decryption
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Clears the memory used to back this decryption object */
|
/** Clears the memory used to back this decryption object */
|
||||||
|
@ -221,7 +235,13 @@ OlmPkSigning *olm_pk_signing(
|
||||||
/** A null terminated string describing the most recent error to happen to a
|
/** A null terminated string describing the most recent error to happen to a
|
||||||
* signing object */
|
* signing object */
|
||||||
const char * olm_pk_signing_last_error(
|
const char * olm_pk_signing_last_error(
|
||||||
OlmPkSigning * sign
|
const OlmPkSigning * sign
|
||||||
|
);
|
||||||
|
|
||||||
|
/** A null terminated string describing the most recent error to happen to a
|
||||||
|
* signing object */
|
||||||
|
enum OlmErrorCode olm_pk_signing_last_error_code(
|
||||||
|
const OlmPkSigning * sign
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Clears the memory used to back this signing object */
|
/** Clears the memory used to back this signing object */
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "olm/error.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -34,7 +36,13 @@ typedef struct OlmSAS OlmSAS;
|
||||||
/** A null terminated string describing the most recent error to happen to an
|
/** A null terminated string describing the most recent error to happen to an
|
||||||
* SAS object. */
|
* SAS object. */
|
||||||
const char * olm_sas_last_error(
|
const char * olm_sas_last_error(
|
||||||
OlmSAS * sas
|
const OlmSAS * sas
|
||||||
|
);
|
||||||
|
|
||||||
|
/** An error code describing the most recent error to happen to an SAS
|
||||||
|
* object. */
|
||||||
|
enum OlmErrorCode olm_sas_last_error_code(
|
||||||
|
const OlmSAS * sas
|
||||||
);
|
);
|
||||||
|
|
||||||
/** The size of an SAS object in bytes. */
|
/** The size of an SAS object in bytes. */
|
||||||
|
|
|
@ -76,6 +76,12 @@ const char *olm_inbound_group_session_last_error(
|
||||||
return _olm_error_to_string(session->last_error);
|
return _olm_error_to_string(session->last_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum OlmErrorCode olm_inbound_group_session_last_error_code(
|
||||||
|
const OlmInboundGroupSession *session
|
||||||
|
) {
|
||||||
|
return session->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
size_t olm_clear_inbound_group_session(
|
size_t olm_clear_inbound_group_session(
|
||||||
OlmInboundGroupSession *session
|
OlmInboundGroupSession *session
|
||||||
) {
|
) {
|
||||||
|
|
35
src/olm.cpp
35
src/olm.cpp
|
@ -42,14 +42,26 @@ static olm::Account * from_c(OlmAccount * account) {
|
||||||
return reinterpret_cast<olm::Account *>(account);
|
return reinterpret_cast<olm::Account *>(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const olm::Account * from_c(const OlmAccount * account) {
|
||||||
|
return reinterpret_cast<const olm::Account *>(account);
|
||||||
|
}
|
||||||
|
|
||||||
static olm::Session * from_c(OlmSession * session) {
|
static olm::Session * from_c(OlmSession * session) {
|
||||||
return reinterpret_cast<olm::Session *>(session);
|
return reinterpret_cast<olm::Session *>(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const olm::Session * from_c(const OlmSession * session) {
|
||||||
|
return reinterpret_cast<const olm::Session *>(session);
|
||||||
|
}
|
||||||
|
|
||||||
static olm::Utility * from_c(OlmUtility * utility) {
|
static olm::Utility * from_c(OlmUtility * utility) {
|
||||||
return reinterpret_cast<olm::Utility *>(utility);
|
return reinterpret_cast<olm::Utility *>(utility);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const olm::Utility * from_c(const OlmUtility * utility) {
|
||||||
|
return reinterpret_cast<const olm::Utility *>(utility);
|
||||||
|
}
|
||||||
|
|
||||||
static std::uint8_t * from_c(void * bytes) {
|
static std::uint8_t * from_c(void * bytes) {
|
||||||
return reinterpret_cast<std::uint8_t *>(bytes);
|
return reinterpret_cast<std::uint8_t *>(bytes);
|
||||||
}
|
}
|
||||||
|
@ -110,27 +122,44 @@ size_t olm_error(void) {
|
||||||
|
|
||||||
|
|
||||||
const char * olm_account_last_error(
|
const char * olm_account_last_error(
|
||||||
OlmAccount * account
|
const OlmAccount * account
|
||||||
) {
|
) {
|
||||||
auto error = from_c(account)->last_error;
|
auto error = from_c(account)->last_error;
|
||||||
return _olm_error_to_string(error);
|
return _olm_error_to_string(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum OlmErrorCode olm_account_last_error_code(
|
||||||
|
const OlmAccount * account
|
||||||
|
) {
|
||||||
|
return from_c(account)->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
const char * olm_session_last_error(
|
const char * olm_session_last_error(
|
||||||
OlmSession * session
|
const OlmSession * session
|
||||||
) {
|
) {
|
||||||
auto error = from_c(session)->last_error;
|
auto error = from_c(session)->last_error;
|
||||||
return _olm_error_to_string(error);
|
return _olm_error_to_string(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum OlmErrorCode olm_session_last_error_code(
|
||||||
|
const OlmSession * session
|
||||||
|
) {
|
||||||
|
return from_c(session)->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
const char * olm_utility_last_error(
|
const char * olm_utility_last_error(
|
||||||
OlmUtility * utility
|
const OlmUtility * utility
|
||||||
) {
|
) {
|
||||||
auto error = from_c(utility)->last_error;
|
auto error = from_c(utility)->last_error;
|
||||||
return _olm_error_to_string(error);
|
return _olm_error_to_string(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum OlmErrorCode olm_utility_last_error_code(
|
||||||
|
const OlmUtility * utility
|
||||||
|
) {
|
||||||
|
return from_c(utility)->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
size_t olm_account_size(void) {
|
size_t olm_account_size(void) {
|
||||||
return sizeof(olm::Account);
|
return sizeof(olm::Account);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,12 @@ const char *olm_outbound_group_session_last_error(
|
||||||
return _olm_error_to_string(session->last_error);
|
return _olm_error_to_string(session->last_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum OlmErrorCode olm_outbound_group_session_last_error_code(
|
||||||
|
const OlmOutboundGroupSession *session
|
||||||
|
) {
|
||||||
|
return session->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
size_t olm_clear_outbound_group_session(
|
size_t olm_clear_outbound_group_session(
|
||||||
OlmOutboundGroupSession *session
|
OlmOutboundGroupSession *session
|
||||||
) {
|
) {
|
||||||
|
|
22
src/pk.cpp
22
src/pk.cpp
|
@ -37,12 +37,18 @@ struct OlmPkEncryption {
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * olm_pk_encryption_last_error(
|
const char * olm_pk_encryption_last_error(
|
||||||
OlmPkEncryption * encryption
|
const OlmPkEncryption * encryption
|
||||||
) {
|
) {
|
||||||
auto error = encryption->last_error;
|
auto error = encryption->last_error;
|
||||||
return _olm_error_to_string(error);
|
return _olm_error_to_string(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OlmErrorCode olm_pk_encryption_last_error_code(
|
||||||
|
const OlmPkEncryption * encryption
|
||||||
|
) {
|
||||||
|
return encryption->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
size_t olm_pk_encryption_size(void) {
|
size_t olm_pk_encryption_size(void) {
|
||||||
return sizeof(OlmPkEncryption);
|
return sizeof(OlmPkEncryption);
|
||||||
}
|
}
|
||||||
|
@ -162,12 +168,18 @@ struct OlmPkDecryption {
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * olm_pk_decryption_last_error(
|
const char * olm_pk_decryption_last_error(
|
||||||
OlmPkDecryption * decryption
|
const OlmPkDecryption * decryption
|
||||||
) {
|
) {
|
||||||
auto error = decryption->last_error;
|
auto error = decryption->last_error;
|
||||||
return _olm_error_to_string(error);
|
return _olm_error_to_string(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OlmErrorCode olm_pk_decryption_last_error_code(
|
||||||
|
const OlmPkDecryption * decryption
|
||||||
|
) {
|
||||||
|
return decryption->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
size_t olm_pk_decryption_size(void) {
|
size_t olm_pk_decryption_size(void) {
|
||||||
return sizeof(OlmPkDecryption);
|
return sizeof(OlmPkDecryption);
|
||||||
}
|
}
|
||||||
|
@ -446,11 +458,15 @@ OlmPkSigning *olm_pk_signing(void * memory) {
|
||||||
return new(memory) OlmPkSigning;
|
return new(memory) OlmPkSigning;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * olm_pk_signing_last_error(OlmPkSigning * sign) {
|
const char * olm_pk_signing_last_error(const OlmPkSigning * sign) {
|
||||||
auto error = sign->last_error;
|
auto error = sign->last_error;
|
||||||
return _olm_error_to_string(error);
|
return _olm_error_to_string(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OlmErrorCode olm_pk_signing_last_error_code(const OlmPkSigning * sign) {
|
||||||
|
return sign->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
size_t olm_clear_pk_signing(OlmPkSigning *sign) {
|
size_t olm_clear_pk_signing(OlmPkSigning *sign) {
|
||||||
/* Clear the memory backing the signing */
|
/* Clear the memory backing the signing */
|
||||||
olm::unset(sign, sizeof(OlmPkSigning));
|
olm::unset(sign, sizeof(OlmPkSigning));
|
||||||
|
|
|
@ -27,11 +27,17 @@ struct OlmSAS {
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * olm_sas_last_error(
|
const char * olm_sas_last_error(
|
||||||
OlmSAS * sas
|
const OlmSAS * sas
|
||||||
) {
|
) {
|
||||||
return _olm_error_to_string(sas->last_error);
|
return _olm_error_to_string(sas->last_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum OlmErrorCode olm_sas_last_error_code(
|
||||||
|
const OlmSAS * sas
|
||||||
|
) {
|
||||||
|
return sas->last_error;
|
||||||
|
}
|
||||||
|
|
||||||
size_t olm_sas_size(void) {
|
size_t olm_sas_size(void) {
|
||||||
return sizeof(OlmSAS);
|
return sizeof(OlmSAS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue