The class is used to build a intermediate node object.
Ejemplo n.º 1
0
        /// <summary>
        /// This method is used to chunk the file data.
        /// </summary>
        /// <returns>A list of IntermediateNodeObject.</returns>
        public override List <IntermediateNodeObject> Chunking()
        {
            int maxChunkSize = 1 * 1024 * 1024;
            List <IntermediateNodeObject> list = new List <IntermediateNodeObject>();

            IntermediateNodeObject.IntermediateNodeObjectBuilder builder = new IntermediateNodeObject.IntermediateNodeObjectBuilder();
            int chunkStart = 0;

            if (this.FileContent.Length <= maxChunkSize)
            {
                list.Add(builder.Build(this.FileContent, this.GetSignature(this.FileContent)));

                return(list);
            }

            while (chunkStart < this.FileContent.Length)
            {
                int    chunkLength = chunkStart + maxChunkSize >= this.FileContent.Length ? this.FileContent.Length - chunkStart : maxChunkSize;
                byte[] temp        = AdapterHelper.GetBytes(this.FileContent, chunkStart, chunkLength);
                list.Add(builder.Build(temp, this.GetSignature(temp)));
                chunkStart += chunkLength;
            }

            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is used to chunk the file data.
        /// </summary>
        /// <returns>A list of IntermediateNodeObject.</returns>
        public override List <IntermediateNodeObject> Chunking()
        {
            List <IntermediateNodeObject> list = new List <IntermediateNodeObject>();

            IntermediateNodeObject.IntermediateNodeObjectBuilder builder = new IntermediateNodeObject.IntermediateNodeObjectBuilder();

            int index = 0;

            while (ZipHeader.IsFileHeader(this.FileContent, index))
            {
                byte[] dataFileSignatureBytes;
                byte[] header         = this.AnalyzeFileHeader(this.FileContent, index, out dataFileSignatureBytes);
                int    headerLength   = header.Length;
                int    compressedSize = (int)this.GetCompressedSize(dataFileSignatureBytes);

                if (headerLength + compressedSize <= 4096)
                {
                    list.Add(builder.Build(AdapterHelper.GetBytes(this.FileContent, index, headerLength + compressedSize), this.GetSingleChunkSignature(header, dataFileSignatureBytes)));
                    index += headerLength += compressedSize;
                }
                else
                {
                    list.Add(builder.Build(header, this.GetSHA1Signature(header)));
                    index += headerLength;

                    byte[] dataFile = AdapterHelper.GetBytes(this.FileContent, index, compressedSize);

                    if (dataFile.Length <= 1048576)
                    {
                        list.Add(builder.Build(dataFile, this.GetDataFileSignature(dataFileSignatureBytes)));
                    }
                    else
                    {
                        list.AddRange(this.GetSubChunkList(dataFile));
                    }

                    index += compressedSize;
                }
            }

            if (0 == index)
            {
                return(null);
            }

            byte[] final = AdapterHelper.GetBytes(this.FileContent, index, this.FileContent.Length - index);

            if (final.Length <= 1048576)
            {
                list.Add(builder.Build(final, this.GetSHA1Signature(final)));
            }
            else
            {
                // In current, it has no idea about how to compute the signature for final part larger than 1MB.
                throw new NotImplementedException("If the final chunk is larger than 1MB, the signature method is not implemented.");
            }

            return(list);
        }
        /// <summary>
        /// This method is used to chunk the file data.
        /// </summary>
        /// <returns>A list of IntermediateNodeObject.</returns>
        public override List<IntermediateNodeObject> Chunking()
        {
            List<IntermediateNodeObject> list = new List<IntermediateNodeObject>();
            IntermediateNodeObject.IntermediateNodeObjectBuilder builder = new IntermediateNodeObject.IntermediateNodeObjectBuilder();

            int index = 0;
            while (ZipHeader.IsFileHeader(this.FileContent, index))
            {
                byte[] dataFileSignatureBytes;
                byte[] header = this.AnalyzeFileHeader(this.FileContent, index, out dataFileSignatureBytes);
                int headerLength = header.Length;
                int compressedSize = (int)this.GetCompressedSize(dataFileSignatureBytes);

                if (headerLength + compressedSize <= 4096)
                {
                    list.Add(builder.Build(AdapterHelper.GetBytes(this.FileContent, index, headerLength + compressedSize), this.GetSingleChunkSignature(header, dataFileSignatureBytes)));
                    index += headerLength += compressedSize;
                }
                else
                {
                    list.Add(builder.Build(header, this.GetSHA1Signature(header)));
                    index += headerLength;

                    byte[] dataFile = AdapterHelper.GetBytes(this.FileContent, index, compressedSize);

                    if (dataFile.Length <= 1048576)
                    {
                        list.Add(builder.Build(dataFile, this.GetDataFileSignature(dataFileSignatureBytes)));
                    }
                    else
                    {
                        list.AddRange(this.GetSubChunkList(dataFile));
                    }

                    index += compressedSize;
                }
            }

            if (0 == index)
            {
                return null;
            }

            byte[] final = AdapterHelper.GetBytes(this.FileContent, index, this.FileContent.Length - index);

            if (final.Length <= 1048576)
            {
                list.Add(builder.Build(final, this.GetSHA1Signature(final)));
            }
            else
            {
                // In current, it has no idea about how to compute the signature for final part larger than 1MB.
                throw new NotImplementedException("If the final chunk is larger than 1MB, the signature method is not implemented.");
            }

            return list;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method is used to chunk the file data.
        /// </summary>
        /// <returns>A list of IntermediateNodeObject.</returns>
        public override List<IntermediateNodeObject> Chunking()
        {
            int maxChunkSize = 1 * 1024 * 1024;
            List<IntermediateNodeObject> list = new List<IntermediateNodeObject>();
            IntermediateNodeObject.IntermediateNodeObjectBuilder builder = new IntermediateNodeObject.IntermediateNodeObjectBuilder();
            int chunkStart = 0;

            if (this.FileContent.Length <= maxChunkSize)
            {
                list.Add(builder.Build(this.FileContent, this.GetSignature(this.FileContent)));

                return list;
            }

            while (chunkStart < this.FileContent.Length)
            {
                int chunkLength = chunkStart + maxChunkSize >= this.FileContent.Length ? this.FileContent.Length - chunkStart : maxChunkSize;
                byte[] temp = AdapterHelper.GetBytes(this.FileContent, chunkStart, chunkLength);
                list.Add(builder.Build(temp, this.GetSignature(temp)));
                chunkStart += chunkLength;
            }

            return list;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method is used to analyze the chunk.
        /// </summary>
        /// <param name="rootNode">Specify the root node object which will be analyzed.</param>
        /// <param name="site">Specify the ITestSite instance.</param>
        public override void AnalyzeChunking(RootNodeObject rootNode, ITestSite site)
        {
            List <IntermediateNodeObject> cloneList = new List <IntermediateNodeObject>(rootNode.IntermediateNodeObjectList);

            while (cloneList.Count != 0)
            {
                IntermediateNodeObject nodeObject = cloneList.First();
                byte[] content = nodeObject.DataNodeObjectData.ObjectData;

                if (cloneList.Count == 1)
                {
                    if (content.Length > 1048576)
                    {
                        throw new NotImplementedException("If the final chunk is larger than 1MB, the signature method is not implemented.");
                    }

                    // Only final chunk left
                    SignatureObject expect = this.GetSHA1Signature(content);
                    if (!expect.Equals(nodeObject.Signature))
                    {
                        site.Assert.Fail("For the Zip file, final part chunk expect the signature {0}, actual signature {1}", expect.ToString(), nodeObject.Signature.ToString());
                    }

                    // Verify the less than 1MB final part related requirements
                    if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                    {
                        MsfsshttpdCapture.VerifySmallFinalChunk(SharedContext.Current.Site);
                    }
                }
                else
                {
                    if (ZipHeader.IsFileHeader(content, 0))
                    {
                        byte[] dataFileSignatureBytes;
                        byte[] header         = this.AnalyzeFileHeader(content, 0, out dataFileSignatureBytes);
                        int    headerLength   = header.Length;
                        int    compressedSize = (int)this.GetCompressedSize(dataFileSignatureBytes);

                        if (headerLength + compressedSize <= 4096)
                        {
                            IntermediateNodeObject expectNode = new IntermediateNodeObject.IntermediateNodeObjectBuilder().Build(content, this.GetSingleChunkSignature(header, dataFileSignatureBytes));
                            if (!expectNode.Signature.Equals(nodeObject.Signature))
                            {
                                site.Assert.Fail("For the Zip file, when zip file is less than 4096, expect the signature {0}, actual signature {1}", expectNode.Signature.ToString(), nodeObject.Signature.ToString());
                            }

                            // Verify the zip file less than 4096 bytes
                            MsfsshttpdCapture.VerifyZipFileLessThan4096Bytes(SharedContext.Current.Site);
                        }
                        else
                        {
                            SignatureObject expectHeader = this.GetSHA1Signature(header);
                            if (!expectHeader.Equals(nodeObject.Signature))
                            {
                                site.Assert.Fail("For the Zip file header, expect the signature {0}, actual signature {1}", expectHeader.ToString(), nodeObject.Signature.ToString());
                            }

                            // Remove the header node
                            cloneList.RemoveAt(0);

                            // Then expect the next is file content node
                            nodeObject = cloneList.First();

                            // Here having something need to be distinguished between the MOSS2010 and MOSS2013
                            if (nodeObject.DataNodeObjectData == null && nodeObject.IntermediateNodeObjectList != null)
                            {
                                // This situation could most happens for MOSS2010, we fake intermediate node instead of the root node when the zip file size is larger than 1M.
                                // In the current stage, this kind of signature algorithm is not mentioned in the open specification, so leave this verify blank.
                            }
                            else if (nodeObject.DataNodeObjectData != null)
                            {
                                site.Assert.AreEqual <ulong>(
                                    (ulong)compressedSize,
                                    nodeObject.DataSize.DataSize,
                                    "The Data Size of the Intermediate Node Object MUST be the total number of bytes represented by the chunk.");

                                SignatureObject contentSignature = new SignatureObject();
                                contentSignature.SignatureData = new BinaryItem(dataFileSignatureBytes);
                                if (!contentSignature.Equals(nodeObject.Signature))
                                {
                                    site.Assert.Fail("For the Zip file content, expect the signature {0}, actual signature {1}", contentSignature.ToString(), nodeObject.Signature.ToString());
                                }

                                // Verify the zip file larger than 4096 bytes and less than 1MB.
                                if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                                {
                                    MsfsshttpdCapture.VerifyZipFileHeaderAndContentSignature(SharedContext.Current.Site);
                                    MsfsshttpdCapture.VerifyIntermediateNodeForZipFileChunk(SharedContext.Current.Site);
                                }
                            }
                            else
                            {
                                throw new InvalidOperationException("The DataNodeObjectData and IntermediateNodeObjectList cannot be null at the same time.");
                            }
                        }
                    }
                }

                cloneList.RemoveAt(0);
            }
        }
        /// <summary>
        /// This method is used to analyze the chunk.
        /// </summary>
        /// <param name="rootNode">Specify the root node object which will be analyzed.</param>
        /// <param name="site">Specify the ITestSite instance.</param>
        public override void AnalyzeChunking(RootNodeObject rootNode, ITestSite site)
        {
            List<IntermediateNodeObject> cloneList = new List<IntermediateNodeObject>(rootNode.IntermediateNodeObjectList);

            while (cloneList.Count != 0)
            {
                IntermediateNodeObject nodeObject = cloneList.First();
                byte[] content = nodeObject.DataNodeObjectData.ObjectData;

                if (cloneList.Count == 1)
                {
                    if (content.Length > 1048576)
                    {
                        throw new NotImplementedException("If the final chunk is larger than 1MB, the signature method is not implemented.");
                    }

                    // Only final chunk left
                    SignatureObject expect = this.GetSHA1Signature(content);
                    if (!expect.Equals(nodeObject.Signature))
                    {
                        site.Assert.Fail("For the Zip file, final part chunk expect the signature {0}, actual signature {1}", expect.ToString(), nodeObject.Signature.ToString());
                    }

                    // Verify the less than 1MB final part related requirements
                    if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                    {
                        MsfsshttpdCapture.VerifySmallFinalChunk(SharedContext.Current.Site);
                    }
                }
                else
                {
                    if (ZipHeader.IsFileHeader(content, 0))
                    {
                        byte[] dataFileSignatureBytes;
                        byte[] header = this.AnalyzeFileHeader(content, 0, out dataFileSignatureBytes);
                        int headerLength = header.Length;
                        int compressedSize = (int)this.GetCompressedSize(dataFileSignatureBytes);

                        if (headerLength + compressedSize <= 4096)
                        {
                            IntermediateNodeObject expectNode = new IntermediateNodeObject.IntermediateNodeObjectBuilder().Build(content, this.GetSingleChunkSignature(header, dataFileSignatureBytes));
                            if (!expectNode.Signature.Equals(nodeObject.Signature))
                            {
                                site.Assert.Fail("For the Zip file, when zip file is less than 4096, expect the signature {0}, actual signature {1}", expectNode.Signature.ToString(), nodeObject.Signature.ToString());
                            }

                            // Verify the zip file less than 4096 bytes
                            MsfsshttpdCapture.VerifyZipFileLessThan4096Bytes(SharedContext.Current.Site);
                        }
                        else
                        {
                            SignatureObject expectHeader = this.GetSHA1Signature(header);
                            if (!expectHeader.Equals(nodeObject.Signature))
                            {
                                site.Assert.Fail("For the Zip file header, expect the signature {0}, actual signature {1}", expectHeader.ToString(), nodeObject.Signature.ToString());
                            }

                            // Remove the header node
                            cloneList.RemoveAt(0);

                            // Then expect the next is file content node
                            nodeObject = cloneList.First();

                            // Here having something need to be distinguished between the MOSS2010 and MOSS2013
                            if (nodeObject.DataNodeObjectData == null && nodeObject.IntermediateNodeObjectList != null)
                            {
                                // This situation could most happens for MOSS2010, we fake intermediate node instead of the root node when the zip file size is larger than 1M.
                                // In the current stage, this kind of signature algorithm is not mentioned in the open specification, so leave this verify blank.
                            }
                            else if (nodeObject.DataNodeObjectData != null)
                            {
                                site.Assert.AreEqual<ulong>(
                                            (ulong)compressedSize,
                                            nodeObject.DataSize.DataSize,
                                            "The Data Size of the Intermediate Node Object MUST be the total number of bytes represented by the chunk.");

                                SignatureObject contentSignature = new SignatureObject();
                                contentSignature.SignatureData = new BinaryItem(dataFileSignatureBytes);
                                if (!contentSignature.Equals(nodeObject.Signature))
                                {
                                    site.Assert.Fail("For the Zip file content, expect the signature {0}, actual signature {1}", contentSignature.ToString(), nodeObject.Signature.ToString());
                                }

                                // Verify the zip file larger than 4096 bytes and less than 1MB.
                                if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                                {
                                    MsfsshttpdCapture.VerifyZipFileHeaderAndContentSignature(SharedContext.Current.Site);
                                    MsfsshttpdCapture.VerifyIntermediateNodeForZipFileChunk(SharedContext.Current.Site);
                                }
                            }
                            else
                            {
                                throw new InvalidOperationException("The DataNodeObjectData and IntermediateNodeObjectList cannot be null at the same time.");
                            }
                        }
                    }
                }

                cloneList.RemoveAt(0);
            }
        }