Key.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Key_H
  16. #define Key_H
  17. #include "benc/String.h"
  18. #include "memory/Allocator.h"
  19. #include <stdint.h>
  20. char* Key_parse_strerror(int error);
  21. #define Key_parse_TOO_SHORT -1
  22. #define Key_parse_MALFORMED -2
  23. #define Key_parse_DECODE_FAILED -3
  24. /** Invalid cjdns key (doesn't hash to an address beginning with FC) */
  25. #define Key_parse_INVALID -4
  26. /**
  27. * Parse a key.
  28. *
  29. * @param key a public key similar to h9xgk0418x538kg2h5yw4n32rkl4wk4wplkzsmltpg20q78bu7q0.k
  30. * @param keyBytesOut a 32 byte array which will be set to the key.
  31. * @param ip6Out a 16 byte array which will be set to the IPv6 address, if NULL it will be skipped
  32. * and the function will not check if the first byte is FC.
  33. * @return an error code or 0 if no error.
  34. */
  35. int Key_parse(String* key, uint8_t keyBytesOut[32], uint8_t ip6Out[16]);
  36. String* Key_stringify(uint8_t key[32], struct Allocator* alloc);
  37. #endif