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
287ca6ec
Commit
287ca6ec
authored
Jan 15, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first implementation of base64_decode()
parent
edca76e2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
2 deletions
+78
-2
base64.c
src/base64.c
+60
-1
base64.vtc
src/tests/base64.vtc
+11
-0
vmod_convert.c
src/vmod_convert.c
+6
-1
vmod_convert.h
src/vmod_convert.h
+1
-0
No files found.
src/base64.c
View file @
287ca6ec
...
...
@@ -26,10 +26,11 @@
*
*/
#include <
stdi
o.h>
#include <
errn
o.h>
#include "vmod_convert.h"
#include "vrt.h"
#include "vas.h"
struct
b64_state_s
{
...
...
@@ -59,6 +60,21 @@ alpha_init(struct b64_alphabet *alpha)
alpha
->
i64
[
alpha
->
padding
]
=
0
;
}
static
inline
int
decode3
(
char
*
restrict
*
restrict
dest
,
char
*
restrict
const
buf
,
const
size_t
maxlen
,
unsigned
u
)
{
char
*
d
=
*
dest
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
if
(
d
==
buf
+
maxlen
)
return
-
1
;
*
d
++
=
(
u
>>
16
)
&
0xff
;
u
<<=
8
;
}
*
dest
+=
d
-
*
dest
;
return
1
;
}
void
base64_init
(
void
)
{
...
...
@@ -160,3 +176,46 @@ base64_encode(const enum encoding enc, char *restrict const buf,
assert
(
outlen
>
0
);
return
p
-
buf
;
}
ssize_t
base64_decode
(
const
enum
encoding
dec
,
char
*
restrict
const
buf
,
const
size_t
maxlen
,
const
char
*
restrict
const
p
,
va_list
ap
)
{
struct
b64_alphabet
*
alpha
=
&
b64_alphabet
[
dec
];
const
char
*
s
;
char
*
dest
=
buf
;
unsigned
u
=
0
;
int
n
;
AN
(
buf
);
for
(
s
=
p
;
s
!=
vrt_magic_string_end
;
s
=
va_arg
(
ap
,
const
char
*
))
{
if
(
s
==
NULL
)
continue
;
while
(
*
s
)
{
for
(
n
=
0
;
n
<
4
;
n
++
)
{
char
b
=
alpha
->
i64
[(
unsigned
)
*
s
++
];
if
(
b
<
0
)
{
errno
=
EINVAL
;
return
-
1
;
}
u
<<=
6
;
u
|=
(
unsigned
)
b
;
if
(
!*
s
)
break
;
}
if
(
n
==
4
)
if
(
decode3
(
&
dest
,
buf
,
maxlen
,
u
)
<
0
)
{
errno
=
ENOMEM
;
return
-
1
;
}
}
}
if
(
n
!=
4
)
if
(
decode3
(
&
dest
,
buf
,
maxlen
,
u
)
<
0
)
{
errno
=
ENOMEM
;
return
-
1
;
}
return
dest
-
buf
;
}
src/tests/base64.vtc
View file @
287ca6ec
...
...
@@ -35,6 +35,15 @@ varnish v1 -vcl+backend {
set
resp
.
http
.
b64urlnopadxcode
=
convert
.
transcode
(
IDENTITY
,
BASE64URLNOPAD
,
req
.
url
+
"Hello world"
+
req
.
url
);
set
resp
.
http
.
dec
=
convert
.
encode
(
IDENTITY
,
convert
.
decode
(
BASE64
,
"L0hlbGxvIHdvcmxkLw=="
));
set
resp
.
http
.
dec2
=
convert
.
encode
(
IDENTITY
,
convert
.
decode
(
BASE64
,
"VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=="
));
}
}
-
start
...
...
@@ -47,6 +56,8 @@ client c1 {
expect
resp
.
http
.
b64xcode
==
"L0hlbGxvIHdvcmxkLw=="
expect
resp
.
http
.
b64urlxcode
==
"L0hlbGxvIHdvcmxkLw=="
expect
resp
.
http
.
b64urlnopadxcode
==
"L0hlbGxvIHdvcmxkLw"
expect
resp
.
http
.
dec
==
"/Hello world/"
expect
resp
.
http
.
dec2
==
"The quick brown fox jumps over the lazy dog"
}
client
c1
-
run
src/vmod_convert.c
View file @
287ca6ec
...
...
@@ -116,6 +116,10 @@ decode(const enum encoding dec, char *restrict const buf,
switch
(
dec
)
{
case
IDENTITY
:
return
id_decode
(
dec
,
buf
,
maxlen
,
p
,
ap
);
case
BASE64
:
case
BASE64URL
:
case
BASE64URLNOPAD
:
return
base64_decode
(
dec
,
buf
,
maxlen
,
p
,
ap
);
case
HEX
:
return
hex_decode
(
dec
,
buf
,
maxlen
,
p
,
ap
);
default:
...
...
@@ -206,7 +210,8 @@ vmod_encode(VRT_CTX, VCL_ENUM encs, VCL_BLOB b) {
ssize_t
len
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
AN
(
b
);
if
(
b
==
NULL
)
return
NULL
;
if
(
wb_create
(
ctx
->
ws
,
&
wb
)
==
NULL
)
return
NULL
;
...
...
src/vmod_convert.h
View file @
287ca6ec
...
...
@@ -107,6 +107,7 @@ decode_f id_decode;
/* base64.c */
void
base64_init
(
void
);
encode_f
base64_encode
;
decode_f
base64_decode
;
/* hex.c */
encode_f
hex_encode
;
...
...
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