Peter's C++ toolbox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

encode.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2002-2006 Peter J Jones (pjones@pmade.org)
  3. * All Rights Reserved
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. * 3. Neither the name of the Author nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  22. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
  23. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  26. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  29. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. */
  32. #ifndef _cxxtools_encode_h_
  33. #define _cxxtools_encode_h_
  34. // standard includes
  35. #include <string>
  36. namespace Cxxtools {
  37. namespace Encode {
  38. //####################################################################
  39. /**
  40. * Base64 encode the given string.
  41. *
  42. * @param s The string to encode.
  43. * @return The encoded string.
  44. * @author Peter Jones
  45. **/
  46. //####################################################################
  47. std::string base64_encode (const std::string &s);
  48. //####################################################################
  49. /**
  50. * Decode the given Base64 string.
  51. *
  52. * @param s The string to decode.
  53. * @return The decoded string.
  54. * @author Peter Jones
  55. **/
  56. //####################################################################
  57. std::string base64_decode (const std::string &s);
  58. //####################################################################
  59. /**
  60. * Digest the given string using the MD5 algorithm.
  61. *
  62. * @param s The string to digest.
  63. * @return The result of digesting s with MD5.
  64. * @author Peter Jones
  65. **/
  66. //####################################################################
  67. std::string md5 (const std::string &s);
  68. //####################################################################
  69. /**
  70. * Digest the given string using the SHA1 algorithm.
  71. *
  72. * @param s The string to digest.
  73. * @return The result of digesting s with SHA1.
  74. * @author Peter Jones
  75. **/
  76. //####################################################################
  77. std::string sha1 (const std::string &s);
  78. }} // end Cxxtools and Encode namespaces
  79. #endif