git ssb

1+

cel / wpa-conf-codec



Commit fcaa206bdc38744fefb5c7ae78e4f1b9834b1fc9

Make encoded text look more like original

cel committed on 2/13/2017, 8:21:36 PM
Parent: b367f8b1c9614eaade917b7e2ea66387fdddbf8a

Files changed

lib/encode.jschanged
test/index.jschanged
test/networks.txtchanged
lib/encode.jsView
@@ -20,8 +20,9 @@
2020 pcsc: encodeQuotedString,
2121 pin: encodeQuotedString,
2222 private_key: encodeQuotedString,
2323 private_key_passwd: encodeQuotedString,
24 + ssid: encodeQuotedString,
2425 psk: function (value) {
2526 if (/[0-9a-f]{40}/i.test(value)) return value
2627 else return encodeQuotedString(value)
2728 },
@@ -49,31 +50,22 @@
4950 }
5051
5152 module.exports = function encodeConfig(conf) {
5253 if (!conf) return ''
53- switch (typeof conf) {
54- case 'object':
55- var lines = []
56- for (var k in conf) {
57- var value = conf[k]
58- if (k === 'networks' && Array.isArray(value)) {
59- value.forEach(function (network) {
60- lines.push('', encodeNetwork(network))
61- })
62- } else {
63- lines.push(encodeProperty(k, value))
64- }
65- }
66- return lines.join('\n')
67- case 'string':
68- // fallthrough
69- case 'number':
70- return JSON.stringify(conf)
71- case 'boolean':
72- return conf ? '1' : '0'
73- default:
74- throw new Error("weird value: " + conf)
54 + var lines = []
55 + for (var k in conf) {
56 + var value = conf[k]
57 + if (k !== 'networks') {
58 + lines.push(encodeProperty(k, value))
59 + }
7560 }
61 + if (Array.isArray(conf.networks)) {
62 + lines.push('')
63 + conf.networks.forEach(function (network) {
64 + lines.push(encodeNetwork(network), '')
65 + })
66 + }
67 + return lines.join('\n')
7668 }
7769
7870 function encodeNetwork(network) {
7971 if (!network) return
test/index.jsView
@@ -12,8 +12,7 @@
1212 t.end()
1313 })
1414
1515 test('encode', function (t) {
16- var txt = wpa.encode(networksObj)
17- t.deepEquals(wpa.decode(txt), networksObj)
16 + t.deepEquals(wpa.encode(networksObj), networksTxt)
1817 t.end()
1918 })
test/networks.txtView
@@ -1,31 +1,25 @@
11 fast_reauth=1
2-
3-# 1. WPA-Personal (PSK) as home network and WPA-Enterprise with EAP-TLS
4-# as work network.
5-
6-
7-# allow frontend (e.g., wpa_cli) to be used by all users in 'wheel' group
82 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
93
104 # home network; allow all valid ciphers
115 network={
12- ssid="home"
13- scan_ssid=1
14- key_mgmt=WPA-PSK
15- psk="very secret passphrase"
6 + ssid="home"
7 + scan_ssid=1
8 + key_mgmt=WPA-PSK
9 + psk="very secret passphrase"
1610 }
1711
1812 # work network; use EAP-TLS with WPA; allow only CCMP and TKIP ciphers
1913 network={
20- ssid="work"
21- scan_ssid=1
22- key_mgmt=WPA-EAP
23- pairwise=CCMP TKIP
24- group=CCMP TKIP
25- eap=TLS
26- identity="user@example.com"
27- ca_cert="/etc/cert/ca.pem"
28- client_cert="/etc/cert/user.pem"
29- private_key="/etc/cert/user.prv"
30- private_key_passwd="password"
14 + ssid="work"
15 + scan_ssid=1
16 + key_mgmt=WPA-EAP
17 + pairwise=CCMP TKIP
18 + group=CCMP TKIP
19 + eap=TLS
20 + identity="user@example.com"
21 + ca_cert="/etc/cert/ca.pem"
22 + client_cert="/etc/cert/user.pem"
23 + private_key="/etc/cert/user.prv"
24 + private_key_passwd="password"
3125 }

Built with git-ssb-web