EnvelopedSignatureTransform.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / EnvelopedSignatureTransform.cs / 1 / EnvelopedSignatureTransform.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.IdentityModel 
{
    using System.Xml; 
    using System.Security.Cryptography; 

    sealed class EnvelopedSignatureTransform : Transform 
    {
        string prefix = XmlSignatureStrings.Prefix;

        public EnvelopedSignatureTransform() 
        {
        } 
 
        public override string Algorithm
        { 
            get { return XD.XmlSignatureDictionary.EnvelopedSignature.Value; }
        }

        public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager) 
        {
            XmlTokenStream tokenStream = input as XmlTokenStream; 
            if (tokenStream != null) 
            {
                tokenStream.SetElementExclusion(XmlSignatureStrings.Signature, XmlSignatureStrings.Namespace); 
                return tokenStream;
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedInputTypeForTransform, input.GetType())));
        } 

        // this transform is not allowed as the last one in a chain 
        public override byte[] ProcessAndDigest(object input, SignatureResourcePool resourcePool, string digestAlgorithm, DictionaryManager dictionaryManager) 
        {
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedLastTransform))); 
        }

        public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
        { 
            reader.MoveToContent();
            string algorithm = XmlHelper.ReadEmptyElementAndRequiredAttribute(reader, 
                dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace, dictionaryManager.XmlSignatureDictionary.Algorithm, out this.prefix); 
            if (algorithm != this.Algorithm)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.AlgorithmMismatchForTransform)));
            }
        }
 
        public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
        { 
            writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace); 
            writer.WriteAttributeString(dictionaryManager.XmlSignatureDictionary.Algorithm, null, this.Algorithm);
            writer.WriteEndElement(); // Transform 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK