2016-11-03 15:22:17 +00:00
|
|
|
/**
|
|
|
|
* an "Identity"
|
|
|
|
*/
|
2016-10-31 16:13:42 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-10-31 19:13:20 +00:00
|
|
|
#include <string.h>
|
2016-10-31 16:13:42 +00:00
|
|
|
|
|
|
|
#include "ipfs/repo/config/identity.h"
|
2016-11-03 15:22:17 +00:00
|
|
|
#include "libp2p/crypto/rsa.h"
|
2016-10-31 16:13:42 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* public methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***
|
2016-11-02 18:09:38 +00:00
|
|
|
* initializes a new Identity
|
2016-10-31 16:13:42 +00:00
|
|
|
* @param identity the identity to fill
|
|
|
|
* @param num_bits_for_keypair the number of bits for the keypair
|
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
|
|
|
int repo_config_identity_new(struct Identity* identity, unsigned long num_bits_for_keypair) {
|
|
|
|
if (num_bits_for_keypair < 1024)
|
|
|
|
return 0;
|
2016-10-31 22:19:27 +00:00
|
|
|
// generate the private key (& public)
|
2016-11-03 15:22:17 +00:00
|
|
|
if (!crypto_rsa_generate_keypair( &(identity->private_key), num_bits_for_keypair))
|
2016-10-31 16:13:42 +00:00
|
|
|
return 0;
|
2016-10-31 22:19:27 +00:00
|
|
|
|
|
|
|
// TODO: Get ID from public key
|
|
|
|
// TODO: Store peer id in identity struct
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
2016-10-31 16:13:42 +00:00
|
|
|
}
|