IsValidCacheState() public static method

public static IsValidCacheState ( ECacheState cachestate ) : bool
cachestate ECacheState
return bool
Beispiel #1
0
        private void ReadBlobHeader()
        {
            cacheState  = (ECacheState)source.ReadByte();
            processCode = (EAutoPreprocessCode)source.ReadByte();

            bytesAvailable = source.ReadInt32();
            spareAvailable = source.ReadInt32();

            if (!BlobUtil.IsValidCacheState(cacheState) || !BlobUtil.IsValidProcess(processCode))
            {
                throw new InvalidBlobException("Invalid blob header");
            }

            TakeBytes(BlobHeaderLength);
            UnpackBlobIfNeeded();
        }
Beispiel #2
0
        private bool TryReadBlob(UInt32 lengthHint)
        {
            if (!CanRead(BlobHeaderLength) || lengthHint < BlobHeaderLength)
            {
                return(false);
            }

            ECacheState         cachestate;
            EAutoPreprocessCode process;
            Int32 serialized, spare;

            Mark(BlobHeaderLength);

            try
            {
                cachestate = (ECacheState)input.ReadByte();
                process    = (EAutoPreprocessCode)input.ReadByte();

                serialized = input.ReadInt32();
                spare      = input.ReadInt32();
            }
            catch (Exception)
            {
                Reset();
                throw new InvalidDataException("Corrupted blob");
            }

            if (!BlobUtil.IsValidCacheState(cachestate) || !BlobUtil.IsValidProcess(process) ||
                serialized < 0 || spare < 0 ||
                !CanReadMarked(serialized))
            {
                Reset();
                return(false);
            }

            serialized -= BlobHeaderLength;


            if (process != EAutoPreprocessCode.eAutoPreprocessCodePlaintext)
            {
                PeekableStream originalStream = input;
                object         extendedData   = null;

                input = HandleProcessCode(process, ref serialized, out extendedData);

                bool result = TryReadBlob((uint)serialized);

                input.ReadBytes(40);   // read and dispose HMACs
                // todo: validate them?

                input.Close();
                input = originalStream;

                return(result);
            }

            if (Blob != null)
            {
                Blob(process, cachestate);
            }

            ProcessFields(serialized);

            if (spare > 0)
            {
                byte[] spareData = new byte[spare];
                input.Read(spareData, 0, spare);

                if (Spare != null)
                {
                    Spare(spareData);
                }
            }

            if (EndBlob != null)
            {
                EndBlob();
            }

            return(true);
        }