Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------ // 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
- WindowsHyperlink.cs
- TypedLocationWrapper.cs
- TimeEnumHelper.cs
- LayoutManager.cs
- PaginationProgressEventArgs.cs
- OdbcHandle.cs
- XmlCodeExporter.cs
- MetadataArtifactLoaderFile.cs
- UnsafeNativeMethods.cs
- MobileListItemCollection.cs
- InvalidProgramException.cs
- TextEndOfSegment.cs
- DataGridViewImageColumn.cs
- SimpleMailWebEventProvider.cs
- RangeValidator.cs
- UInt32.cs
- BitmapEffectDrawing.cs
- BitmapDecoder.cs
- HeaderedContentControl.cs
- TableColumnCollection.cs
- WindowsMenu.cs
- ListenerBinder.cs
- UInt32.cs
- EventTask.cs
- Converter.cs
- TypefaceMap.cs
- InputMethod.cs
- Columns.cs
- StorageRoot.cs
- TreeView.cs
- HandleCollector.cs
- XmlSchemaAttribute.cs
- MaskDesignerDialog.cs
- WindowsFormsSynchronizationContext.cs
- Label.cs
- ClientTarget.cs
- LocalizabilityAttribute.cs
- SecureUICommand.cs
- StickyNote.cs
- __ConsoleStream.cs
- TextElementCollectionHelper.cs
- TraversalRequest.cs
- Utilities.cs
- DiscoveryOperationContextExtension.cs
- SupportsEventValidationAttribute.cs
- UriTemplateCompoundPathSegment.cs
- TargetControlTypeAttribute.cs
- AnimatedTypeHelpers.cs
- PagedControl.cs
- TextEndOfParagraph.cs
- DataGridCaption.cs
- TemplatedWizardStep.cs
- CompleteWizardStep.cs
- MetadataItem_Static.cs
- SmtpLoginAuthenticationModule.cs
- BitmapSourceSafeMILHandle.cs
- BigIntegerStorage.cs
- Encoding.cs
- RangeValueProviderWrapper.cs
- SqlDependency.cs
- MouseCaptureWithinProperty.cs
- TypeGeneratedEventArgs.cs
- ObjectListCommandCollection.cs
- ListViewDataItem.cs
- Trigger.cs
- AdPostCacheSubstitution.cs
- StringToken.cs
- DetailsViewCommandEventArgs.cs
- ConsumerConnectionPointCollection.cs
- TextRangeAdaptor.cs
- Clipboard.cs
- XDeferredAxisSource.cs
- ContentElementAutomationPeer.cs
- ProcessingInstructionAction.cs
- SQLGuid.cs
- CapabilitiesUse.cs
- SettingsAttributes.cs
- XmlSchemaAttribute.cs
- CacheEntry.cs
- updatecommandorderer.cs
- BatchServiceHost.cs
- IfJoinedCondition.cs
- TreeViewDataItemAutomationPeer.cs
- MatchingStyle.cs
- ToolStripProgressBar.cs
- XamlTemplateSerializer.cs
- BaseCodeDomTreeGenerator.cs
- PerspectiveCamera.cs
- KnownTypeHelper.cs
- Compensate.cs
- RankException.cs
- ProvidePropertyAttribute.cs
- login.cs
- XmlNamespaceMapping.cs
- ClientSettings.cs
- ActiveDesignSurfaceEvent.cs
- ExtendedPropertyInfo.cs
- SQLConvert.cs
- ColorTransformHelper.cs
- Visual3DCollection.cs