zcrypt.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef ZCRYPT_HPP__
  14. #define ZCRYPT_HPP__
  15. #ifndef ZCRYPT_API
  16. #ifdef _WIN32
  17. #ifndef ZCRYPT_EXPORTS
  18. #define ZCRYPT_API __declspec(dllimport)
  19. #else
  20. #define ZCRYPT_API __declspec(dllexport)
  21. #endif
  22. #else
  23. #define ZCRYPT_API
  24. #endif //_WIN32
  25. #endif
  26. #include <string>
  27. #include "platform.h"
  28. #include "jlib.hpp"
  29. using namespace std;
  30. class ZCRYPT_API IZInterface
  31. {
  32. public:
  33. virtual ~IZInterface() {}
  34. };
  35. class ZCRYPT_API IZBuffer : public IZInterface
  36. {
  37. public:
  38. virtual ~IZBuffer();
  39. virtual int length() = 0;
  40. virtual unsigned char* buffer() = 0;
  41. };
  42. class ZCRYPT_API IZEncryptor : public IZInterface
  43. {
  44. public:
  45. virtual ~IZEncryptor();
  46. virtual void setTraceLevel(unsigned trace_level) = 0;
  47. virtual void setEncoding(bool yes = true) = 0;
  48. virtual int encrypt(int in_len, unsigned char* in, IZBuffer*& session_key, IZBuffer*& encrypted_data) = 0;
  49. };
  50. class ZCRYPT_API IZDecryptor : public IZInterface
  51. {
  52. public:
  53. virtual ~IZDecryptor();
  54. virtual void setTraceLevel(unsigned trace_level) = 0;
  55. virtual void setEncoding(bool yes = true) = 0;
  56. virtual IZBuffer* decrypt(int key_len, unsigned char* keybuf, int in_len, unsigned char* inbuf) = 0;
  57. virtual IZBuffer* decrypt(unsigned char* keybuf, unsigned char* inbuf) = 0;
  58. };
  59. class ZCRYPT_API IZZIPor : public IZInterface
  60. {
  61. public:
  62. virtual ~IZZIPor();
  63. virtual void setTraceLevel(unsigned trace_level) = 0;
  64. virtual int gzipToFile(unsigned in_len, void const *in, const char* fileToBeZipped) = 0;
  65. virtual int addContentToZIP(unsigned contentLength, void *content, char* fileName, bool append = false) = 0;
  66. virtual int addContentToZIP(unsigned contentLength, void *content, char* fileName, time_t tm, bool append = false) = 0;
  67. virtual int zipToFile(unsigned in_len, void const *in, const char* fileToBeZipped, const char* zippedFileName) = 0;
  68. virtual int zipToFile(const char* zipFileName, bool cleanFileListAfterUsed = true) = 0;
  69. };
  70. extern "C"
  71. {
  72. ZCRYPT_API IZZIPor* createZZIPor();
  73. ZCRYPT_API IZEncryptor* createZEncryptor(const char* publickey);
  74. ZCRYPT_API IZDecryptor* createZDecryptor(const char* privatekey, const char* passphrase);
  75. ZCRYPT_API void releaseIZ(IZInterface* iz);
  76. }
  77. // the following GZ_* values map to corresponding Z_* values defined in zlib.h
  78. #define GZ_BEST_SPEED 1
  79. #define GZ_BEST_COMPRESSION 9
  80. #define GZ_DEFAULT_COMPRESSION (-1)
  81. // Compress a character buffer using zlib in gzip format with given compression level
  82. char* gzip( const char* inputBuffer, unsigned int inputSize,
  83. unsigned int* outlen, int compressionLevel=GZ_DEFAULT_COMPRESSION);
  84. void gunzip(const byte* compressed, unsigned int comprLen, StringBuffer& sOutput);
  85. #endif