comp_lib.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. {
  11. /* ZZZZZZZZZZZZZZZZ */
  12. return(NULL);
  13. }
  14. memset(ret,0,sizeof(COMP_CTX));
  15. ret->meth=meth;
  16. if ((ret->meth->init != NULL) && !ret->meth->init(ret))
  17. {
  18. OPENSSL_free(ret);
  19. ret=NULL;
  20. }
  21. return(ret);
  22. }
  23. void COMP_CTX_free(COMP_CTX *ctx)
  24. {
  25. if(ctx == NULL)
  26. return;
  27. if (ctx->meth->finish != NULL)
  28. ctx->meth->finish(ctx);
  29. OPENSSL_free(ctx);
  30. }
  31. int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
  32. unsigned char *in, int ilen)
  33. {
  34. int ret;
  35. if (ctx->meth->compress == NULL)
  36. {
  37. /* ZZZZZZZZZZZZZZZZZ */
  38. return(-1);
  39. }
  40. ret=ctx->meth->compress(ctx,out,olen,in,ilen);
  41. if (ret > 0)
  42. {
  43. ctx->compress_in+=ilen;
  44. ctx->compress_out+=ret;
  45. }
  46. return(ret);
  47. }
  48. int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
  49. unsigned char *in, int ilen)
  50. {
  51. int ret;
  52. if (ctx->meth->expand == NULL)
  53. {
  54. /* ZZZZZZZZZZZZZZZZZ */
  55. return(-1);
  56. }
  57. ret=ctx->meth->expand(ctx,out,olen,in,ilen);
  58. if (ret > 0)
  59. {
  60. ctx->expand_in+=ilen;
  61. ctx->expand_out+=ret;
  62. }
  63. return(ret);
  64. }