Commit fcaa206bdc38744fefb5c7ae78e4f1b9834b1fc9
Make encoded text look more like original
cel committed on 2/13/2017, 8:21:36 PMParent: b367f8b1c9614eaade917b7e2ea66387fdddbf8a
Files changed
lib/encode.js | changed |
test/index.js | changed |
test/networks.txt | changed |
lib/encode.js | |||
---|---|---|---|
@@ -20,8 +20,9 @@ | |||
20 | 20 … | pcsc: encodeQuotedString, | |
21 | 21 … | pin: encodeQuotedString, | |
22 | 22 … | private_key: encodeQuotedString, | |
23 | 23 … | private_key_passwd: encodeQuotedString, | |
24 … | + ssid: encodeQuotedString, | ||
24 | 25 … | psk: function (value) { | |
25 | 26 … | if (/[0-9a-f]{40}/i.test(value)) return value | |
26 | 27 … | else return encodeQuotedString(value) | |
27 | 28 … | }, | |
@@ -49,31 +50,22 @@ | |||
49 | 50 … | } | |
50 | 51 … | ||
51 | 52 … | module.exports = function encodeConfig(conf) { | |
52 | 53 … | 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 … | + } | ||
75 | 60 … | } | |
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') | ||
76 | 68 … | } | |
77 | 69 … | ||
78 | 70 … | function encodeNetwork(network) { | |
79 | 71 … | if (!network) return |
test/index.js | ||
---|---|---|
@@ -12,8 +12,7 @@ | ||
12 | 12 … | t.end() |
13 | 13 … | }) |
14 | 14 … | |
15 | 15 … | test('encode', function (t) { |
16 | - var txt = wpa.encode(networksObj) | |
17 | - t.deepEquals(wpa.decode(txt), networksObj) | |
16 … | + t.deepEquals(wpa.encode(networksObj), networksTxt) | |
18 | 17 … | t.end() |
19 | 18 … | }) |
test/networks.txt | ||
---|---|---|
@@ -1,31 +1,25 @@ | ||
1 | 1 … | 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 | |
8 | 2 … | ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel |
9 | 3 … | |
10 | 4 … | # home network; allow all valid ciphers |
11 | 5 … | 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" | |
16 | 10 … | } |
17 | 11 … | |
18 | 12 … | # work network; use EAP-TLS with WPA; allow only CCMP and TKIP ciphers |
19 | 13 … | 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" | |
31 | 25 … | } |
Built with git-ssb-web