Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
86c58a5b
Commit
86c58a5b
authored
Feb 07, 2022
by
Edward Thomson
Committed by
Edward Thomson
Feb 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
str: add hexadigit encoding to strings
parent
3c53796c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
src/str.c
+26
-0
src/str.h
+3
-0
No files found.
src/str.c
View file @
86c58a5b
...
@@ -217,6 +217,32 @@ int git_str_puts(git_str *buf, const char *string)
...
@@ -217,6 +217,32 @@ int git_str_puts(git_str *buf, const char *string)
return
git_str_put
(
buf
,
string
,
strlen
(
string
));
return
git_str_put
(
buf
,
string
,
strlen
(
string
));
}
}
static
char
hex_encode
[]
=
"0123456789abcdef"
;
int
git_str_encode_hexstr
(
git_str
*
str
,
const
char
*
data
,
size_t
len
)
{
size_t
new_size
,
i
;
char
*
s
;
GIT_ERROR_CHECK_ALLOC_MULTIPLY
(
&
new_size
,
len
,
2
);
GIT_ERROR_CHECK_ALLOC_ADD
(
&
new_size
,
new_size
,
1
);
if
(
git_str_grow_by
(
str
,
new_size
)
<
0
)
return
-
1
;
s
=
str
->
ptr
+
str
->
size
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
*
s
++
=
hex_encode
[(
data
[
i
]
&
0xf0
)
>>
4
];
*
s
++
=
hex_encode
[(
data
[
i
]
&
0x0f
)];
}
str
->
size
+=
(
len
*
2
);
str
->
ptr
[
str
->
size
]
=
'\0'
;
return
0
;
}
static
const
char
base64_encode
[]
=
static
const
char
base64_encode
[]
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
...
...
src/str.h
View file @
86c58a5b
...
@@ -217,6 +217,9 @@ int git_str_cmp(const git_str *a, const git_str *b);
...
@@ -217,6 +217,9 @@ int git_str_cmp(const git_str *a, const git_str *b);
int
git_str_quote
(
git_str
*
str
);
int
git_str_quote
(
git_str
*
str
);
int
git_str_unquote
(
git_str
*
str
);
int
git_str_unquote
(
git_str
*
str
);
/* Write data as a hex string */
int
git_str_encode_hexstr
(
git_str
*
str
,
const
char
*
data
,
size_t
len
);
/* Write data as base64 encoded in string buffer */
/* Write data as base64 encoded in string buffer */
int
git_str_encode_base64
(
git_str
*
str
,
const
char
*
data
,
size_t
len
);
int
git_str_encode_base64
(
git_str
*
str
,
const
char
*
data
,
size_t
len
);
/* Decode the given bas64 and write the result to the string buffer */
/* Decode the given bas64 and write the result to the string buffer */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment