[noise] rev32b (Release Candidate)
Jason A. Donenfeld
Jason at zx2c4.com
Sun May 14 10:36:27 PDT 2017
Hey,
On Sun, May 14, 2017 at 5:44 AM, Guanhao Yin <sopium at mysterious.site> wrote:
> I am more inclined to have read_message/write_message returning an
> error indicating that a PSK is needed. Something like
>
> let r = handshake_state.write_message(payload, output);
> if r == Err(NeedPsk) {
> let psk = lookup_psk(handshake_state.get_rs());
> handshake_state.set_next_psk(psk);
> handshake_state.write_message(payload, output);
> }
That's a really cool way of dealing with it. You could actually have
this work generically for all needed key types:
First there's the usual standard set of `setters`:
handshake_state.set_psk(psk)
handshake_state.set_local_static(private)
handshake_state.set_remote_static(public)
handshake_state.set_something_else(blah)
Then, if it turns out a particular handshake needs any of these,
r = handshake_state.write_message(payload, output)
if r.has_error {
if r.error & NeedPsk {
handshake_state.set_psk(psk)
}
if r.error & NeedLocalStatic {
handshake_state.set_local_static(private)
}
if r.error & NeedRemoteStatic {
handshake_state.set_remote_static(public)
}
if r.error & NeedSomethingElse {
handshake_state.set_something_else(blah)
}
handshake_state.write_message(payload, output)
}
With this kind of setup, users of the API who a priori know all the
different things will just call the various setters first. Users who
only know a few will set the ones they know, and then check for the
NeedX error, and then query and set appropriately, as you've described
above. This seems to me like a pretty good pattern.
Jason
More information about the Noise
mailing list