]>
git.proxmox.com Git - libgit2.git/blob - tests/filter/custom_helpers.c
ee3b6353b322c265a7a5cb5e5383e82c00370e34
1 #include "clar_libgit2.h"
4 #include "git2/sys/filter.h"
6 #define VERY_SECURE_ENCRYPTION(b) ((b) ^ 0xff)
8 int bitflip_filter_apply(
13 const git_filter_source
*source
)
15 const unsigned char *src
= (const unsigned char *)from
->ptr
;
19 GIT_UNUSED(self
); GIT_UNUSED(payload
);
21 /* verify that attribute path match worked as expected */
23 0, git__strncmp("hero", git_filter_source_path(source
), 4));
28 cl_git_pass(git_buf_grow(to
, from
->size
));
30 dst
= (unsigned char *)to
->ptr
;
32 for (i
= 0; i
< from
->size
; i
++)
33 dst
[i
] = VERY_SECURE_ENCRYPTION(src
[i
]);
35 to
->size
= from
->size
;
40 static int bitflip_filter_stream(
41 git_writestream
**out
,
44 const git_filter_source
*src
,
45 git_writestream
*next
)
47 return git_filter_buffered_stream_new(out
,
48 self
, bitflip_filter_apply
, NULL
, payload
, src
, next
);
51 static void bitflip_filter_free(git_filter
*f
)
56 git_filter
*create_bitflip_filter(void)
58 git_filter
*filter
= git__calloc(1, sizeof(git_filter
));
61 filter
->version
= GIT_FILTER_VERSION
;
62 filter
->attributes
= "+bitflip";
63 filter
->shutdown
= bitflip_filter_free
;
64 filter
->stream
= bitflip_filter_stream
;
70 int reverse_filter_apply(
75 const git_filter_source
*source
)
77 const unsigned char *src
= (const unsigned char *)from
->ptr
;
78 const unsigned char *end
= src
+ from
->size
;
81 GIT_UNUSED(self
); GIT_UNUSED(payload
); GIT_UNUSED(source
);
83 /* verify that attribute path match worked as expected */
85 0, git__strncmp("hero", git_filter_source_path(source
), 4));
90 cl_git_pass(git_buf_grow(to
, from
->size
));
92 dst
= (unsigned char *)to
->ptr
+ from
->size
- 1;
97 to
->size
= from
->size
;
102 static int reverse_filter_stream(
103 git_writestream
**out
,
106 const git_filter_source
*src
,
107 git_writestream
*next
)
109 return git_filter_buffered_stream_new(out
,
110 self
, reverse_filter_apply
, NULL
, payload
, src
, next
);
113 static void reverse_filter_free(git_filter
*f
)
118 git_filter
*create_reverse_filter(const char *attrs
)
120 git_filter
*filter
= git__calloc(1, sizeof(git_filter
));
123 filter
->version
= GIT_FILTER_VERSION
;
124 filter
->attributes
= attrs
;
125 filter
->shutdown
= reverse_filter_free
;
126 filter
->stream
= reverse_filter_stream
;
131 int erroneous_filter_stream(
132 git_writestream
**out
,
135 const git_filter_source
*src
,
136 git_writestream
*next
)
146 static void erroneous_filter_free(git_filter
*f
)
151 git_filter
*create_erroneous_filter(const char *attrs
)
153 git_filter
*filter
= git__calloc(1, sizeof(git_filter
));
156 filter
->version
= GIT_FILTER_VERSION
;
157 filter
->attributes
= attrs
;
158 filter
->stream
= erroneous_filter_stream
;
159 filter
->shutdown
= erroneous_filter_free
;