Debian Codegraph @

device-src/s3-util.h

raw
1 /*
2 * Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
3 * Copyright (c) 2013-2016 Carbonite, Inc. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Contact information: Carbonite Inc., 756 N Pastoria Ave
20 * Sunnyvale, CA 94085, or: http://www.zmanda.com
21 */
22
23 #ifndef __S3_UTIL_H__
24 #define __S3_UTIL_H__
25
26 #ifdef HAVE_REGEX_H
27 # ifdef HAVE_SYS_TYPES_H
28 # include <sys/types.h>
29 # endif
30 #include <regex.h>
31 #endif
32 #include <glib.h>
33
34 /*
35 * Constants
36 */
37
38 /* number of raw bytes in MD5 hash */
39 #define S3_MD5_HASH_BYTE_LEN 16
40 /* length of an MD5 hash encoded as base64 (not including terminating NULL) */
41 #define S3_MD5_HASH_B64_LEN 25
42 /* length of an MD5 hash encoded as hexadecimal (not including terminating NULL) */
43 #define S3_MD5_HASH_HEX_LEN 32
44
45 /*
46 * Types
47 */
48
49 #ifndef HAVE_REGEX_H
50 typedef GRegex* regex_t;
51
52 typedef gint regoff_t;
53 typedef struct
54 {
55 regoff_t rm_so; /* Byte offset from string's start to substring's start. */
56 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
57 } regmatch_t;
58
59 typedef enum
60 {
61 REG_NOERROR = 0, /* Success. */
62 REG_NOMATCH /* Didn't find a match (for regexec). */
63 } reg_errcode_t;
64 #endif
65
66 /*
67 * Functions
68 */
69
70 #ifndef USE_GETTEXT
71 /* we don't use gettextize, so hack around this ... */
72 #undef _
73 #define _(str) (str)
74 #endif
75
76 /*
77 * Wrapper around regexec to handle programmer errors.
78 * Only returns if the regexec returns 0 (match) or REG_NOMATCH.
79 * See regexec(3) documentation for the rest.
80 */
81 int
82 s3_regexec_wrap(regex_t *regex,
83 const char *str,
84 size_t nmatch,
85 regmatch_t pmatch[],
86 int eflags);
87
88 #ifndef HAVE_AMANDA_H
89 char*
90 find_regex_substring(const char* base_string,
91 const regmatch_t match);
92 #endif
93
94 /*
95 * Encode bytes using Base-64
96 *
97 * @note: GLib 2.12+ has a function for this (g_base64_encode)
98 * but we support much older versions. gnulib does as well, but its
99 * hard to use correctly (see its notes).
100 *
101 * @param to_enc: The data to encode.
102 * @returns: A new, null-terminated string or NULL if to_enc is NULL.
103 */
104 gchar*
105 s3_base64_encode(const GByteArray *to_enc);
106
107 /*
108 * Encode bytes using hexadecimal
109 *
110 * @param to_enc: The data to encode.
111 * @returns: A new, null-terminated string or NULL if to_enc is NULL.
112 */
113 gchar*
114 s3_hex_encode(const GByteArray *to_enc);
115
116 /*
117 * Compute the MD5 hash of a blob of data.
118 *
119 * @param to_hash: The data to compute the hash for.
120 * @returns: A new GByteArray containing the MD5 hash of data or
121 * NULL if to_hash is NULL.
122 */
123 GByteArray*
124 s3_compute_md5_hash(const GByteArray *to_hash);
125
126 char *
127 s3_compute_sha256_hash_ba(const GByteArray *to_hash);
128 char *
129 s3_compute_sha256_hash(const unsigned char *to_hash, int len);
130
131 char *
132 s3_uri_encode(const char *s, gboolean encodeSlash);
133
134 unsigned char *
135 EncodeHMACSHA256(
136 unsigned char* key,
137 int keylen,
138 const char* data,
139 int datalen);
140
141 unsigned char *
142 s3_tohex(unsigned char *s, int len_s);
143
144 #endif
145