Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / HashStream.cs / 1305376 / HashStream.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System.IO; using System.Security.Cryptography; using System.IdentityModel.Diagnostics; sealed class HashStream : Stream { HashAlgorithm hash; long length; bool hashNeedsReset; MemoryStream logStream; public HashStream(HashAlgorithm hash) { if (hash == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("hash"); Reset(hash); } public override bool CanRead { get { return false; } } public override bool CanWrite { get { return true; } } public override bool CanSeek { get { return false; } } public HashAlgorithm Hash { get { return this.hash; } } public override long Length { get { return this.length; } } public override long Position { get { return this.length; } set { // PreSharp Bug: Property get methods should not throw exceptions. #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } } public override void Flush() { } public void FlushHash() { this.hash.TransformFinalBlock(CryptoHelper.EmptyBuffer, 0, 0); if (DigestTraceRecordHelper.ShouldTraceDigest) DigestTraceRecordHelper.TraceDigest(this.logStream, this.hash); } public byte[] FlushHashAndGetValue() { FlushHash(); return this.hash.Hash; } public override int Read(byte[] buffer, int offset, int count) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } public void Reset() { if (this.hashNeedsReset) { this.hash.Initialize(); this.hashNeedsReset = false; } this.length = 0; if (DigestTraceRecordHelper.ShouldTraceDigest) this.logStream = new MemoryStream(); } public void Reset(HashAlgorithm hash) { this.hash = hash; this.hashNeedsReset = false; this.length = 0; if (DigestTraceRecordHelper.ShouldTraceDigest) this.logStream = new MemoryStream(); } public override void Write(byte[] buffer, int offset, int count) { this.hash.TransformBlock(buffer, offset, count, buffer, offset); this.length += count; this.hashNeedsReset = true; if (DigestTraceRecordHelper.ShouldTraceDigest) this.logStream.Write(buffer, offset, count); } public override long Seek(long offset, SeekOrigin origin) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } public override void SetLength(long length) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } } } // 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
- NestedContainer.cs
- InternalPolicyElement.cs
- DebugHandleTracker.cs
- EdmScalarPropertyAttribute.cs
- TextViewBase.cs
- XmlReaderDelegator.cs
- GeneralTransform.cs
- UdpDiscoveryEndpointElement.cs
- MenuItemCollection.cs
- RewritingProcessor.cs
- Normalizer.cs
- SqlServices.cs
- DrawingImage.cs
- BuildProvidersCompiler.cs
- ConcurrentQueue.cs
- DbConnectionStringCommon.cs
- DelayedRegex.cs
- SQLResource.cs
- QilInvokeLateBound.cs
- CommunicationObjectAbortedException.cs
- InputLanguage.cs
- RegexTypeEditor.cs
- ExpanderAutomationPeer.cs
- DataGridSortCommandEventArgs.cs
- PerformanceCountersElement.cs
- ServicesUtilities.cs
- Substitution.cs
- CollectionDataContractAttribute.cs
- dtdvalidator.cs
- SessionEndingEventArgs.cs
- OperatorExpressions.cs
- MemberAccessException.cs
- TimeZone.cs
- DynamicPropertyReader.cs
- CodeGroup.cs
- LinqDataSourceUpdateEventArgs.cs
- AsymmetricKeyExchangeFormatter.cs
- TextBox.cs
- CheckBoxBaseAdapter.cs
- TextServicesCompartmentEventSink.cs
- DirtyTextRange.cs
- EndEvent.cs
- ScrollProperties.cs
- Matrix3DStack.cs
- RelationshipWrapper.cs
- PostBackTrigger.cs
- EntitySqlQueryBuilder.cs
- CompiledXpathExpr.cs
- DisplayNameAttribute.cs
- MessageSecurityProtocol.cs
- AliasExpr.cs
- QuaternionKeyFrameCollection.cs
- HashAlgorithm.cs
- WindowsRegion.cs
- WebUtil.cs
- TraceContextRecord.cs
- MasterPage.cs
- ZoneButton.cs
- TextPenaltyModule.cs
- SequenceFullException.cs
- FileBasedResourceGroveler.cs
- EventEntry.cs
- SingleStorage.cs
- HierarchicalDataTemplate.cs
- Matrix.cs
- SafeRightsManagementQueryHandle.cs
- Cursor.cs
- XmlAnyElementAttributes.cs
- XmlAnyElementAttributes.cs
- WeakReadOnlyCollection.cs
- TdsParserSessionPool.cs
- DataGridTableStyleMappingNameEditor.cs
- CommandBindingCollection.cs
- SourceChangedEventArgs.cs
- ConstructorNeedsTagAttribute.cs
- ObjectDataProvider.cs
- BitmapCodecInfoInternal.cs
- TimeSpanValidator.cs
- BrowserTree.cs
- NumericUpDown.cs
- SwitchCase.cs
- SafeIUnknown.cs
- UnauthorizedWebPart.cs
- CodeMethodMap.cs
- Baml2006KnownTypes.cs
- ItemChangedEventArgs.cs
- OleDbPermission.cs
- AutoGeneratedFieldProperties.cs
- TabPage.cs
- BindMarkupExtensionSerializer.cs
- EnumConverter.cs
- StylusPointPropertyId.cs
- Win32Native.cs
- AppDomainManager.cs
- ProcessDesigner.cs
- Rijndael.cs
- WebMessageBodyStyleHelper.cs
- TypeElement.cs
- TracingConnectionInitiator.cs
- Point4D.cs