]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/comp/c_rle.c
Run util/openssl-format-source -v -c .
[thirdparty/openssl.git] / crypto / comp / c_rle.c
CommitLineData
dfeab068
RE
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
ec577822
BM
4#include <openssl/objects.h>
5#include <openssl/comp.h>
dfeab068
RE
6
7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
0f113f3e
MC
8 unsigned int olen, unsigned char *in,
9 unsigned int ilen);
dfeab068 10static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
0f113f3e
MC
11 unsigned int olen, unsigned char *in,
12 unsigned int ilen);
13
14static COMP_METHOD rle_method = {
15 NID_rle_compression,
16 LN_rle_compression,
17 NULL,
18 NULL,
19 rle_compress_block,
20 rle_expand_block,
21 NULL,
22 NULL,
23};
dfeab068 24
6b691a5c 25COMP_METHOD *COMP_rle(void)
0f113f3e
MC
26{
27 return (&rle_method);
28}
dfeab068 29
6b691a5c 30static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
0f113f3e
MC
31 unsigned int olen, unsigned char *in,
32 unsigned int ilen)
33{
34 /* int i; */
dfeab068 35
0f113f3e
MC
36 if (olen < (ilen + 1)) {
37 /* ZZZZZZZZZZZZZZZZZZZZZZ */
38 return (-1);
39 }
dfeab068 40
0f113f3e
MC
41 *(out++) = 0;
42 memcpy(out, in, ilen);
43 return (ilen + 1);
44}
dfeab068 45
6b691a5c 46static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
0f113f3e
MC
47 unsigned int olen, unsigned char *in,
48 unsigned int ilen)
49{
50 int i;
51
52 if (ilen == 0 || olen < (ilen - 1)) {
53 /* ZZZZZZZZZZZZZZZZZZZZZZ */
54 return (-1);
55 }
56
57 i = *(in++);
58 if (i == 0) {
59 memcpy(out, in, ilen - 1);
60 }
61 return (ilen - 1);
62}