comp_lib.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <openssl/objects.h>
  5. #include <openssl/comp.h>
  6. COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
  7. {
  8. COMP_CTX *ret;
  9. if ((ret = (COMP_CTX *)OPENSSL_malloc(sizeof(COMP_CTX))) == NULL) {
  10. /* ZZZZZZZZZZZZZZZZ */
  11. return (NULL);
  12. }
  13. memset(ret, 0, sizeof(COMP_CTX));
  14. ret->meth = meth;
  15. if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
  16. OPENSSL_free(ret);
  17. ret = NULL;
  18. }
  19. return (ret);
  20. }
  21. void COMP_CTX_free(COMP_CTX *ctx)
  22. {
  23. if (ctx == NULL)
  24. return;
  25. if (ctx->meth->finish != NULL)
  26. ctx->meth->finish(ctx);
  27. OPENSSL_free(ctx);
  28. }
  29. int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
  30. unsigned char *in, int ilen)
  31. {
  32. int ret;
  33. if (ctx->meth->compress == NULL) {
  34. /* ZZZZZZZZZZZZZZZZZ */
  35. return (-1);
  36. }
  37. ret = ctx->meth->compress(ctx, out, olen, in, ilen);
  38. if (ret > 0) {
  39. ctx->compress_in += ilen;
  40. ctx->compress_out += ret;
  41. }
  42. return (ret);
  43. }
  44. int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
  45. unsigned char *in, int ilen)
  46. {
  47. int ret;
  48. if (ctx->meth->expand == NULL) {
  49. /* ZZZZZZZZZZZZZZZZZ */
  50. return (-1);
  51. }
  52. ret = ctx->meth->expand(ctx, out, olen, in, ilen);
  53. if (ret > 0) {
  54. ctx->expand_in += ilen;
  55. ctx->expand_out += ret;
  56. }
  57. return (ret);
  58. }