/** * Read existing private key from file or create a new one if it does not exist * yet. * Returns the private key on success, NULL on error. */ static struct GNUNET_CRYPTO_RsaPrivateKey * init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *nick_name) { char *home; char *keyfile; struct GNUNET_CRYPTO_RsaPrivateKey *privKey; #if DEBUG_CHAT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing private key\n"); #endif if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "chat", "HOME", &home)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Configuration option `%s' in section `%s' missing\n"), "HOME", "chat"); return NULL; } GNUNET_DISK_directory_create (home); if (GNUNET_OK != GNUNET_DISK_directory_test (home)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to access chat home directory `%s'\n"), home); GNUNET_free (home); return NULL; } /* read or create private key */ keyfile = GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) + strlen (nick_name) + 2); strcpy (keyfile, home); GNUNET_free (home); if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR) strcat (keyfile, DIR_SEPARATOR_STR); strcat (keyfile, NICK_IDENTITY_PREFIX); strcat (keyfile, nick_name); privKey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); if (NULL == privKey) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to create/open key in file `%s'\n"), keyfile); } GNUNET_free (keyfile); return privKey; }
static int testDirMani () { if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing")) return 1; if (GNUNET_NO != GNUNET_DISK_file_test ("test")) return 1; if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing")) return 1; if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) return 1; if (GNUNET_OK != GNUNET_DISK_directory_create ("test")) return 1; if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES)) return 1; if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) return 1; return 0; }