/src/openssl111/crypto/comp/comp_lib.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 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 | 
| 8 |  |  */ | 
| 9 |  |  | 
| 10 |  | #include <stdio.h> | 
| 11 |  | #include <stdlib.h> | 
| 12 |  | #include <string.h> | 
| 13 |  | #include <openssl/objects.h> | 
| 14 |  | #include <openssl/comp.h> | 
| 15 |  | #include <openssl/err.h> | 
| 16 |  | #include "comp_local.h" | 
| 17 |  |  | 
| 18 |  | COMP_CTX *COMP_CTX_new(COMP_METHOD *meth) | 
| 19 | 0 | { | 
| 20 | 0 |     COMP_CTX *ret; | 
| 21 |  | 
 | 
| 22 | 0 |     if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { | 
| 23 | 0 |         COMPerr(COMP_F_COMP_CTX_NEW, ERR_R_MALLOC_FAILURE); | 
| 24 | 0 |         return NULL; | 
| 25 | 0 |     } | 
| 26 | 0 |     ret->meth = meth; | 
| 27 | 0 |     if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { | 
| 28 | 0 |         OPENSSL_free(ret); | 
| 29 | 0 |         ret = NULL; | 
| 30 | 0 |     } | 
| 31 | 0 |     return ret; | 
| 32 | 0 | } | 
| 33 |  |  | 
| 34 |  | const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx) | 
| 35 | 0 | { | 
| 36 | 0 |     return ctx->meth; | 
| 37 | 0 | } | 
| 38 |  |  | 
| 39 |  | int COMP_get_type(const COMP_METHOD *meth) | 
| 40 | 12 | { | 
| 41 | 12 |     return meth->type; | 
| 42 | 12 | } | 
| 43 |  |  | 
| 44 |  | const char *COMP_get_name(const COMP_METHOD *meth) | 
| 45 | 0 | { | 
| 46 | 0 |     return meth->name; | 
| 47 | 0 | } | 
| 48 |  |  | 
| 49 |  | void COMP_CTX_free(COMP_CTX *ctx) | 
| 50 | 288k | { | 
| 51 | 288k |     if (ctx == NULL) | 
| 52 | 288k |         return; | 
| 53 | 0 |     if (ctx->meth->finish != NULL) | 
| 54 | 0 |         ctx->meth->finish(ctx); | 
| 55 |  | 
 | 
| 56 | 0 |     OPENSSL_free(ctx); | 
| 57 | 0 | } | 
| 58 |  |  | 
| 59 |  | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, | 
| 60 |  |                         unsigned char *in, int ilen) | 
| 61 | 0 | { | 
| 62 | 0 |     int ret; | 
| 63 | 0 |     if (ctx->meth->compress == NULL) { | 
| 64 | 0 |         return -1; | 
| 65 | 0 |     } | 
| 66 | 0 |     ret = ctx->meth->compress(ctx, out, olen, in, ilen); | 
| 67 | 0 |     if (ret > 0) { | 
| 68 | 0 |         ctx->compress_in += ilen; | 
| 69 | 0 |         ctx->compress_out += ret; | 
| 70 | 0 |     } | 
| 71 | 0 |     return ret; | 
| 72 | 0 | } | 
| 73 |  |  | 
| 74 |  | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, | 
| 75 |  |                       unsigned char *in, int ilen) | 
| 76 | 0 | { | 
| 77 | 0 |     int ret; | 
| 78 |  | 
 | 
| 79 | 0 |     if (ctx->meth->expand == NULL) { | 
| 80 | 0 |         return -1; | 
| 81 | 0 |     } | 
| 82 | 0 |     ret = ctx->meth->expand(ctx, out, olen, in, ilen); | 
| 83 | 0 |     if (ret > 0) { | 
| 84 | 0 |         ctx->expand_in += ilen; | 
| 85 | 0 |         ctx->expand_out += ret; | 
| 86 | 0 |     } | 
| 87 | 0 |     return ret; | 
| 88 | 0 | } | 
| 89 |  |  | 
| 90 |  | int COMP_CTX_get_type(const COMP_CTX* comp) | 
| 91 | 0 | { | 
| 92 | 0 |     return comp->meth ? comp->meth->type : NID_undef; | 
| 93 | 0 | } |