|
24 | 24 | # TLV encodings (notably the Weave Certificate object). |
25 | 25 | # |
26 | 26 |
|
| 27 | +from __future__ import absolute_import |
| 28 | +from __future__ import print_function |
27 | 29 | import sys |
28 | 30 |
|
29 | 31 | def identity(n): |
@@ -221,126 +223,126 @@ def encodeOID(oid): |
221 | 223 |
|
222 | 224 | return encodedOID |
223 | 225 |
|
224 | | -print "/*" |
225 | | -print " *" |
226 | | -print " * Copyright (c) 2019 Google LLC." |
227 | | -print " * Copyright (c) 2013-2017 Nest Labs, Inc." |
228 | | -print " * All rights reserved." |
229 | | -print " *" |
230 | | -print " * Licensed under the Apache License, Version 2.0 (the \"License\");" |
231 | | -print " * you may not use this file except in compliance with the License." |
232 | | -print " * You may obtain a copy of the License at" |
233 | | -print " *" |
234 | | -print " * http://www.apache.org/licenses/LICENSE-2.0" |
235 | | -print " *" |
236 | | -print " * Unless required by applicable law or agreed to in writing, software" |
237 | | -print " * distributed under the License is distributed on an \"AS IS\" BASIS," |
238 | | -print " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." |
239 | | -print " * See the License for the specific language governing permissions and" |
240 | | -print " * limitations under the License." |
241 | | -print " *" |
242 | | -print " */" |
243 | | -print "" |
244 | | -print "/**" |
245 | | -print " * @file" |
246 | | -print " * ASN.1 Object ID Definitions" |
247 | | -print " *" |
248 | | -print " * !!! WARNING !!! WARNING !!! WARNING !!!" |
249 | | -print " *" |
250 | | -print " * DO NOT EDIT THIS FILE! This file is generated by the" |
251 | | -print " * gen-oid-table.py script." |
252 | | -print " *" |
253 | | -print " * To make changes, edit the script and re-run it to generate" |
254 | | -print " * this file." |
255 | | -print " *" |
256 | | -print " */" |
257 | | -print "" |
258 | | -print "#ifndef ASN1OID_H_" |
259 | | -print "#define ASN1OID_H_" |
260 | | -print "" |
261 | | -print "enum OIDCategory" |
262 | | -print "{" |
| 226 | +print("/*") |
| 227 | +print(" *") |
| 228 | +print(" * Copyright (c) 2019 Google LLC.") |
| 229 | +print(" * Copyright (c) 2013-2017 Nest Labs, Inc.") |
| 230 | +print(" * All rights reserved.") |
| 231 | +print(" *") |
| 232 | +print(" * Licensed under the Apache License, Version 2.0 (the \"License\");") |
| 233 | +print(" * you may not use this file except in compliance with the License.") |
| 234 | +print(" * You may obtain a copy of the License at") |
| 235 | +print(" *") |
| 236 | +print(" * http://www.apache.org/licenses/LICENSE-2.0") |
| 237 | +print(" *") |
| 238 | +print(" * Unless required by applicable law or agreed to in writing, software") |
| 239 | +print(" * distributed under the License is distributed on an \"AS IS\" BASIS,") |
| 240 | +print(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.") |
| 241 | +print(" * See the License for the specific language governing permissions and") |
| 242 | +print(" * limitations under the License.") |
| 243 | +print(" *") |
| 244 | +print(" */") |
| 245 | +print("") |
| 246 | +print("/**") |
| 247 | +print(" * @file") |
| 248 | +print(" * ASN.1 Object ID Definitions") |
| 249 | +print(" *") |
| 250 | +print(" * !!! WARNING !!! WARNING !!! WARNING !!!") |
| 251 | +print(" *") |
| 252 | +print(" * DO NOT EDIT THIS FILE! This file is generated by the") |
| 253 | +print(" * gen-oid-table.py script.") |
| 254 | +print(" *") |
| 255 | +print(" * To make changes, edit the script and re-run it to generate") |
| 256 | +print(" * this file.") |
| 257 | +print(" *") |
| 258 | +print(" */") |
| 259 | +print("") |
| 260 | +print("#ifndef ASN1OID_H_") |
| 261 | +print("#define ASN1OID_H_") |
| 262 | +print("") |
| 263 | +print("enum OIDCategory") |
| 264 | +print("{") |
263 | 265 | for (catName, catEnum) in oidCategories: |
264 | | - print " kOIDCategory_%s = 0x%04X," % (catName, catEnum) |
265 | | -print "" |
266 | | -print " kOIDCategory_NotSpecified = 0," |
267 | | -print " kOIDCategory_Unknown = 0x0F00," |
268 | | -print " kOIDCategory_Mask = 0x0F00" |
269 | | -print "};" |
270 | | -print "" |
271 | | - |
272 | | -print "typedef uint16_t OID;" |
273 | | -print "" |
274 | | - |
275 | | -print "enum" |
276 | | -print "{" |
| 266 | + print(" kOIDCategory_%s = 0x%04X," % (catName, catEnum)) |
| 267 | +print("") |
| 268 | +print(" kOIDCategory_NotSpecified = 0,") |
| 269 | +print(" kOIDCategory_Unknown = 0x0F00,") |
| 270 | +print(" kOIDCategory_Mask = 0x0F00") |
| 271 | +print("};") |
| 272 | +print("") |
| 273 | + |
| 274 | +print("typedef uint16_t OID;") |
| 275 | +print("") |
| 276 | + |
| 277 | +print("enum") |
| 278 | +print("{") |
277 | 279 | for (catName, catEnum) in oidCategories: |
278 | 280 | for (oidCatName, oidName, oidEnum, oid) in oids: |
279 | 281 | if (oidCatName == catName): |
280 | | - print " kOID_%s_%s = 0x%04X," % (catName, oidName, catEnum + oidEnum) |
281 | | - print "" |
282 | | -print " kOID_NotSpecified = 0," |
283 | | -print " kOID_Unknown = 0xFFFF," |
284 | | -print " kOID_Mask = 0x00FF" |
285 | | -print "};" |
286 | | -print "" |
287 | | - |
288 | | -print "struct OIDTableEntry" |
289 | | -print "{" |
290 | | -print " OID EnumVal;" |
291 | | -print " const uint8_t *EncodedOID;" |
292 | | -print " uint16_t EncodedOIDLen;" |
293 | | -print "};" |
294 | | -print "" |
295 | | - |
296 | | -print "struct OIDNameTableEntry" |
297 | | -print "{" |
298 | | -print " OID EnumVal;" |
299 | | -print " const char *Name;" |
300 | | -print "};" |
301 | | -print "" |
302 | | - |
303 | | -print "extern const OIDTableEntry sOIDTable[];" |
304 | | -print "extern const OIDNameTableEntry sOIDNameTable[];" |
305 | | -print "extern const size_t sOIDTableSize;" |
306 | | -print "" |
307 | | - |
308 | | -print "#ifdef ASN1_DEFINE_OID_TABLE" |
309 | | -print "" |
| 282 | + print(" kOID_%s_%s = 0x%04X," % (catName, oidName, catEnum + oidEnum)) |
| 283 | + print("") |
| 284 | +print(" kOID_NotSpecified = 0,") |
| 285 | +print(" kOID_Unknown = 0xFFFF,") |
| 286 | +print(" kOID_Mask = 0x00FF") |
| 287 | +print("};") |
| 288 | +print("") |
| 289 | + |
| 290 | +print("struct OIDTableEntry") |
| 291 | +print("{") |
| 292 | +print(" OID EnumVal;") |
| 293 | +print(" const uint8_t *EncodedOID;") |
| 294 | +print(" uint16_t EncodedOIDLen;") |
| 295 | +print("};") |
| 296 | +print("") |
| 297 | + |
| 298 | +print("struct OIDNameTableEntry") |
| 299 | +print("{") |
| 300 | +print(" OID EnumVal;") |
| 301 | +print(" const char *Name;") |
| 302 | +print("};") |
| 303 | +print("") |
| 304 | + |
| 305 | +print("extern const OIDTableEntry sOIDTable[];") |
| 306 | +print("extern const OIDNameTableEntry sOIDNameTable[];") |
| 307 | +print("extern const size_t sOIDTableSize;") |
| 308 | +print("") |
| 309 | + |
| 310 | +print("#ifdef ASN1_DEFINE_OID_TABLE") |
| 311 | +print("") |
310 | 312 |
|
311 | 313 | for (catName, oidName, oidEnum, oid) in oids: |
312 | | - print "static const uint8_t sOID_%s_%s[] = { %s };" % (catName, oidName, ", ".join([ "0x%02X" % (x) for x in encodeOID(oid) ])) |
313 | | -print "" |
| 314 | + print("static const uint8_t sOID_%s_%s[] = { %s };" % (catName, oidName, ", ".join([ "0x%02X" % (x) for x in encodeOID(oid) ]))) |
| 315 | +print("") |
314 | 316 |
|
315 | | -print "const OIDTableEntry sOIDTable[] =" |
316 | | -print "{" |
| 317 | +print("const OIDTableEntry sOIDTable[] =") |
| 318 | +print("{") |
317 | 319 | oidTableSize = 0 |
318 | 320 | for (catName, oidName, oidEnum, oid) in oids: |
319 | | - print " { kOID_%s_%s, sOID_%s_%s, sizeof(sOID_%s_%s) }," % (catName, oidName, catName, oidName, catName, oidName) |
| 321 | + print(" { kOID_%s_%s, sOID_%s_%s, sizeof(sOID_%s_%s) }," % (catName, oidName, catName, oidName, catName, oidName)) |
320 | 322 | oidTableSize += 1 |
321 | | -print " { kOID_NotSpecified, NULL, 0 }" |
322 | | -print "};" |
323 | | -print "" |
| 323 | +print(" { kOID_NotSpecified, NULL, 0 }") |
| 324 | +print("};") |
| 325 | +print("") |
324 | 326 |
|
325 | | -print "const size_t sOIDTableSize = %d;" % (oidTableSize) |
326 | | -print "" |
| 327 | +print("const size_t sOIDTableSize = %d;" % (oidTableSize)) |
| 328 | +print("") |
327 | 329 |
|
328 | | -print "#endif // ASN1_DEFINE_OID_TABLE" |
329 | | -print "" |
| 330 | +print("#endif // ASN1_DEFINE_OID_TABLE") |
| 331 | +print("") |
330 | 332 |
|
331 | | -print "#ifdef ASN1_DEFINE_OID_NAME_TABLE" |
332 | | -print "" |
| 333 | +print("#ifdef ASN1_DEFINE_OID_NAME_TABLE") |
| 334 | +print("") |
333 | 335 |
|
334 | | -print "const OIDNameTableEntry sOIDNameTable[] =" |
335 | | -print "{" |
| 336 | +print("const OIDNameTableEntry sOIDNameTable[] =") |
| 337 | +print("{") |
336 | 338 | for (catName, oidName, oidEnum, oid) in oids: |
337 | | - print " { kOID_%s_%s, \"%s\" }," % (catName, oidName, oidName) |
338 | | -print " { kOID_NotSpecified, NULL }" |
339 | | -print "};" |
340 | | -print "" |
| 339 | + print(" { kOID_%s_%s, \"%s\" }," % (catName, oidName, oidName)) |
| 340 | +print(" { kOID_NotSpecified, NULL }") |
| 341 | +print("};") |
| 342 | +print("") |
341 | 343 |
|
342 | | -print "#endif // ASN1_DEFINE_OID_NAME_TABLE" |
343 | | -print "" |
| 344 | +print("#endif // ASN1_DEFINE_OID_NAME_TABLE") |
| 345 | +print("") |
344 | 346 |
|
345 | | -print "" |
346 | | -print "#endif // ASN1OID_H_" |
| 347 | +print("") |
| 348 | +print("#endif // ASN1OID_H_") |
0 commit comments