add function to forget the old fallback key

This commit is contained in:
Hubert Chathi 2021-11-19 21:43:27 -05:00
parent c5eff859cb
commit 29e0287ef3
5 changed files with 28 additions and 2 deletions

View file

@ -169,6 +169,9 @@ struct Account {
std::uint8_t * fallback_json, std::size_t fallback_json_length std::uint8_t * fallback_json, std::size_t fallback_json_length
); );
/** Forget about the old fallback key */
void forget_old_fallback_key();
/** Lookup a one time key with the given public key */ /** Lookup a one time key with the given public key */
OneTimeKey const * lookup_key( OneTimeKey const * lookup_key(
_olm_curve25519_public_key const & public_key _olm_curve25519_public_key const & public_key

View file

@ -310,6 +310,15 @@ OLM_EXPORT size_t olm_account_unpublished_fallback_key(
void * fallback_key, size_t fallback_key_size void * fallback_key, size_t fallback_key_size
); );
/** Forget about the old fallback key. This should be called once you are
* reasonably certain that you will not receive any more messages that use
* the old fallback key (e.g. 5 minutes after the new fallback key has been
* published).
*/
OLM_EXPORT void olm_account_forget_old_fallback_key(
OlmAccount * account
);
/** The number of random bytes needed to create an outbound session */ /** The number of random bytes needed to create an outbound session */
OLM_EXPORT size_t olm_create_outbound_session_random_length( OLM_EXPORT size_t olm_create_outbound_session_random_length(

View file

@ -194,8 +194,8 @@ Account.prototype['unpublished_fallback_key'] = restore_stack(function() {
return UTF8ToString(keys, keys_length); return UTF8ToString(keys, keys_length);
}); });
Account.prototype['forget_previous_fallback'] = restore_stack(function() { Account.prototype['forget_old_fallback'] = restore_stack(function() {
account_method(Module['_olm_account_forget_previous_fallback_key'])( account_method(Module['_olm_account_forget_old_fallback_key'])(
this.ptr this.ptr
); );
}); });

View file

@ -398,6 +398,13 @@ std::size_t olm::Account::get_unpublished_fallback_key_json(
return pos - fallback_json; return pos - fallback_json;
} }
void olm::Account::forget_old_fallback_key(
) {
if (num_fallback_keys >= 2) {
num_fallback_keys = 1;
}
}
namespace olm { namespace olm {
static std::size_t pickle_length( static std::size_t pickle_length(

View file

@ -512,6 +512,13 @@ size_t olm_account_unpublished_fallback_key(
} }
void olm_account_forget_old_fallback_key(
OlmAccount * account
) {
return from_c(account)->forget_old_fallback_key();
}
size_t olm_create_outbound_session_random_length( size_t olm_create_outbound_session_random_length(
OlmSession const * session OlmSession const * session
) { ) {