Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(identity): mark sign as infaillible #5728

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

drHuangMHT
Copy link
Contributor

Description

A minimal working example of making Keypair::sign infaillible.
Refer to #4650 for more detail.

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Copy link
Member

@dariusc93 dariusc93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Did leave some comments.

@@ -176,12 +178,12 @@ impl Keypair {
/// Sign a message using the private key of this keypair, producing
/// a signature that can be verified using the corresponding public key.
#[allow(unused_variables)]
pub fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError> {
pub fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, Infallible> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are returning Ok throughout the inner functions, should we go on and remove the Result here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. But what about upstream? there are a couple of functions that return a Result only because sign does so. Should we address them here? The biggest change will be noise security upgrade become infallible but the trait bound in swarm builder expect an associated Error type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change it so it is no longer expecting an associated error type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not against making the change here. Thoughts on that @jxs ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think if it's api that doesn't make sense we should address it and take the next release cycle to release a new libp2p-identity release wdyt?

@@ -90,7 +90,7 @@ impl Keypair {
self,
id_keys: &identity::Keypair,
) -> Result<AuthenticKeypair, Error> {
let sig = id_keys.sign(&[STATIC_KEY_DOMAIN.as_bytes(), self.public.as_ref()].concat())?;
let sig = id_keys.sign(&[STATIC_KEY_DOMAIN.as_bytes(), self.public.as_ref()].concat()).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto; we should use expect here to provide context if it ever does fails and panics. Unlikely though but its more of a just-in-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants