We should reject duplicated messages immediately without trying
to decrypt them with every state.
Reorder some prekey handling functions to match the Java
The Java code uses a class here which contains referencs to the various
stores. However this is less than convenient in the case of FFI.
In particular encryption only requires access to a couple of the stores.
A lot of these functions are afaict just defined on the interface,
implemented in Signal-Android, and then never used anywhere at all. A
few are used within the Signal-Android client, but not in
libsignal-protocol-{java,rust}. Remove anything that we ourselves do
not need implemented, because every additional function on these
traits adds a few dozen lines in the JNI interop layer.
This doesn't negatively affect Signal-Android since we will retain the
various functions on the Java interface specs. They'll simply never be
invoked, which is mostly the status quo anyway with
libsignal-protocol-java.
Avoids an unnecessary clone when getting the device ID since otherwise
we call sender() which clones the ProtocolAddress but then we extract
the u32 and throw away the string.
Rename SenderKeyRecord::empty to is_empty to match Java.
The Java storage interface wants to return a newly allocated
SenderKeyRecord if it is new. This seems weird to me vs just returning
null but in any case detect a fresh record.
We continue to expect an Option<> and create a new fresh record if
None is returned as other bindings may find it more convenient to just
return None/null/whatever.
Also limit sender key IDs to 31-bits for Java
This allows bindings (ex JNI) to pass errors received from a callback
back through libsignal-protocol-rust so they can be returned by the
operation which had invoked the callback.
We could instead do something fancy with Any here instead, so that a
callback into Java which throws an exception ends with exception being
captured, flowing through libsignal-protocol-rust and then rethrown
when we return to Java. But it's not clear if that's so necessary
vs the much simpler option of capturing the exception text.
Rename KeyPair::new to KeyPair::generate and add a KeyPair::new which
just takes the respective public and private key.
Add deserialize functions for PreKey and SignedPreKey objects
The Java equivalent of remove_previous_session_states is also dead - not called
within either the lib itself nor by Signal-Android.
The previous_counter field in SignalMessage seems to be dead and I don't
understand its purpose. It is similar dead in the Java code (read, but not used
anywhere within the class and not exposed via a getter).
Unrelated, export HKDF as Signal-Android uses HKDF via libsignal
Now dead code is also prohibited. modulo the previous_counter field.