2 * Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
13 #include <openssl/objects.h>
14 #include <openssl/comp.h>
15 #include <openssl/err.h>
18 COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
22 if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
23 COMPerr(COMP_F_COMP_CTX_NEW, ERR_R_MALLOC_FAILURE);
27 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
34 const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx)
39 int COMP_get_type(const COMP_METHOD *meth)
44 const char *COMP_get_name(const COMP_METHOD *meth)
49 void COMP_CTX_free(COMP_CTX *ctx)
53 if (ctx->meth->finish != NULL)
54 ctx->meth->finish(ctx);
59 int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
60 unsigned char *in, int ilen)
63 if (ctx->meth->compress == NULL) {
66 ret = ctx->meth->compress(ctx, out, olen, in, ilen);
68 ctx->compress_in += ilen;
69 ctx->compress_out += ret;
74 int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
75 unsigned char *in, int ilen)
79 if (ctx->meth->expand == NULL) {
82 ret = ctx->meth->expand(ctx, out, olen, in, ilen);
84 ctx->expand_in += ilen;
85 ctx->expand_out += ret;
90 int COMP_CTX_get_type(const COMP_CTX* comp)
92 return comp->meth ? comp->meth->type : NID_undef;