Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-blobsha256
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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-blobsha256
Commits
fcb3c398
Commit
fcb3c398
authored
Apr 15, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add the blob object interface
parent
1d06f969
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
10 deletions
+118
-10
README.rst
README.rst
+37
-4
vmod_blobsha256.c
src/vmod_blobsha256.c
+56
-2
vmod_blobsha256.vcc
src/vmod_blobsha256.vcc
+25
-4
No files found.
README.rst
View file @
fcb3c398
...
...
@@ -27,6 +27,8 @@ import blobsha256 [from "path"] ;
CONTENTS
========
* Object blob
* BLOB blob.hash()
* BLOB hash(BLOB)
* Object hmac
* BLOB hmac.hmac(BLOB)
...
...
@@ -46,8 +48,8 @@ Description
given ``key``.
Example
``new key = blobcode.blob(BASE64, "a2V5");``
``new hmac = blobsha256.hmac(key.get());``
new key = blobcode.blob(BASE64, "a2V5");
new hmac = blobsha256.hmac(key.get());
.. _func_hmac.hmac:
...
...
@@ -62,7 +64,38 @@ Description
``msg`` based on the key provided in the constructor.
Example
``set req.http.hmac = hmac.hmac(blobcode.decode(BASE64, "Zm9v"));``
set req.http.hmac = hmac.hmac(blobcode.decode(BASE64, "Zm9v"));
.. _obj_blob:
Object blob
===========
Prototype
new OBJ = blobsha256.blob(BLOB blob)
Description
Creates an object that returns the SHA256 digest of the given
``blob``.
Example
new key = blobcode.blob(BASE64, "Zm9v");
new foo = blobsha256.blob(key.get());
.. _func_blob.hash:
BLOB blob.hash()
----------------
Prototype
BLOB blob.hash()
Description
Returns the SHA256 digest for the blob given in the constructor.
Example
set req.http.X-Hash = blobcode.encode(BASE64, foo.hash());
.. _func_hash:
...
...
@@ -87,4 +120,4 @@ Description
Returns the version string for this VMOD.
Example
``std.log("Using VMOD blobsha256 version " + blobsha256.version());``
std.log("Using VMOD blobsha256 version " + blobsha256.version());
src/vmod_blobsha256.c
View file @
fcb3c398
...
...
@@ -60,6 +60,12 @@ struct vmod_blobsha256_hmac {
SHA256_CTX
outer_ctx
;
};
struct
vmod_blobsha256_blob
{
unsigned
magic
;
#define VMOD_BLOBSHA256_BLOB_MAGIC 0x2067c219
struct
vmod_priv
hash
;
};
static
void
errmsg
(
VRT_CTX
,
const
char
*
fmt
,
...)
{
...
...
@@ -88,7 +94,7 @@ digest(SHA256_CTX *restrict const ctx, VCL_BLOB restrict const b,
SHA256_Final
(
digest
,
ctx
);
}
/* Object
s
*/
/* Object
hmac
*/
VCL_VOID
vmod_hmac__init
(
VRT_CTX
,
struct
vmod_blobsha256_hmac
**
hmacp
,
...
...
@@ -128,6 +134,7 @@ vmod_hmac_hmac(VRT_CTX, struct vmod_blobsha256_hmac *h, VCL_BLOB msg)
struct
vmod_priv
*
b
;
char
*
snap
;
SHA256_CTX
inner_ctx
,
outer_ctx
;
uint8_t
inner_digest
[
SHA256_LEN
];
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
h
,
VMOD_BLOBSHA256_HMAC_MAGIC
);
...
...
@@ -146,7 +153,6 @@ vmod_hmac_hmac(VRT_CTX, struct vmod_blobsha256_hmac *h, VCL_BLOB msg)
b
->
len
=
SHA256_LEN
;
b
->
free
=
NULL
;
uint8_t
inner_digest
[
SHA256_LEN
];
memcpy
(
&
inner_ctx
,
&
h
->
inner_ctx
,
sizeof
(
SHA256_CTX
));
memcpy
(
&
outer_ctx
,
&
h
->
outer_ctx
,
sizeof
(
SHA256_CTX
));
...
...
@@ -172,6 +178,54 @@ vmod_hmac__fini(struct vmod_blobsha256_hmac **hmacp)
FREE_OBJ
(
hmac
);
}
/* Object blob */
VCL_VOID
vmod_blob__init
(
VRT_CTX
,
struct
vmod_blobsha256_blob
**
blobp
,
const
char
*
vcl_name
,
VCL_BLOB
b
)
{
struct
vmod_blobsha256_blob
*
blob
;
SHA256_CTX
hctx
[
1
];
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
AN
(
blobp
);
AZ
(
*
blobp
);
AN
(
vcl_name
);
ALLOC_OBJ
(
blob
,
VMOD_BLOBSHA256_BLOB_MAGIC
);
AN
(
blob
);
*
blobp
=
blob
;
blob
->
hash
.
priv
=
malloc
(
SHA256_LEN
);
if
(
blob
->
hash
.
priv
==
NULL
)
{
ERRNOMEM
(
ctx
,
"allocating hash in blob constructor"
);
return
;
}
blob
->
hash
.
len
=
SHA256_LEN
;
blob
->
hash
.
free
=
NULL
;
digest
(
hctx
,
b
,
blob
->
hash
.
priv
);
}
VCL_BLOB
vmod_blob_hash
(
VRT_CTX
,
struct
vmod_blobsha256_blob
*
blob
)
{
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
blob
,
VMOD_BLOBSHA256_BLOB_MAGIC
);
return
&
blob
->
hash
;
}
VCL_VOID
vmod_blob__fini
(
struct
vmod_blobsha256_blob
**
blobp
)
{
struct
vmod_blobsha256_blob
*
blob
;
AN
(
*
blobp
);
blob
=
*
blobp
;
*
blobp
=
NULL
;
CHECK_OBJ_NOTNULL
(
blob
,
VMOD_BLOBSHA256_BLOB_MAGIC
);
FREE_OBJ
(
blob
);
}
/* Functions */
VCL_BLOB
...
...
src/vmod_blobsha256.vcc
View file @
fcb3c398
...
...
@@ -19,8 +19,8 @@ Description
given ``key``.
Example
``new key = blobcode.blob(BASE64, "a2V5");``
``new hmac = blobsha256.hmac(key.get());``
new key = blobcode.blob(BASE64, "a2V5");
new hmac = blobsha256.hmac(key.get());
$Method BLOB .hmac(BLOB msg)
...
...
@@ -29,7 +29,28 @@ Description
``msg`` based on the key provided in the constructor.
Example
``set req.http.hmac = hmac.hmac(blobcode.decode(BASE64, "Zm9v"));``
set req.http.hmac = hmac.hmac(blobcode.decode(BASE64, "Zm9v"));
$Object blob(BLOB blob)
Prototype
new OBJ = blobsha256.blob(BLOB blob)
Description
Creates an object that returns the SHA256 digest of the given
``blob``.
Example
new key = blobcode.blob(BASE64, "Zm9v");
new foo = blobsha256.blob(key.get());
$Method BLOB .hash()
Description
Returns the SHA256 digest for the blob given in the constructor.
Example
set req.http.X-Hash = blobcode.encode(BASE64, foo.hash());
$Function BLOB hash(BLOB msg)
...
...
@@ -42,4 +63,4 @@ Description
Returns the version string for this VMOD.
Example
``std.log("Using VMOD blobsha256 version " + blobsha256.version());``
std.log("Using VMOD blobsha256 version " + blobsha256.version());
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