1+ #
2+ # Copyright (c) 2018-2019 Google, LLC.
3+ # All rights reserved.
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+ #
17+
118import os
219import sys
320import re
@@ -70,23 +87,23 @@ def indent(s, indentStr=' '):
7087
7188with open (inFileName , 'r' ) as inFile :
7289 with open (outFileName , 'w' ) as outFile :
73-
90+
7491 outFile .write (preamble );
75-
92+
7693 for line in inFile :
7794 line = line .strip ()
78-
95+
7996 if line == "" :
8097 continue
81-
98+
8299 (macAddr , certificate , privateKey ) = [ x .strip () for x in line .split (',' )[:3 ]]
83100
84101 if macAddr == 'MAC' and certificate == 'Certificate' and privateKey == 'Private Key' :
85102 continue
86103
87104 certificate = base64 .b64decode (certificate )
88105 privateKey = base64 .b64decode (privateKey )
89-
106+
90107 idNum = int (macAddr [- 2 :], 16 )
91108
92109 outFile .write ('''\
@@ -102,9 +119,9 @@ def indent(s, indentStr=' '):
102119const uint8_t TestDeviceCert[] =
103120{
104121''' % (macAddr ))
105-
122+
106123 outFile .write (indent (toArrayInit (certificate ).strip ()))
107-
124+
108125 outFile .write ('''
109126};
110127
@@ -113,12 +130,12 @@ def indent(s, indentStr=' '):
113130''' )
114131
115132 outFile .write (indent (toArrayInit (privateKey ).strip ()))
116-
133+
117134 outFile .write ('''
118135};
119136
120137''' )
121-
138+
122139 outFile .write ('''\
123140 #endif // WEAVE_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY == %d
124141''' % (idNum ))
0 commit comments