ericcornelissen / NervousFish

An app for your :iphone: to exchange public-keys in a secure manner.
GNU Lesser General Public License v3.0
2 stars 4 forks source link

App/generate key pair #47

Closed clenrock closed 7 years ago

clenrock commented 7 years ago

Relevant Issues: #28


NOTE; this pull request is now opened only for review. When the pull request #41 is merged in develop I will finish this. Also only check the class KeyPairGenerator, the other interfaces are of no use now.

What

This pull request adds a way to create a public/private Key Pairs.

Why

When people want to exchange keys, they need to have generated one first.

ericcornelissen commented 7 years ago

@jverbraeken @clenrock

Currently the keypair generator methods (1, 2, 3) all catch errors internally and return null if the key could not be generated. But I think this is not the way to go.

A better solution, in my opinion, would be to delegate these errors to the caller of these methods. This because the error is more informative then just a null value to the caller, and they have to handle the error anyway (also making it more intuitive to use the method). The only effect of this change (I think) would be that the following code (where a keypair is generated):

KeyGenerator keyGenerator = new KeyGenerator();
KeyPair keyPair = keyGenerator.generateRandomKeyPair();
if (keyPair == null) {
  // inform user about error
} else {
  // do useful stuff
}

Would change into:

KeyGenerator keyGenerator = new KeyGenerator();
try {
   KeyPair keyPair = keyGenerator.generateRandomKeyPair();
  // do usefull stuff
} catch (...) {
  // inform user about error
}

What are your thoughts on this? 😁

clenrock commented 7 years ago

@ericcornelissen I think I prefer your suggestion, but it doesn't matter a lot ;). If @jverbraeken also thinks your suggestion is better I'll change it.