dsig.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import struct
  2. from lxml.etree import Element
  3. from data import BFlags
  4. from transform.bytes import outputTableBytes
  5. class DSIG:
  6. """
  7. Class representing a placeholder DSIG table.
  8. """
  9. def __init__(self):
  10. self.version = 0x00000001
  11. # Hardcoded. It is what it's supposed to be - a single UInt32 formatted as hex.
  12. self.flags = BFlags('00000000')
  13. self.numSigs = 0
  14. def toTTX(self):
  15. """
  16. Create a dummy DSIG table.
  17. """
  18. dsig = Element("DSIG")
  19. dsig.append(Element("tableHeader", {'version': hex(self.version)
  20. ,'flag': self.flags.toTTXStr()
  21. ,'numSigs': str(self.numSigs)
  22. }))
  23. return dsig
  24. def toBytes(self):
  25. dsig = struct.pack( '>I2sH'
  26. , self.version # UInt32 (not fixed type!)
  27. , self.flags.toBytes() # 2 bytes/UInt16
  28. , self.numSigs # UInt16
  29. )
  30. return outputTableBytes(dsig)