2 * Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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>
16 #include "comp_local.h"
18 COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
25 if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
28 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
35 const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx)
40 int COMP_get_type(const COMP_METHOD *meth)
47 const char *COMP_get_name(const COMP_METHOD *meth)
54 void COMP_CTX_free(COMP_CTX *ctx)
58 if (ctx->meth->finish != NULL)
59 ctx->meth->finish(ctx);
64 int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
65 unsigned char *in, int ilen)
68 if (ctx->meth->compress == NULL) {
71 ret = ctx->meth->compress(ctx, out, olen, in, ilen);
73 ctx->compress_in += ilen;
74 ctx->compress_out += ret;
79 int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
80 unsigned char *in, int ilen)
84 if (ctx->meth->expand == NULL) {
87 ret = ctx->meth->expand(ctx, out, olen, in, ilen);
89 ctx->expand_in += ilen;
90 ctx->expand_out += ret;
95 int COMP_CTX_get_type(const COMP_CTX* comp)
97 return comp->meth ? comp->meth->type : NID_undef;