basic.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef PADDLE_MODEL_PROTECT_UTIL_BASIC_H
  2. #define PADDLE_MODEL_PROTECT_UTIL_BASIC_H
  3. #include <iomanip>
  4. #include <iostream>
  5. #include <random>
  6. #include <string>
  7. #include <sstream>
  8. namespace util {
  9. namespace crypto {
  10. class Basic {
  11. public:
  12. /**
  13. * \brief byte to hex
  14. *
  15. * \note byte to hex.
  16. *
  17. *
  18. * \param in_byte byte array(in)
  19. * \param len byte array length(in)
  20. * \param out_hex the hex string(in)
  21. *
  22. *
  23. * \return return 0 if successful
  24. */
  25. static int byte_to_hex(
  26. const unsigned char* in_byte,
  27. int len,
  28. std::string& out_hex);
  29. /**
  30. * \brief hex to byte
  31. *
  32. * \note hex to byte.
  33. *
  34. *
  35. * \param in_hex the hex string(in)
  36. * \param out_byte byte array(out)
  37. *
  38. * \return return 0 if successful
  39. * -1 invalid in_hex
  40. */
  41. static int hex_to_byte(
  42. const std::string& in_hex,
  43. unsigned char* out_byte);
  44. /**
  45. * \brief get random char for length
  46. *
  47. * \note get random char for length
  48. *
  49. *
  50. * \param array to be random(out)
  51. * \param len array length(in)
  52. *
  53. * \return return 0 if successful
  54. * -1 invalid parameters
  55. */
  56. static int random(
  57. unsigned char* random,
  58. int len);
  59. };
  60. }
  61. } // namespace common
  62. #endif // PADDLE_MODEL_PROTECT_UTIL_BASIC_H