rehash_util.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* GNU Guix --- Functional package management for GNU
  2. Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
  3. This file is part of GNU Guix.
  4. GNU Guix is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or (at
  7. your option) any later version.
  8. GNU Guix is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
  14. /**
  15. * @brief Some hash manipulation
  16. * @author Maxime Devos
  17. */
  18. #ifndef GNUNET_REHASH_UTIL_H
  19. #define GNUNET_REHASH_UTIL_H
  20. #include "rehash_types.h"
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #if 0
  25. }
  26. #endif
  27. #endif
  28. /**
  29. * Convert a given name of a hash to to our internal
  30. * representation.
  31. *
  32. * @param name human readable string (e.g. sha256), NUL-terminated
  33. * @return the hash type on success, #GNUNET_REHASH_HASH_NONE on error
  34. */
  35. enum GNUNET_REHASH_Hash_Type
  36. GNUNET_REHASH_parse_hashtype_string (const char *name);
  37. /**
  38. * How long is the string representation of the hash
  39. * type? (including terminating NUL byte)
  40. *
  41. * @param internal representation (#GNUNET_REHASH_HASH_NONE is invalid!)
  42. * @return the length on success (>0, <=32), 0 if not recognised
  43. */
  44. int
  45. GNUNET_REHASH_hashtype_strsize (enum GNUNET_REHASH_Hash_Type type);
  46. /**
  47. * Write a human readable representation of a hash type.
  48. *
  49. * If the output buffer is too small, only a partial write
  50. * is performed.
  51. *
  52. * @param type hash type to figure out a string of
  53. * @param size size of output buffer
  54. * @param outbuf location to write output, including terminating NUL byte
  55. * @return the size of the actual string (including NUL byte), or 0
  56. * if type is unrecognised
  57. */
  58. int
  59. GNUNET_REHASH_unparse_hashtype (enum GNUNET_REHASH_Hash_Type type, int size, char outbuf[]);
  60. #if 0
  61. {
  62. #endif
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif