Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / SignatureResourcePool.cs / 1305376 / SignatureResourcePool.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System.IO; using System.Security.Cryptography; using System.IdentityModel.Tokens; using System.Xml; using System.Text; // for sequential use by one thread sealed class SignatureResourcePool { const int BufferSize = 64; CanonicalizationDriver canonicalizationDriver; HashStream hashStream; HashAlgorithm hashAlgorithm; #if NO XmlC14NWriter integratedWriter; #endif XmlDictionaryWriter utf8Writer; byte[] encodingBuffer; char[] base64Buffer; public char[] TakeBase64Buffer() { if (this.base64Buffer == null) { this.base64Buffer = new char[BufferSize]; } return this.base64Buffer; } public CanonicalizationDriver TakeCanonicalizationDriver() { if (this.canonicalizationDriver == null) { this.canonicalizationDriver = new CanonicalizationDriver(); } else { this.canonicalizationDriver.Reset(); } return this.canonicalizationDriver; } public byte[] TakeEncodingBuffer() { if (this.encodingBuffer == null) { this.encodingBuffer = new byte[BufferSize]; } return this.encodingBuffer; } public HashAlgorithm TakeHashAlgorithm(string algorithm) { if ( this.hashAlgorithm == null ) { if ( String.IsNullOrEmpty( algorithm ) ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument( algorithm, SR.GetString( SR.EmptyOrNullArgumentString, "algorithm" ) ); } this.hashAlgorithm = CryptoHelper.CreateHashAlgorithm( algorithm ); } else { this.hashAlgorithm.Initialize(); } return this.hashAlgorithm; } public HashStream TakeHashStream(HashAlgorithm hash) { if (this.hashStream == null) { this.hashStream = new HashStream(hash); } else { this.hashStream.Reset(hash); } return this.hashStream; } public HashStream TakeHashStream(string algorithm) { return TakeHashStream(TakeHashAlgorithm(algorithm)); } #if NO public XmlC14NWriter TakeIntegratedWriter(Stream stream) { return TakeIntegratedWriter(stream, false, null); } public XmlC14NWriter TakeIntegratedWriter(Stream stream, bool includeComments, string[] inclusivePrefixes) { if (this.integratedWriter == null) { this.integratedWriter = new XmlC14NWriter(stream, includeComments, inclusivePrefixes); } else { this.integratedWriter.SetOutput(stream, includeComments, inclusivePrefixes); } return this.integratedWriter; } #endif public XmlDictionaryWriter TakeUtf8Writer() { if (this.utf8Writer == null) { this.utf8Writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null, Encoding.UTF8, false); } else { ((IXmlTextWriterInitializer) this.utf8Writer).SetOutput(Stream.Null, Encoding.UTF8, false); } return this.utf8Writer; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System.IO; using System.Security.Cryptography; using System.IdentityModel.Tokens; using System.Xml; using System.Text; // for sequential use by one thread sealed class SignatureResourcePool { const int BufferSize = 64; CanonicalizationDriver canonicalizationDriver; HashStream hashStream; HashAlgorithm hashAlgorithm; #if NO XmlC14NWriter integratedWriter; #endif XmlDictionaryWriter utf8Writer; byte[] encodingBuffer; char[] base64Buffer; public char[] TakeBase64Buffer() { if (this.base64Buffer == null) { this.base64Buffer = new char[BufferSize]; } return this.base64Buffer; } public CanonicalizationDriver TakeCanonicalizationDriver() { if (this.canonicalizationDriver == null) { this.canonicalizationDriver = new CanonicalizationDriver(); } else { this.canonicalizationDriver.Reset(); } return this.canonicalizationDriver; } public byte[] TakeEncodingBuffer() { if (this.encodingBuffer == null) { this.encodingBuffer = new byte[BufferSize]; } return this.encodingBuffer; } public HashAlgorithm TakeHashAlgorithm(string algorithm) { if ( this.hashAlgorithm == null ) { if ( String.IsNullOrEmpty( algorithm ) ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument( algorithm, SR.GetString( SR.EmptyOrNullArgumentString, "algorithm" ) ); } this.hashAlgorithm = CryptoHelper.CreateHashAlgorithm( algorithm ); } else { this.hashAlgorithm.Initialize(); } return this.hashAlgorithm; } public HashStream TakeHashStream(HashAlgorithm hash) { if (this.hashStream == null) { this.hashStream = new HashStream(hash); } else { this.hashStream.Reset(hash); } return this.hashStream; } public HashStream TakeHashStream(string algorithm) { return TakeHashStream(TakeHashAlgorithm(algorithm)); } #if NO public XmlC14NWriter TakeIntegratedWriter(Stream stream) { return TakeIntegratedWriter(stream, false, null); } public XmlC14NWriter TakeIntegratedWriter(Stream stream, bool includeComments, string[] inclusivePrefixes) { if (this.integratedWriter == null) { this.integratedWriter = new XmlC14NWriter(stream, includeComments, inclusivePrefixes); } else { this.integratedWriter.SetOutput(stream, includeComments, inclusivePrefixes); } return this.integratedWriter; } #endif public XmlDictionaryWriter TakeUtf8Writer() { if (this.utf8Writer == null) { this.utf8Writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null, Encoding.UTF8, false); } else { ((IXmlTextWriterInitializer) this.utf8Writer).SetOutput(Stream.Null, Encoding.UTF8, false); } return this.utf8Writer; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BevelBitmapEffect.cs
- TemplateBindingExpressionConverter.cs
- ConfigurationValidatorBase.cs
- ErrorHandlingAcceptor.cs
- AssertUtility.cs
- ImageButton.cs
- WebControl.cs
- CommentEmitter.cs
- RotationValidation.cs
- List.cs
- DataBoundControlDesigner.cs
- SystemNetworkInterface.cs
- AssemblySettingAttributes.cs
- MenuAdapter.cs
- TextRangeEditTables.cs
- x509utils.cs
- HMACSHA256.cs
- LongCountAggregationOperator.cs
- HMACSHA384.cs
- WebPartAddingEventArgs.cs
- BezierSegment.cs
- InvalidBodyAccessException.cs
- InstancePersistenceCommand.cs
- Win32KeyboardDevice.cs
- MetadataSerializer.cs
- TileBrush.cs
- UnauthorizedAccessException.cs
- TaskResultSetter.cs
- CopyNodeSetAction.cs
- CallbackHandler.cs
- ComPlusTraceRecord.cs
- NavigationHelper.cs
- StandardCommands.cs
- SamlAuthorizationDecisionStatement.cs
- WebPartConnectionsCancelEventArgs.cs
- Monitor.cs
- XmlSchemaSearchPattern.cs
- EntityWithKeyStrategy.cs
- DebuggerAttributes.cs
- ExtentKey.cs
- SqlClientMetaDataCollectionNames.cs
- GradientBrush.cs
- FixedDocument.cs
- PageCache.cs
- ProxyElement.cs
- PagerSettings.cs
- BinaryUtilClasses.cs
- UrlPath.cs
- ToolStripDesigner.cs
- XmlDataProvider.cs
- ObjectKeyFrameCollection.cs
- SoapFault.cs
- SystemIPInterfaceStatistics.cs
- SplineQuaternionKeyFrame.cs
- ArgumentValidation.cs
- ConstructorNeedsTagAttribute.cs
- ZoneLinkButton.cs
- RetrieveVirtualItemEventArgs.cs
- WindowsRichEdit.cs
- WindowsEditBoxRange.cs
- Blend.cs
- QueueProcessor.cs
- HwndSubclass.cs
- SecUtil.cs
- RelationshipConstraintValidator.cs
- ReadOnlyHierarchicalDataSource.cs
- QueryableFilterRepeater.cs
- ParserExtension.cs
- Line.cs
- PersonalizationProviderHelper.cs
- Blend.cs
- MobileControlDesigner.cs
- DependencyPropertyAttribute.cs
- PartBasedPackageProperties.cs
- FontSourceCollection.cs
- GridViewDeletedEventArgs.cs
- BitmapEffectrendercontext.cs
- DataGridViewComboBoxCell.cs
- SmtpNegotiateAuthenticationModule.cs
- ExtenderControl.cs
- ListViewHitTestInfo.cs
- DependencyPropertyConverter.cs
- EdmType.cs
- Message.cs
- ComponentFactoryHelpers.cs
- InvalidEnumArgumentException.cs
- LabelEditEvent.cs
- Canvas.cs
- SystemDiagnosticsSection.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- StateMachineSubscriptionManager.cs
- XpsInterleavingPolicy.cs
- DesignerSerializationOptionsAttribute.cs
- EntityContainerAssociationSet.cs
- HttpCachePolicy.cs
- DeadCharTextComposition.cs
- WeakKeyDictionary.cs
- HttpInputStream.cs
- RequiredFieldValidator.cs
- SatelliteContractVersionAttribute.cs