-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytestring.h
103 lines (80 loc) · 2.94 KB
/
bytestring.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**********************************************************************
*
* This file is part of Cardpeek, the smartcard reader utility.
*
* Copyright 2009 by 'L1L1'
*
* Cardpeek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cardpeek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cardpeek. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BYTESTRING_H
#define BYTESTRING_H
typedef struct {
unsigned len;
unsigned alloc;
unsigned char *data;
} bytestring_t;
enum {
BYTESTRING_ERROR=0,
BYTESTRING_OK=1,
BYTESTRING_NPOS=0x7FFFFFFF
};
bytestring_t* bytestring_new();
bytestring_t* bytestring_new_from_hex(const char *hex);
bytestring_t* bytestring_duplicate(const bytestring_t *bs);
int bytestring_assign_data(bytestring_t* bs,
unsigned len, const unsigned char *data);
int bytestring_assign_uchar(bytestring_t* bs,
unsigned len, unsigned char c);
int bytestring_copy(bytestring_t *bs,
const bytestring_t *src);
int bytestring_append(bytestring_t *bs,
const bytestring_t *extra);
int bytestring_append_data(bytestring_t *bs,
unsigned len, const unsigned char *data);
int bytestring_append_uchar(bytestring_t* bs,
unsigned len, unsigned char c);
int bytestring_pushback(bytestring_t *bs,
unsigned char c);
int bytestring_set_uchar(const bytestring_t *bs,
int pos, unsigned char c);
unsigned char bytestring_get_uchar(const bytestring_t *bs,
int pos);
void bytestring_clear(bytestring_t *bs);
const unsigned char *bytestring_get_data(const bytestring_t *bs);
int bytestring_erase(bytestring_t *bs,
unsigned pos,
unsigned len);
int bytestring_is_empty(const bytestring_t *bs);
int bytestring_is_printable(const bytestring_t *bs);
int bytestring_insert_data(bytestring_t *bs,
unsigned pos,
unsigned len, const unsigned char* data);
int bytestring_insert_uchar(bytestring_t *bs,
unsigned pos,
unsigned len, unsigned char c);
int bytestring_insert(bytestring_t *bs,
unsigned pos,
const bytestring_t *src);
int bytestring_reserve(bytestring_t *bs, unsigned size);
int bytestring_resize(bytestring_t *bs, unsigned len);
unsigned bytestring_get_size(const bytestring_t *bs);
int bytestring_substr(const bytestring_t *src,
unsigned pos, unsigned len,
bytestring_t* dst);
char *bytestring_to_string(const bytestring_t *bs);
char *bytestring_to_hex_string(const bytestring_t *bs);
void bytestring_free(bytestring_t *bs);
/* unsigned subbitstr(unsigned bpos, unsigned blen) const; */
#endif