示例#1
0
        private bool ReadARecord(RecordStream rs)
        {
            switch (rs.PeekNextSid())
            {
            case ProtectRecord.sid:
                CheckNotPresent(_protectRecord);
                _protectRecord = rs.GetNext() as ProtectRecord;
                break;

            case ObjectProtectRecord.sid:
                CheckNotPresent(_objectProtectRecord);
                _objectProtectRecord = rs.GetNext() as ObjectProtectRecord;
                break;

            case ScenarioProtectRecord.sid:
                CheckNotPresent(_scenarioProtectRecord);
                _scenarioProtectRecord = rs.GetNext() as ScenarioProtectRecord;
                break;

            case PasswordRecord.sid:
                CheckNotPresent(_passwordRecord);
                _passwordRecord = rs.GetNext() as PasswordRecord;
                break;

            default:
                // all other record types are not part of the PageSettingsBlock
                return(false);
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// protect a spreadsheet with a password (not encrypted, just sets protect flags and the password.)
        /// </summary>
        /// <param name="password">password to set;Pass <code>null</code> to remove all protection</param>
        /// <param name="shouldProtectObjects">shouldProtectObjects are protected</param>
        /// <param name="shouldProtectScenarios">shouldProtectScenarios are protected</param>
        public void ProtectSheet(String password, bool shouldProtectObjects,
                                 bool shouldProtectScenarios)
        {
            if (password == null)
            {
                _passwordRecord        = null;
                _protectRecord         = null;
                _objectProtectRecord   = null;
                _scenarioProtectRecord = null;
                return;
            }

            ProtectRecord  prec = this.Protect;
            PasswordRecord pass = this.Password;

            prec.Protect  = true;
            pass.Password = (PasswordRecord.HashPassword(password));
            if (_objectProtectRecord == null && shouldProtectObjects)
            {
                ObjectProtectRecord rec = CreateObjectProtect();
                rec.Protect          = (true);
                _objectProtectRecord = rec;
            }
            if (_scenarioProtectRecord == null && shouldProtectScenarios)
            {
                ScenarioProtectRecord srec = CreateScenarioProtect();
                srec.Protect           = (true);
                _scenarioProtectRecord = srec;
            }
        }
示例#3
0
        /// <summary>
        /// Creates an ObjectProtect record with protect set to false.
        /// </summary>
        /// <returns></returns>
        private static ObjectProtectRecord CreateObjectProtect()
        {
            ObjectProtectRecord retval = new ObjectProtectRecord();

            retval.Protect = (false);
            return(retval);
        }
示例#4
0
        /// <summary>
        /// protect a spreadsheet with a password (not encrypted, just sets protect flags and the password.)
        /// </summary>
        /// <param name="password">password to set;Pass <code>null</code> to remove all protection</param>
        /// <param name="shouldProtectObjects">shouldProtectObjects are protected</param>
        /// <param name="shouldProtectScenarios">shouldProtectScenarios are protected</param>
        public void ProtectSheet(String password, bool shouldProtectObjects,
                                 bool shouldProtectScenarios)
        {
            if (password == null)
            {
                _passwordRecord        = null;
                _protectRecord         = null;
                _objectProtectRecord   = null;
                _scenarioProtectRecord = null;
                return;
            }

            ProtectRecord  prec = this.Protect;
            PasswordRecord pass = this.Password;

            prec.Protect  = true;
            pass.Password = (short)CryptoFunctions.CreateXorVerifier1(password);
            if (_objectProtectRecord == null && shouldProtectObjects)
            {
                ObjectProtectRecord rec = CreateObjectProtect();
                rec.Protect          = (true);
                _objectProtectRecord = rec;
            }
            if (_scenarioProtectRecord == null && shouldProtectScenarios)
            {
                ScenarioProtectRecord srec = CreateScenarioProtect();
                srec.Protect           = (true);
                _scenarioProtectRecord = srec;
            }
        }