Example #1
0
        BlobChunkVerificationResultInfo VerifyEof(bool streamFirst = true,
                                                  BlobTransportStreamAuthentication expectedAuthentication = BlobTransportStreamAuthentication.None)
        {
            var result = streamFirst ? VerifyEnoughBytesForChunkOrData(kFooterSize) : BlobChunkVerificationResultInfo.ValidResult;

            if (result.IsValid)
            {
                if (streamFirst)
                {
                    mFooterPosition = BaseStream.Position;
                    UnderlyingStream.Stream(ref mHeader);
                }
                long blob_size = AssumedBlobSize;

                result = mFooter.Verify(expectedAuthentication, blob_size);

                if (streamFirst && result.IsValid)
                {
                    mFooter.SerializeAuthenticationData(UnderlyingStream);
                }
            }

            if (result.IsInvalid)
            {
                result.Context = BlobChunkVerificationResultContext.Footer;
            }

            return(result);
        }
Example #2
0
        BlobChunkVerificationResultInfo VerifyStart(bool streamFirst = true)
        {
            var result = streamFirst ? VerifyEnoughBytesForChunkOrData(kHeaderSize) : BlobChunkVerificationResultInfo.ValidResult;

            if (result.IsValid)
            {
                if (streamFirst)
                {
                    UnderlyingStream.Stream(ref mHeader);
                }

                bool requires_byteswap;
                result = mHeader.Verify(out requires_byteswap);

                if (result.IsValid && requires_byteswap)
                {
                    UnderlyingStream.ChangeByteOrder(UnderlyingStream.ByteOrder.Invert());
                }
            }

            if (result.IsInvalid)
            {
                result.Context = BlobChunkVerificationResultContext.Header;
            }

            return(result);
        }
Example #3
0
        BlobChunkVerificationResultInfo EnumerateOneChunk <T>(
            out BlobChunkHeader header, ref T resultValue,
            Func <BlobTransportStream, BlobChunkHeader, T> getResultValue, bool getResultValueConsumesChunk,
            out bool isEof)
        {
            header = BlobChunkHeader.Null;
            isEof  = false;
            var result = VerifyEnoughBytesForChunkOrData(BlobChunkHeader.kSizeOf);

            if (result.IsValid)
            {
                UnderlyingStream.Stream(ref header);
                result = header.VerifyVersionIsPositive()
                         .And(header, h => h.VerifyDataSize(0))
                         .And(header, h => h.VerifyFlagsIsPostive())
                         .And(header, this, (h, s) => s.VerifyEnoughBytesForChunkOrData(h.DataSize));

                isEof = header.Signature == StreamFooter.kSignature.ID;

                if (result.IsValid)
                {
                    if (isEof)
                    {
                        mFooterPosition = BaseStream.Position - BlobChunkHeader.kSizeOf;
                        mFooter.SerializeSansHeader(UnderlyingStream, header);
                        mFooter.SerializeAuthenticationData(UnderlyingStream);
                    }
                    else
                    {
                        resultValue = getResultValue(this, header);

                        if (!getResultValueConsumesChunk)
                        {
                            header.StreamSkipData(BaseStream);
                        }
                    }
                }
                else
                {
                    if (isEof)
                    {
                        result.Context = BlobChunkVerificationResultContext.Footer;
                    }
                }
            }
            return(result);
        }