Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-blobcode
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-blobcode
Commits
1dcce458
Commit
1dcce458
authored
Feb 08, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify base64_encode()
parent
38346b3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
25 deletions
+22
-25
base64.c
src/base64.c
+22
-25
No files found.
src/base64.c
View file @
1dcce458
...
...
@@ -61,6 +61,7 @@ base64_encode(const enum encoding enc, char *restrict const buf,
const
struct
b64_alphabet
*
alpha
=
&
b64_alphabet
[
enc
];
char
*
p
=
buf
;
const
uint8_t
*
in
=
(
uint8_t
*
)
inbuf
;
const
uint8_t
*
const
end
=
in
+
inlength
;
AN
(
buf
);
AN
(
alpha
);
...
...
@@ -70,34 +71,30 @@ base64_encode(const enum encoding enc, char *restrict const buf,
||
maxlen
<
base64nopad_encode_l
(
inlength
))
return
-
1
;
while
(
in
<
(
uint8_t
*
)
inbuf
+
inlength
)
{
uint8_t
idx
;
size_t
rest
=
((
uint8_t
*
)
inbuf
+
inlength
)
-
in
;
while
(
end
-
in
>=
3
)
{
*
p
++
=
alpha
->
b64
[(
in
[
0
]
>>
2
)
&
0x3f
];
idx
=
(
in
[
0
]
<<
4
);
if
(
rest
>
1
)
idx
+=
(
in
[
1
]
>>
4
);
*
p
++
=
alpha
->
b64
[
idx
&
0x3f
];
if
(
rest
>
1
)
{
idx
=
(
in
[
1
]
<<
2
);
if
(
rest
>
2
)
idx
+=
in
[
2
]
>>
6
;
*
p
++
=
alpha
->
b64
[
idx
&
0x3f
];
}
else
if
(
alpha
->
padding
)
*
p
++
=
alpha
->
padding
;
if
(
rest
>
2
)
*
p
++
=
alpha
->
b64
[
in
[
2
]
&
0x3f
];
else
if
(
alpha
->
padding
)
*
p
++
=
alpha
->
padding
;
*
p
++
=
alpha
->
b64
[((
in
[
0
]
<<
4
)
|
(
in
[
1
]
>>
4
))
&
0x3f
];
*
p
++
=
alpha
->
b64
[((
in
[
1
]
<<
2
)
|
(
in
[
2
]
>>
6
))
&
0x3f
];
*
p
++
=
alpha
->
b64
[
in
[
2
]
&
0x3f
];
in
+=
3
;
}
if
(
end
-
in
>
0
)
{
*
p
++
=
alpha
->
b64
[(
in
[
0
]
>>
2
)
&
0x3f
];
if
(
end
-
in
==
1
)
{
*
p
++
=
alpha
->
b64
[(
in
[
0
]
<<
4
)
&
0x3f
];
if
(
alpha
->
padding
)
{
*
p
++
=
alpha
->
padding
;
*
p
++
=
alpha
->
padding
;
}
}
else
{
*
p
++
=
alpha
->
b64
[((
in
[
0
]
<<
4
)
|
(
in
[
1
]
>>
4
))
&
0x3f
];
*
p
++
=
alpha
->
b64
[(
in
[
1
]
<<
2
)
&
0x3f
];
if
(
alpha
->
padding
)
{
*
p
++
=
alpha
->
padding
;
}
}
}
assert
(
p
>=
buf
&&
p
-
buf
<=
maxlen
);
return
p
-
buf
;
}
...
...
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