gchecksum.h 3.6 KB

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