vmod_blob / vmod_blobobj for encoding/decoding to/from blobs?
Nils Goroll
slink at schokola.de
Wed Jun 17 14:42:17 CEST 2015
Hi,
after some discussion with dridi and martin at uplex this is what I have in
http://etherpad.wikimedia.org/p/libvmod_code.vcc now:
- vmod_convert as a functional interface with nmemonic short function names for
the common use cases
- vmod_blob for converting to/from blob objects oo-style
comments are still welcome.
= CURRENT DRAFT =
== Formats to support ==
(L) is for (L)ater
=== encode + decode formats ===
* IDENTITY / STRING
* BASE64
** for encode, defaults to BASE64 (no padding)
** for decode, accept BASE64URL tolerates missing padding at end of string
* URL
** as in vmod_urlcode
* HEX
** for encode, default to HEXLC
** for decode, accept any
* ROT13 (L)
* H2HUFF (L) (http/2 HPACK huffman table)
=== additional encode formats ===
* BASE64URL : encode: +/ replaced by -_, no padding
* BASE64URLPAD: same with padding (exotic)
* HEXLC (same as HEX)
* HEXUC (upcase)
== vmod_convert : functional interface ==
$Module convert 3 convert to/from different encodings
// common use cases
// b->s
$Function STRING encode(ENUM { IDENTITY, BASE64, HEXLC, ... }, BLOB)
// s->b
$Function BLOB decode(ENUM { IDENTITY, BASE64, HEX, ... }, STRING_LIST)
// s->s
$Function STRING transcode(ENUM { IDENTITY, BASE64, HEX, ... }, ENUM { IDENTITY,
BASE64, HEXLC, ... }, STRING_LIST)
// EXOTIC use case b->b
$Function BLOB transcode_blob(ENUM { IDENTITY, BASE64, HEX, ... }, ENUM {
IDENTITY, BASE64, HEXLC, ... }, BLOB)
# example
sub vcl_recv {
set req.http.x-hash = convert.encode(BASE64, digest4.hash(MD5,
convert.decode(HEX, "0x123abcdef", "ffaacc11")));
// inefficient, but just an example
if (req.http.Authentication != "Basic " + convert.transcode(IDENTITY,
BASE64, "user:passwort")) {
return (synth(403));
}
}
== vmod blob : oo-interface for handling blob objects with encode/decode ==
$Module blob 3 Blob objects
// create a const object which cannot be set/apppended to - PRIV_VCL scope
$Object const(ENUM { IDENTITY, BASE64, HEXLC, ... }, STRING_LIST)
// create a blob variable object - PRIV_TASK scope
$Object var()
$Method BLOB get()
$Method VOID set(BLOB)
$Method VOID append(BLOB)
$Method BLOB splice(BLOB, INT, INT)
$Method VOID from(ENUM { IDENTITY, BASE64, HEX, ... }, STRING_LIST)
$Method STRING encode(ENUM { IDENTITY, BASE64, HEX, ... })
vcl_init {
new constblob = blob.const(BASE64, "V2VkIDE3IEp1biAxMTozNjoxNCBDRVNUIDIwMTUK");
new myhash = blob.var();
new myhmac = blob.var();
}
vcl_recv {
myhash.set(digest4.hash(SHA256, convert.decode(HEX, "0xabcdef")));
set req.http.x-out = myhash.encode(BASE64);
myhmac.set(digest4.hmac(SHA256, constblob.get(), myhash.get()));
}
More information about the varnish-dev
mailing list