/src/openssl/crypto/comp/comp_lib.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
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 |
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 (meth == NULL) |
23 | 0 | return NULL; |
24 | | |
25 | 0 | if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) |
26 | 0 | return NULL; |
27 | 0 | ret->meth = meth; |
28 | 0 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { |
29 | 0 | OPENSSL_free(ret); |
30 | 0 | ret = NULL; |
31 | 0 | } |
32 | 0 | return ret; |
33 | 0 | } |
34 | | |
35 | | const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx) |
36 | 0 | { |
37 | 0 | return ctx->meth; |
38 | 0 | } |
39 | | |
40 | | int COMP_get_type(const COMP_METHOD *meth) |
41 | 4 | { |
42 | 4 | if (meth == NULL) |
43 | 4 | return NID_undef; |
44 | 0 | return meth->type; |
45 | 4 | } |
46 | | |
47 | | const char *COMP_get_name(const COMP_METHOD *meth) |
48 | 0 | { |
49 | 0 | if (meth == NULL) |
50 | 0 | return NULL; |
51 | 0 | return meth->name; |
52 | 0 | } |
53 | | |
54 | | void COMP_CTX_free(COMP_CTX *ctx) |
55 | 0 | { |
56 | 0 | if (ctx == NULL) |
57 | 0 | return; |
58 | 0 | if (ctx->meth->finish != NULL) |
59 | 0 | ctx->meth->finish(ctx); |
60 | |
|
61 | 0 | OPENSSL_free(ctx); |
62 | 0 | } |
63 | | |
64 | | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, |
65 | | unsigned char *in, int ilen) |
66 | 0 | { |
67 | 0 | int ret; |
68 | 0 | if (ctx->meth->compress == NULL) { |
69 | 0 | return -1; |
70 | 0 | } |
71 | 0 | ret = ctx->meth->compress(ctx, out, olen, in, ilen); |
72 | 0 | if (ret > 0) { |
73 | 0 | ctx->compress_in += ilen; |
74 | 0 | ctx->compress_out += ret; |
75 | 0 | } |
76 | 0 | return ret; |
77 | 0 | } |
78 | | |
79 | | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, |
80 | | unsigned char *in, int ilen) |
81 | 0 | { |
82 | 0 | int ret; |
83 | |
|
84 | 0 | if (ctx->meth->expand == NULL) { |
85 | 0 | return -1; |
86 | 0 | } |
87 | 0 | ret = ctx->meth->expand(ctx, out, olen, in, ilen); |
88 | 0 | if (ret > 0) { |
89 | 0 | ctx->expand_in += ilen; |
90 | 0 | ctx->expand_out += ret; |
91 | 0 | } |
92 | 0 | return ret; |
93 | 0 | } |
94 | | |
95 | | int COMP_CTX_get_type(const COMP_CTX* comp) |
96 | 0 | { |
97 | 0 | return comp->meth ? comp->meth->type : NID_undef; |
98 | 0 | } |