gchecksum.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* gchecksum.h - data hashing functions
  2. *
  3. * Copyright (C) 2007 Emmanuele Bassi <[email protected]>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public
  16. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __G_CHECKSUM_H__
  19. #define __G_CHECKSUM_H__
  20. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  21. #error "Only <glib.h> can be included directly."
  22. #endif
  23. #include <glib/gtypes.h>
  24. #include <glib/gbytes.h>
  25. G_BEGIN_DECLS
  26. /**
  27. * GChecksumType:
  28. * @G_CHECKSUM_MD5: Use the MD5 hashing algorithm
  29. * @G_CHECKSUM_SHA1: Use the SHA-1 hashing algorithm
  30. * @G_CHECKSUM_SHA256: Use the SHA-256 hashing algorithm
  31. * @G_CHECKSUM_SHA512: Use the SHA-512 hashing algorithm
  32. *
  33. * The hashing algorithm to be used by #GChecksum when performing the
  34. * digest of some data.
  35. *
  36. * Note that the #GChecksumType enumeration may be extended at a later
  37. * date to include new hashing algorithm types.
  38. *
  39. * Since: 2.16
  40. */
  41. typedef enum {
  42. G_CHECKSUM_MD5,
  43. G_CHECKSUM_SHA1,
  44. G_CHECKSUM_SHA256,
  45. G_CHECKSUM_SHA512
  46. } GChecksumType;
  47. /**
  48. * GChecksum:
  49. *
  50. * An opaque structure representing a checksumming operation.
  51. * To create a new GChecksum, use g_checksum_new(). To free
  52. * a GChecksum, use g_checksum_free().
  53. *
  54. * Since: 2.16
  55. */
  56. typedef struct _GChecksum GChecksum;
  57. GLIB_AVAILABLE_IN_ALL
  58. gssize g_checksum_type_get_length (GChecksumType checksum_type);
  59. GLIB_AVAILABLE_IN_ALL
  60. GChecksum * g_checksum_new (GChecksumType checksum_type);
  61. GLIB_AVAILABLE_IN_ALL
  62. void g_checksum_reset (GChecksum *checksum);
  63. GLIB_AVAILABLE_IN_ALL
  64. GChecksum * g_checksum_copy (const GChecksum *checksum);
  65. GLIB_AVAILABLE_IN_ALL
  66. void g_checksum_free (GChecksum *checksum);
  67. GLIB_AVAILABLE_IN_ALL
  68. void g_checksum_update (GChecksum *checksum,
  69. const guchar *data,
  70. gssize length);
  71. GLIB_AVAILABLE_IN_ALL
  72. const gchar * g_checksum_get_string (GChecksum *checksum);
  73. GLIB_AVAILABLE_IN_ALL
  74. void g_checksum_get_digest (GChecksum *checksum,
  75. guint8 *buffer,
  76. gsize *digest_len);
  77. GLIB_AVAILABLE_IN_ALL
  78. gchar *g_compute_checksum_for_data (GChecksumType checksum_type,
  79. const guchar *data,
  80. gsize length);
  81. GLIB_AVAILABLE_IN_ALL
  82. gchar *g_compute_checksum_for_string (GChecksumType checksum_type,
  83. const gchar *str,
  84. gssize length);
  85. GLIB_AVAILABLE_IN_2_34
  86. gchar *g_compute_checksum_for_bytes (GChecksumType checksum_type,
  87. GBytes *data);
  88. G_END_DECLS
  89. #endif /* __G_CHECKSUM_H__ */