public bool Open(Stream fs) { try { var intBytes = new byte[4]; fs.Read(intBytes, 0, 4); SignatureType = (SignatureType)BitConverter.ToInt32(intBytes, 0); // Read the TMD RSA Type if (SignatureType == SignatureType.RSA_2048_SHA256) { Hash = new byte[256]; } else if (SignatureType == SignatureType.RSA_4096_SHA256) { Hash = new byte[512]; } else { errorMessage = "This kind of TMD is unsupported."; return(false); } fs.Read(Hash, 0, Hash.Length); //Continue reading header Head = MarshalUtil.ReadStructBE <TMDHeader>(fs); //read header ContentInfoRecords = new TMDContentInfoRecord[64]; for (var i = 0; i < ContentInfoRecords.Length; i++) { ContentInfoRecords[i] = MarshalUtil.ReadStructBE <TMDContentInfoRecord>(fs); } Chunks = new TMDContentChunkRecord[Head.ContentCount]; // new ArrayList(); for (var i = 0; i < Head.ContentCount; i++) { Chunks[i] = MarshalUtil.ReadStructBE <TMDContentChunkRecord>(fs); } //Check if certificates are next fs.Read(intBytes, 0, 4); switch ((SignatureType)BitConverter.ToInt32(intBytes, 0)) { case SignatureType.RSA_2048_SHA1: case SignatureType.RSA_2048_SHA256: case SignatureType.RSA_4096_SHA1: case SignatureType.RSA_4096_SHA256: fs.Seek(-4, SeekOrigin.Current); //go back CertificatesContext = new CertificatesContext(); if (!CertificatesContext.Open(fs)) { errorMessage = CertificatesContext.GetErrorMessage(); return(false); } break; } return(true); } catch { errorMessage = "Error opening the TMD file. may be corrupt."; return(false); } }
public bool Open(Stream fs) { try { var intBytes = new byte[4]; fs.Read(intBytes, 0, 4); SignatureType = (SignatureType)BitConverter.ToInt32(intBytes, 0); // Read the TMD RSA Type if (SignatureType == SignatureType.RSA_2048_SHA256) Hash = new byte[256]; else if (SignatureType == SignatureType.RSA_4096_SHA256) Hash = new byte[512]; else { errorMessage = "This kind of TMD is unsupported."; return false; } fs.Read(Hash, 0, Hash.Length); //Continue reading header Head = MarshalUtil.ReadStructBE<TMDHeader>(fs); //read header ContentInfoRecords = new TMDContentInfoRecord[64]; for (var i = 0; i < ContentInfoRecords.Length; i++) ContentInfoRecords[i] = MarshalUtil.ReadStructBE<TMDContentInfoRecord>(fs); Chunks = new TMDContentChunkRecord[Head.ContentCount]; // new ArrayList(); for (var i = 0; i < Head.ContentCount; i++) Chunks[i] = MarshalUtil.ReadStructBE<TMDContentChunkRecord>(fs); //Check if certificates are next fs.Read(intBytes, 0, 4); switch ((SignatureType)BitConverter.ToInt32(intBytes, 0)) { case SignatureType.RSA_2048_SHA1: case SignatureType.RSA_2048_SHA256: case SignatureType.RSA_4096_SHA1: case SignatureType.RSA_4096_SHA256: fs.Seek(-4, SeekOrigin.Current); //go back CertificatesContext = new CertificatesContext(); if (!CertificatesContext.Open(fs)) { errorMessage = CertificatesContext.GetErrorMessage(); return false; } break; } return true; } catch { errorMessage = "Error opening the TMD file. may be corrupt."; return false; } }