anode-make-identity.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* libanode: the Anode C reference implementation
  2. * Copyright (C) 2009 Adam Ierymenko <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <arpa/inet.h>
  20. #include "../anode.h"
  21. #include "../impl/misc.h"
  22. #include "../impl/types.h"
  23. int main(int argc,char **argv)
  24. {
  25. char str[1024];
  26. AnodeZone zone;
  27. AnodeIdentity identity;
  28. if (argc < 2) {
  29. printf("Usage: anode-make-identity <32-bit zone ID hex>\n");
  30. return 0;
  31. }
  32. *((uint32_t *)zone.bits) = htonl((uint32_t)strtoul(argv[1],(char **)0,16));
  33. if (AnodeIdentity_generate(&identity,&zone,ANODE_ADDRESS_ANODE_256_40)) {
  34. fprintf(stderr,"Error: identity key pair generation failed (check build settings).\n");
  35. return 1;
  36. }
  37. if (AnodeIdentity_to_string(&identity,str,sizeof(str)) <= 0) {
  38. fprintf(stderr,"Error: internal error converting identity to string.\n");
  39. return -1;
  40. }
  41. printf("%s\n",str);
  42. return 0;
  43. }