[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] ltn12ce - An all-in-one compression and encryption library for Lua
- From: Michal Kottman <k0mpjut0r@...>
- Date: Wed, 2 Jan 2013 01:30:40 +0100
Hello,
for anyone interested (and as my birthday present from me to the community), I have just uploaded a new compression and encryption/digest library [1], which I call ltn12ce for now.
The main motivation for creating this module was to provide all-in-one functionality in one module without any external dependencies, and with a common API. This module contains the following modules: bzip2, miniLZO, LZMA, PolarSSL (for encryption/hashing) and zlib. I translated all systems to CMake, so it should be relatively portable (Windows, Linux, Mac OS X).
The API tries to adhere to the "filter" [2] standard to be usable by LuaSocket LTN12 module [3]. The Lua side of the API is not ready yet, but all the filters are ready and usable. The existing API is object-based (a filter is an object with update() and finish() methods), and will be wrapped in a function-interface as described in [2] in the next release of the library.
My use-case for this library is testing a custom web API that sends JSON documents, which are sent compressed and encrypted. This module is designed to be plugged in with LuaSocket, so that all I have to do in Lua to access the data is:
local ltn12 = require 'ltn12'
local ce = require 'ltn12ce'
local filter = ltn12.filter.chain(ce.decrypt('aes', key), ce.decompress('zlib'))
local result = {}
http.request { url = "" sink = ltn12.sink.chain(filter, ltn12.sink.table(result) }
For an example of what works now: to compress and encrypt a string, you can do this:
local core = require 'ltn12ce.core'
function runthrough(filter, data)
return filter:update(data) .. filter:finish()
end
function makekey(key, bits)
return key .. string.rep('0', bits/8 - #key)
end
local compressor = core.zlib('compress', 9)
local encrypter = core.cipher('aes-256-cbc')
encrypter:setkey(makekey('12345678', 256), 'encrypt')
local input = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
local compressed = runthrough(compressor, input)
local output = runthrough(encrypter, compressed)
Regarding the name of the library - I searching for a nicer name for the library than the current ltn12ce (as in "LTN12-based Compression and Encryption"), and I am really thinking about changing it. I would be grateful for any ideas - something which represents the nature of the module (I was thinking about "binary-filters"), is searchable on Google (bad example: "go" programming language) and not already used...
Also, any feedback regarding the library and it's design/usability is more than welcome.
Have a happy and productive year 2013 :)