Key.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 "util/Linker.h"
  20. Linker_require("crypto/Key.c")
  21. #include <stdint.h>
  22. char* Key_parse_strerror(int error);
  23. #define Key_parse_TOO_SHORT -1
  24. #define Key_parse_MALFORMED -2
  25. #define Key_parse_DECODE_FAILED -3
  26. /** Invalid cjdns key (doesn't hash to an address beginning with FC) */
  27. #define Key_parse_INVALID -4
  28. /**
  29. * Parse a key.
  30. *
  31. * @param key a public key similar to h9xgk0418x538kg2h5yw4n32rkl4wk4wplkzsmltpg20q78bu7q0.k
  32. * @param keyBytesOut a 32 byte array which will be set to the key.
  33. * @param ip6Out a 16 byte array which will be set to the IPv6 address, if NULL it will be skipped
  34. * and the function will not check if the first byte is FC.
  35. * @return an error code or 0 if no error.
  36. */
  37. int Key_parse(String* key, uint8_t keyBytesOut[32], uint8_t ip6Out[16]);
  38. String* Key_stringify(uint8_t key[32], struct Allocator* alloc);
  39. #endif