Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
64874cf7
Commit
64874cf7
authored
Aug 30, 2006
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix base64 encoding and add regression test
parent
ac52d273
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
29 deletions
+42
-29
include/vlc_url.h
include/vlc_url.h
+18
-27
src/test/url.c
src/test/url.c
+24
-2
No files found.
include/vlc_url.h
View file @
64874cf7
...
...
@@ -217,7 +217,7 @@ static inline int vlc_UrlIsNotEncoded( const char *psz_url )
*****************************************************************************
*
*****************************************************************************/
static
inline
char
*
vlc_b64_encode
(
char
*
src
)
static
inline
char
*
vlc_b64_encode
(
c
onst
c
har
*
src
)
{
static
const
char
b64
[]
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
...
...
@@ -232,38 +232,29 @@ static inline char *vlc_b64_encode( char *src )
while
(
len
>
0
)
{
/* pops (up to) 3 bytes of input */
uint32_t
v
=
*
src
++
<<
24
;
/* pops (up to) 3 bytes of input, push 4 bytes */
uint32_t
v
=
*
src
++
<<
24
;
// 1/3
*
dst
++
=
b64
[
v
>>
26
];
// 1/4
v
=
v
<<
6
;
if
(
len
>=
2
)
{
v
|=
*
src
++
<<
16
;
if
(
len
>=
3
)
v
|=
*
src
++
<<
8
;
}
v
|=
*
src
++
<<
16
;
// 2/3
*
dst
++
=
b64
[
v
>>
26
];
// 2/4
v
=
v
<<
6
;
/* pushes (up to) 4 bytes of output */
while
(
v
)
{
*
dst
++
=
b64
[
v
>>
26
];
if
(
len
>=
3
)
v
|=
*
src
++
<<
8
;
// 3/3
*
dst
++
=
(
len
>=
2
)
?
b64
[
v
>>
26
]
:
'='
;
// 3/4
v
=
v
<<
6
;
}
switch
(
len
)
*
dst
++
=
(
len
>=
3
)
?
b64
[
v
>>
26
]
:
'='
;
// 4/4
len
--
;
if
(
len
>
0
)
{
case
1
:
*
dst
++
=
'='
;
*
dst
++
=
'='
;
len
--
;
break
;
case
2
:
*
dst
++
=
'='
;
len
-=
2
;
break
;
default:
len
-=
3
;
if
(
len
>
0
)
len
--
;
}
}
...
...
src/test/url.c
View file @
64874cf7
...
...
@@ -25,21 +25,36 @@
#include <stdio.h>
#include <stdlib.h>
void
test_decode
(
const
char
*
in
,
const
char
*
out
)
typedef
char
*
(
*
conv_t
)
(
const
char
*
);
static
void
test
(
conv_t
f
,
const
char
*
in
,
const
char
*
out
)
{
char
*
res
;
printf
(
"
\"
%s
\"
->
\"
%s
\"
?
\n
"
,
in
,
out
);
res
=
decode_URI_duplicate
(
in
);
res
=
f
(
in
);
if
(
res
==
NULL
)
exit
(
1
);
if
(
strcmp
(
res
,
out
))
{
printf
(
" ERROR: got
\"
%s
\"\n
"
,
res
);
exit
(
2
);
}
free
(
res
);
}
static
inline
void
test_decode
(
const
char
*
in
,
const
char
*
out
)
{
test
(
decode_URI_duplicate
,
in
,
out
);
}
static
inline
void
test_b64
(
const
char
*
in
,
const
char
*
out
)
{
test
(
vlc_b64_encode
,
in
,
out
);
}
int
main
(
void
)
{
(
void
)
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
...
...
@@ -64,5 +79,12 @@ int main (void)
test_decode
(
"T%E9l%E9vision"
,
"T?l?vision"
);
test_decode
(
"%C1%94%C3%a9l%c3%A9vision"
,
"??élévision"
);
/* overlong */
/* Base 64 tests */
test_b64
(
""
,
""
);
test_b64
(
"d"
,
"ZA=="
);
test_b64
(
"ab"
,
"YQG="
);
test_b64
(
"abc"
,
"YQGI"
);
test_b64
(
"abcd"
,
"YQGIZA=="
);
return
0
;
}
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