Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Steve Lhomme
VLC
Commits
64f01804
Commit
64f01804
authored
Aug 30, 2006
by
Rémi Denis-Courmont
Browse files
*Really* fix base 64 encoding
parent
f8343052
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/vlc_url.h
View file @
64f01804
...
...
@@ -222,6 +222,7 @@ static inline char *vlc_b64_encode( const char *src )
static
const
char
b64
[]
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
size_t
len
=
strlen
(
src
);
const
uint8_t
*
in
=
(
const
uint8_t
*
)
src
;
char
*
ret
;
char
*
dst
=
(
char
*
)
malloc
(
(
len
+
4
)
*
4
/
3
);
...
...
@@ -233,17 +234,17 @@ static inline char *vlc_b64_encode( const char *src )
while
(
len
>
0
)
{
/* pops (up to) 3 bytes of input, push 4 bytes */
uint32_t
v
=
*
src
++
<<
24
;
// 1/3
uint32_t
v
=
*
in
++
<<
24
;
// 1/3
*
dst
++
=
b64
[
v
>>
26
];
// 1/4
v
=
v
<<
6
;
if
(
len
>=
2
)
v
|=
*
src
++
<<
16
;
// 2/3
v
|=
*
in
++
<<
22
;
// 2/3
*
dst
++
=
b64
[
v
>>
26
];
// 2/4
v
=
v
<<
6
;
if
(
len
>=
3
)
v
|=
*
src
++
<<
8
;
// 3/3
v
|=
*
in
++
<<
20
;
// 3/3
*
dst
++
=
(
len
>=
2
)
?
b64
[
v
>>
26
]
:
'='
;
// 3/4
v
=
v
<<
6
;
...
...
src/test/url.c
View file @
64f01804
...
...
@@ -82,9 +82,9 @@ int main (void)
/* Base 64 tests */
test_b64
(
""
,
""
);
test_b64
(
"d"
,
"ZA=="
);
test_b64
(
"ab"
,
"Y
QG
="
);
test_b64
(
"abc"
,
"Y
QGI
"
);
test_b64
(
"abcd"
,
"Y
QGI
ZA=="
);
test_b64
(
"ab"
,
"Y
WI
="
);
test_b64
(
"abc"
,
"Y
WJj
"
);
test_b64
(
"abcd"
,
"Y
WJj
ZA=="
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment