/************************ * public static methods */ public static TTCHeader ReadTTCHeader(OTFile file) { TTCHeader ttc = null; const int SIZEOF_FIRSTTHREEFIELDS = 12; const int SIZEOF_UINT = 4; // read the first three fields of the TTC Header // starting at the beginning of the file MBOBuffer buf = file.ReadPaddedBuffer(0, SIZEOF_FIRSTTHREEFIELDS); OTTag tag = null; uint version = 0; uint DirectoryCount = 0; if (buf != null) { tag = new OTTag(buf.GetBuffer()); version = buf.GetUint(4); DirectoryCount = buf.GetUint(8); } // if the tag and the version and the dir count seem correct then // allocate a TTCHeader object and try to read the rest of the header if ((string)tag == "ttcf" && (version == 0x00010000 || version == 0x00020000) && 12 + DirectoryCount * SIZEOF_UINT < file.GetFileLength()) { ttc = new TTCHeader(); ttc.TTCTag = tag; ttc.version = version; ttc.DirectoryCount = DirectoryCount; // Directory offsets buf = file.ReadPaddedBuffer(SIZEOF_FIRSTTHREEFIELDS, DirectoryCount*SIZEOF_UINT); if (buf != null) { for (uint i=0; i<ttc.DirectoryCount; i++) { uint offset = buf.GetUint(i*SIZEOF_UINT); ttc.DirectoryOffsets.Add(offset); } } // only read Dsig fields if version 2.0 and last buffer was successfully read if ((version == 0x00010000 || version == 0x00020000) && buf != null) { uint filepos = SIZEOF_FIRSTTHREEFIELDS + DirectoryCount*SIZEOF_UINT; buf = file.ReadPaddedBuffer(filepos, 3*SIZEOF_UINT); if (buf != null) { // DsigTag ttc.DsigTag = new OTTag(buf.GetBuffer()); if ( ( version == 0x00010000 ) && ( (string) ttc.DsigTag != "DSIG" ) ) { // failed v1 trial - reset & bail ttc.DsigTag = null; return ttc; } // DsigLength ttc.DsigLength = buf.GetUint(4); // DsigOffset ttc.DsigOffset = buf.GetUint(8); } } } return ttc; }
/************************ * public static methods */ public static TTCHeader ReadTTCHeader(OTFile file) { TTCHeader ttc = null; const int SIZEOF_FIRSTTHREEFIELDS = 12; const int SIZEOF_UINT = 4; // read the first three fields of the TTC Header // starting at the beginning of the file MBOBuffer buf = file.ReadPaddedBuffer(0, SIZEOF_FIRSTTHREEFIELDS); OTTag tag = null; uint version = 0; uint DirectoryCount = 0; if (buf != null) { tag = new OTTag(buf.GetBuffer()); version = buf.GetUint(4); DirectoryCount = buf.GetUint(8); } // if the tag and the version and the dir count seem correct then // allocate a TTCHeader object and try to read the rest of the header if ((string)tag == "ttcf" && (version == 0x00010000 || version == 0x00020000) && 12 + DirectoryCount * SIZEOF_UINT < file.GetFileLength()) { ttc = new TTCHeader(); ttc.TTCTag = tag; ttc.version = version; ttc.DirectoryCount = DirectoryCount; // Directory offsets buf = file.ReadPaddedBuffer(SIZEOF_FIRSTTHREEFIELDS, DirectoryCount * SIZEOF_UINT); if (buf != null) { for (uint i = 0; i < ttc.DirectoryCount; i++) { uint offset = buf.GetUint(i * SIZEOF_UINT); ttc.DirectoryOffsets.Add(offset); } } // only read Dsig fields if version 2.0 and last buffer was successfully read if ((version == 0x00010000 || version == 0x00020000) && buf != null) { uint filepos = SIZEOF_FIRSTTHREEFIELDS + DirectoryCount * SIZEOF_UINT; buf = file.ReadPaddedBuffer(filepos, 3 * SIZEOF_UINT); if (buf != null) { // DsigTag ttc.DsigTag = new OTTag(buf.GetBuffer()); if ((version == 0x00010000) && ((string)ttc.DsigTag != "DSIG")) { // failed v1 trial - reset & bail ttc.DsigTag = null; return(ttc); } // DsigLength ttc.DsigLength = buf.GetUint(4); // DsigOffset ttc.DsigOffset = buf.GetUint(8); } } } return(ttc); }