diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-12-03 15:17:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-08 16:26:20 +0100 |
commit | 1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch) | |
tree | 35e16f100466e4e00657199b38bb3d87d52bf73f /libs/luci-lib-px5g/lua/px5g/util.lua | |
parent | 9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff) |
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names
* Make each LuCI module its own standalone package
* Deploy a shared luci.mk which is used by each module Makefile
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'libs/luci-lib-px5g/lua/px5g/util.lua')
-rw-r--r-- | libs/luci-lib-px5g/lua/px5g/util.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libs/luci-lib-px5g/lua/px5g/util.lua b/libs/luci-lib-px5g/lua/px5g/util.lua new file mode 100644 index 000000000..0f07c81b8 --- /dev/null +++ b/libs/luci-lib-px5g/lua/px5g/util.lua @@ -0,0 +1,44 @@ +--[[ + * px5g - Embedded x509 key and certificate generator based on PolarSSL + * + * Copyright (C) 2009 Steven Barth <steven@midlink.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License, version 2.1 as published by the Free Software Foundation. +]]-- + +local nixio = require "nixio" +local table = require "table" + +module "px5g.util" + +local preamble = { + key = "-----BEGIN RSA PRIVATE KEY-----", + cert = "-----BEGIN CERTIFICATE-----", + request = "-----BEGIN CERTIFICATE REQUEST-----" +} + +local postamble = { + key = "-----END RSA PRIVATE KEY-----", + cert = "-----END CERTIFICATE-----", + request = "-----END CERTIFICATE REQUEST-----" +} + +function der2pem(data, type) + local b64 = nixio.bin.b64encode(data) + + local outdata = {preamble[type]} + for i = 1, #b64, 64 do + outdata[#outdata + 1] = b64:sub(i, i + 63) + end + outdata[#outdata + 1] = postamble[type] + outdata[#outdata + 1] = "" + + return table.concat(outdata, "\n") +end + +function pem2der(data) + local b64 = data:gsub({["\n"] = "", ["%-%-%-%-%-.-%-%-%-%-%-"] = ""}) + return nixio.bin.b64decode(b64) +end
\ No newline at end of file |