155714Skris#include <stdio.h> 255714Skris#include <stdlib.h> 355714Skris#include <string.h> 455714Skris#include <openssl/objects.h> 555714Skris#include <openssl/comp.h> 655714Skris 755714SkrisCOMP_CTX *COMP_CTX_new(COMP_METHOD *meth) 8296341Sdelphij{ 9296341Sdelphij COMP_CTX *ret; 1055714Skris 11296341Sdelphij if ((ret = (COMP_CTX *)OPENSSL_malloc(sizeof(COMP_CTX))) == NULL) { 12296341Sdelphij /* ZZZZZZZZZZZZZZZZ */ 13296341Sdelphij return (NULL); 14296341Sdelphij } 15296341Sdelphij memset(ret, 0, sizeof(COMP_CTX)); 16296341Sdelphij ret->meth = meth; 17296341Sdelphij if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { 18296341Sdelphij OPENSSL_free(ret); 19296341Sdelphij ret = NULL; 20296341Sdelphij } 21296341Sdelphij return (ret); 22296341Sdelphij} 2355714Skris 2455714Skrisvoid COMP_CTX_free(COMP_CTX *ctx) 25296341Sdelphij{ 26296341Sdelphij if (ctx == NULL) 27296341Sdelphij return; 2855714Skris 29296341Sdelphij if (ctx->meth->finish != NULL) 30296341Sdelphij ctx->meth->finish(ctx); 3155714Skris 32296341Sdelphij OPENSSL_free(ctx); 33296341Sdelphij} 3455714Skris 3555714Skrisint COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 36296341Sdelphij unsigned char *in, int ilen) 37296341Sdelphij{ 38296341Sdelphij int ret; 39296341Sdelphij if (ctx->meth->compress == NULL) { 40296341Sdelphij /* ZZZZZZZZZZZZZZZZZ */ 41296341Sdelphij return (-1); 42296341Sdelphij } 43296341Sdelphij ret = ctx->meth->compress(ctx, out, olen, in, ilen); 44296341Sdelphij if (ret > 0) { 45296341Sdelphij ctx->compress_in += ilen; 46296341Sdelphij ctx->compress_out += ret; 47296341Sdelphij } 48296341Sdelphij return (ret); 49296341Sdelphij} 5055714Skris 5155714Skrisint COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 52296341Sdelphij unsigned char *in, int ilen) 53296341Sdelphij{ 54296341Sdelphij int ret; 5555714Skris 56296341Sdelphij if (ctx->meth->expand == NULL) { 57296341Sdelphij /* ZZZZZZZZZZZZZZZZZ */ 58296341Sdelphij return (-1); 59296341Sdelphij } 60296341Sdelphij ret = ctx->meth->expand(ctx, out, olen, in, ilen); 61296341Sdelphij if (ret > 0) { 62296341Sdelphij ctx->expand_in += ilen; 63296341Sdelphij ctx->expand_out += ret; 64296341Sdelphij } 65296341Sdelphij return (ret); 66296341Sdelphij} 67