public override void ApplyBodySecurity(XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)
        {
            SecurityAppliedMessage message = this.SecurityAppliedMessage;
            EncryptedData          encryptedData;
            HashStream             hashStream;

            switch (message.BodyProtectionMode)
            {
            case MessagePartProtectionMode.None:
                return;

            case MessagePartProtectionMode.Sign:
                hashStream = TakeHashStream();
                if (CanCanonicalizeAndFragment(writer))
                {
                    message.WriteBodyToSignWithFragments(hashStream, false, null, writer);
                }
                else
                {
                    message.WriteBodyToSign(hashStream);
                }
                this.signedInfo.AddReference(message.BodyId, hashStream.FlushHashAndGetValue());
                return;

            case MessagePartProtectionMode.SignThenEncrypt:
                hashStream    = TakeHashStream();
                encryptedData = CreateEncryptedDataForBody();
                if (CanCanonicalizeAndFragment(writer))
                {
                    message.WriteBodyToSignThenEncryptWithFragments(hashStream, false, null, encryptedData, this.encryptingSymmetricAlgorithm, writer);
                }
                else
                {
                    message.WriteBodyToSignThenEncrypt(hashStream, encryptedData, this.encryptingSymmetricAlgorithm);
                }
                this.signedInfo.AddReference(message.BodyId, hashStream.FlushHashAndGetValue());
                this.referenceList.AddReferredId(encryptedData.Id);
                this.hasSignedEncryptedMessagePart = true;
                return;

            case MessagePartProtectionMode.Encrypt:
                encryptedData = CreateEncryptedDataForBody();
                message.WriteBodyToEncrypt(encryptedData, this.encryptingSymmetricAlgorithm);
                this.referenceList.AddReferredId(encryptedData.Id);
                return;

            case MessagePartProtectionMode.EncryptThenSign:
                hashStream    = TakeHashStream();
                encryptedData = CreateEncryptedDataForBody();
                message.WriteBodyToEncryptThenSign(hashStream, encryptedData, this.encryptingSymmetricAlgorithm);
                this.signedInfo.AddReference(message.BodyId, hashStream.FlushHashAndGetValue());
                this.referenceList.AddReferredId(encryptedData.Id);
                return;

            default:
                Fx.Assert("Invalid MessagePartProtectionMode");
                return;
            }
        }
        public override void ApplyBodySecurity(XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)
        {
            EncryptedData          data;
            HashStream             stream;
            SecurityAppliedMessage securityAppliedMessage = base.SecurityAppliedMessage;

            switch (securityAppliedMessage.BodyProtectionMode)
            {
            case MessagePartProtectionMode.Sign:
                stream = this.TakeHashStream();
                if (!CanCanonicalizeAndFragment(writer))
                {
                    securityAppliedMessage.WriteBodyToSign(stream);
                }
                else
                {
                    securityAppliedMessage.WriteBodyToSignWithFragments(stream, false, null, writer);
                }
                this.signedInfo.AddReference(securityAppliedMessage.BodyId, stream.FlushHashAndGetValue());
                return;

            case MessagePartProtectionMode.Encrypt:
                data = this.CreateEncryptedDataForBody();
                securityAppliedMessage.WriteBodyToEncrypt(data, this.encryptingSymmetricAlgorithm);
                this.referenceList.AddReferredId(data.Id);
                return;

            case MessagePartProtectionMode.SignThenEncrypt:
                stream = this.TakeHashStream();
                data   = this.CreateEncryptedDataForBody();
                if (!CanCanonicalizeAndFragment(writer))
                {
                    securityAppliedMessage.WriteBodyToSignThenEncrypt(stream, data, this.encryptingSymmetricAlgorithm);
                }
                else
                {
                    securityAppliedMessage.WriteBodyToSignThenEncryptWithFragments(stream, false, null, data, this.encryptingSymmetricAlgorithm, writer);
                }
                this.signedInfo.AddReference(securityAppliedMessage.BodyId, stream.FlushHashAndGetValue());
                this.referenceList.AddReferredId(data.Id);
                this.hasSignedEncryptedMessagePart = true;
                return;

            case MessagePartProtectionMode.EncryptThenSign:
                stream = this.TakeHashStream();
                data   = this.CreateEncryptedDataForBody();
                securityAppliedMessage.WriteBodyToEncryptThenSign(stream, data, this.encryptingSymmetricAlgorithm);
                this.signedInfo.AddReference(securityAppliedMessage.BodyId, stream.FlushHashAndGetValue());
                this.referenceList.AddReferredId(data.Id);
                return;
            }
        }