Skip to content

Instantly share code, notes, and snippets.

#include "thirdparty/glog/logging.h"
#include <string.h>
namespace chaoaero
{
// ecb mode with no padding
// no need to append '\0' when the length of input text is not multiple of the block size
Aes128::Aes128(const std::string& key_data)
{
int key_len = key_data.size();
-- Copyright (C) Weichao Meng (chaoaero)
--
-- This library is an approximate Lua port of the standard ngx_limit_req using token bucket algorithms.
-- The main idea derives from https://github.com/openresty/lua-resty-limit-traffic
local ffi = require "ffi"
local math = require "math"
@chaoaero
chaoaero / token_bucket_limit_req.lua
Last active October 26, 2015 02:55
This is the token bucket request limitation code snippets based on openresty.
-- People can call this module by the following methods:
[==[
local req = require "path.token_bucket"
local ok = req.limit{ key = ngx.var.remote_addr, zone = "ip",
rate = "2r/s", capacity = 10, log_level = ngx.ERROR,
rds = { host = "127.0.0.1", port = 6379 }}
if not ok then
return ngx.exit(503)
end
]==]
@chaoaero
chaoaero / hmac.lua
Created October 15, 2015 08:47
hmac script that can be used in openresty. This script derives from other people's gist repository while I just fix some bugs.
local ffi = require "ffi"
local ffi_new = ffi.new
local ffi_str = ffi.string
local C = ffi.C
local setmetatable = setmetatable
local error = error
local _M = {_VERSION = '0.01' }