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