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