Esempio n. 1
0
        /// <summary>
        /// Checks the validity of the authorization rule.
        /// </summary>
        protected override void OnValidate()
        {
            if (string.IsNullOrEmpty(this.InternalKeyName) || !string.Equals(this.InternalKeyName, Auth.SharedAccessSignatureBuilder.UrlEncode(this.InternalKeyName)))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyContainsInvalidCharacters);
            }

            if (this.InternalKeyName.Length > 256)
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyNameTooBig((object)256));
            }
            if (string.IsNullOrEmpty(this.InternalPrimaryKey))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleRequiresPrimaryKey);
            }

            if (Encoding.ASCII.GetByteCount(this.InternalPrimaryKey) != 44)
            {
                throw new InvalidDataContractException(SRCore.SharedAccessRuleAllowsFixedLengthKeys((object)44));
            }

            if (!SharedAccessAuthorizationRule.CheckBase64(this.InternalPrimaryKey))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessKeyShouldbeBase64);
            }

            if (!string.IsNullOrEmpty(this.InternalSecondaryKey))
            {
                if (Encoding.ASCII.GetByteCount(this.InternalSecondaryKey) != 44)
                {
                    throw new InvalidDataContractException(SRCore.SharedAccessRuleAllowsFixedLengthKeys((object)44));
                }
                if (!SharedAccessAuthorizationRule.CheckBase64(this.InternalSecondaryKey))
                {
                    throw new InvalidDataContractException(SRCore.SharedAccessKeyShouldbeBase64);
                }
            }

            if (!SharedAccessAuthorizationRule.IsValidCombinationOfRights(this.Rights))
            {
                throw new InvalidDataContractException(SRClient.InvalidCombinationOfManageRight);
            }
        }