Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
12729d62
Unverified
Commit
12729d62
authored
6 years ago
by
Juan I Carrano
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #10053 from OTAkeys/feat/base64_const
sys/base64: api change (const + void*)
parents
8148790e
394c3ecd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/base64/base64.c
+8
-6
8 additions, 6 deletions
sys/base64/base64.c
sys/include/base64.h
+3
-3
3 additions, 3 deletions
sys/include/base64.h
with
11 additions
and
9 deletions
sys/base64/base64.c
+
8
−
6
View file @
12729d62
...
@@ -56,9 +56,10 @@ static char getsymbol(unsigned char code)
...
@@ -56,9 +56,10 @@ static char getsymbol(unsigned char code)
return
(
char
)
BASE64_NOT_DEFINED
;
return
(
char
)
BASE64_NOT_DEFINED
;
}
}
int
base64_encode
(
unsigned
char
*
data_in
,
size_t
data_in_size
,
\
int
base64_encode
(
const
void
*
data_in
,
size_t
data_in_size
,
unsigned
char
*
base64_out
,
size_t
*
base64_out_size
)
unsigned
char
*
base64_out
,
size_t
*
base64_out_size
)
{
{
const
unsigned
char
*
in
=
data_in
;
size_t
required_size
=
4
*
((
data_in_size
+
2
)
/
3
);
size_t
required_size
=
4
*
((
data_in_size
+
2
)
/
3
);
if
(
data_in
==
NULL
)
{
if
(
data_in
==
NULL
)
{
...
@@ -86,7 +87,7 @@ int base64_encode(unsigned char *data_in, size_t data_in_size, \
...
@@ -86,7 +87,7 @@ int base64_encode(unsigned char *data_in, size_t data_in_size, \
for
(
int
i
=
0
;
i
<
(
int
)(
data_in_size
);
++
i
)
{
for
(
int
i
=
0
;
i
<
(
int
)(
data_in_size
);
++
i
)
{
unsigned
char
tmpval
;
unsigned
char
tmpval
;
njump
++
;
njump
++
;
tmpval
=
*
(
data_
in
+
i
);
tmpval
=
*
(
in
+
i
);
nNum
=
(
tmpval
>>
(
2
*
njump
));
nNum
=
(
tmpval
>>
(
2
*
njump
));
...
@@ -159,9 +160,10 @@ static int getcode(char symbol)
...
@@ -159,9 +160,10 @@ static int getcode(char symbol)
return
BASE64_NOT_DEFINED
;
return
BASE64_NOT_DEFINED
;
}
}
int
base64_decode
(
unsigned
char
*
base64_in
,
size_t
base64_in_size
,
\
int
base64_decode
(
const
unsigned
char
*
base64_in
,
size_t
base64_in_size
,
unsigned
char
*
data_out
,
size_t
*
data_out_size
)
void
*
data_out
,
size_t
*
data_out_size
)
{
{
unsigned
char
*
out
=
data_out
;
size_t
required_size
=
((
base64_in_size
/
4
)
*
3
);
size_t
required_size
=
((
base64_in_size
/
4
)
*
3
);
if
(
base64_in
==
NULL
)
{
if
(
base64_in
==
NULL
)
{
...
@@ -200,13 +202,13 @@ int base64_decode(unsigned char *base64_in, size_t base64_in_size, \
...
@@ -200,13 +202,13 @@ int base64_decode(unsigned char *base64_in, size_t base64_in_size, \
nNum
=
nLst
+
((
code
&
(
0xFF
&
nm
))
>>
(
2
*
mask
));
nNum
=
nLst
+
((
code
&
(
0xFF
&
nm
))
>>
(
2
*
mask
));
nLst
=
(
code
&
(
0xFF
&
~
nm
))
<<
(
8
-
(
2
*
mask
));
nLst
=
(
code
&
(
0xFF
&
~
nm
))
<<
(
8
-
(
2
*
mask
));
(
mask
!=
3
)
?
data_
out
[
iterate_data_buffer
++
]
=
nNum
:
nNum
;
(
mask
!=
3
)
?
out
[
iterate_data_buffer
++
]
=
nNum
:
nNum
;
(
mask
==
0
)
?
mask
=
3
:
mask
--
;
(
mask
==
0
)
?
mask
=
3
:
mask
--
;
}
}
if
(
code
==
BASE64_EQUALS
)
{
if
(
code
==
BASE64_EQUALS
)
{
/* add the last character to the data_out buffer */
/* add the last character to the data_out buffer */
data_
out
[
iterate_data_buffer
]
=
nNum
;
out
[
iterate_data_buffer
]
=
nNum
;
}
}
*
data_out_size
=
iterate_data_buffer
;
*
data_out_size
=
iterate_data_buffer
;
...
...
This diff is collapsed.
Click to expand it.
sys/include/base64.h
+
3
−
3
View file @
12729d62
...
@@ -50,7 +50,7 @@ extern "C" {
...
@@ -50,7 +50,7 @@ extern "C" {
BASE64_ERROR_DATA_IN if `data_in` equals NULL,
BASE64_ERROR_DATA_IN if `data_in` equals NULL,
BASE64_ERROR_DATA_IN_SIZE if `data_in_size` is less then 1.
BASE64_ERROR_DATA_IN_SIZE if `data_in_size` is less then 1.
*/
*/
int
base64_encode
(
unsigned
char
*
data_in
,
size_t
data_in_size
,
\
int
base64_encode
(
const
void
*
data_in
,
size_t
data_in_size
,
unsigned
char
*
base64_out
,
size_t
*
base64_out_size
);
unsigned
char
*
base64_out
,
size_t
*
base64_out_size
);
/**
/**
...
@@ -71,8 +71,8 @@ int base64_encode(unsigned char *data_in, size_t data_in_size, \
...
@@ -71,8 +71,8 @@ int base64_encode(unsigned char *data_in, size_t data_in_size, \
BASE64_ERROR_DATA_IN if `base64_in` equals NULL,
BASE64_ERROR_DATA_IN if `base64_in` equals NULL,
BASE64_ERROR_DATA_IN_SIZE if `base64_in_size` is less then 4.
BASE64_ERROR_DATA_IN_SIZE if `base64_in_size` is less then 4.
*/
*/
int
base64_decode
(
unsigned
char
*
base64_in
,
size_t
base64_in_size
,
\
int
base64_decode
(
const
unsigned
char
*
base64_in
,
size_t
base64_in_size
,
unsigned
char
*
data_out
,
size_t
*
data_out_size
);
void
*
data_out
,
size_t
*
data_out_size
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment