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
- StateElementCollection.cs
- Font.cs
- ObjectStateFormatter.cs
- WhitespaceRuleLookup.cs
- MessageBox.cs
- PenCursorManager.cs
- AdapterDictionary.cs
- ComplexObject.cs
- SerializationException.cs
- ToolStripInSituService.cs
- ClientScriptManager.cs
- NavigateEvent.cs
- XDeferredAxisSource.cs
- RemotingException.cs
- ActiveXContainer.cs
- SecurityHelper.cs
- PerformanceCounterLib.cs
- LastQueryOperator.cs
- ManagementObjectCollection.cs
- SafeHandles.cs
- ResourceKey.cs
- ResourceCategoryAttribute.cs
- ClientConvert.cs
- OracleCommand.cs
- PageAdapter.cs
- RegexReplacement.cs
- EventSetter.cs
- ByteStream.cs
- AvTrace.cs
- SizeConverter.cs
- EntityCollection.cs
- SessionStateItemCollection.cs
- AdornerHitTestResult.cs
- UniqueIdentifierService.cs
- OleDbStruct.cs
- DataKey.cs
- ConfigurationManagerInternalFactory.cs
- PieceNameHelper.cs
- ServicePointManager.cs
- ZipIOCentralDirectoryBlock.cs
- Pair.cs
- StringConverter.cs
- ProfileGroupSettingsCollection.cs
- URLString.cs
- ChangeBlockUndoRecord.cs
- ClientTargetCollection.cs
- AdapterUtil.cs
- DiscoveryClientProtocol.cs
- DataGridViewColumnCollection.cs
- RadioButton.cs
- ScriptReferenceBase.cs
- ImportContext.cs
- LineMetrics.cs
- DataServiceRequestException.cs
- SqlClientMetaDataCollectionNames.cs
- UnsafeCollabNativeMethods.cs
- InvalidProgramException.cs
- BoundsDrawingContextWalker.cs
- SiteMapProvider.cs
- DllNotFoundException.cs
- CultureMapper.cs
- OutputCacheSettingsSection.cs
- AttributeCollection.cs
- basecomparevalidator.cs
- Rfc2898DeriveBytes.cs
- ConfigurationSection.cs
- GeneratedCodeAttribute.cs
- HttpProfileGroupBase.cs
- ScriptComponentDescriptor.cs
- TemplateLookupAction.cs
- XmlSchemaObject.cs
- PathSegment.cs
- RangeContentEnumerator.cs
- Model3D.cs
- FileDetails.cs
- TableLayoutPanelCodeDomSerializer.cs
- GradientStop.cs
- NamespaceList.cs
- CodeAssignStatement.cs
- EditorZoneAutoFormat.cs
- ByteConverter.cs
- SectionInput.cs
- SqlNodeTypeOperators.cs
- TemplateField.cs
- UnsafeNativeMethodsCLR.cs
- BamlResourceDeserializer.cs
- AssociationProvider.cs
- ActivityTypeResolver.xaml.cs
- BasicHttpMessageSecurity.cs
- PathData.cs
- AutomationInteropProvider.cs
- CompiledAction.cs
- AnimationClockResource.cs
- Int64AnimationUsingKeyFrames.cs
- MimeReturn.cs
- FixedSOMLineRanges.cs
- DelegatingConfigHost.cs
- CheckBox.cs
- FrameworkContextData.cs
- ManifestBasedResourceGroveler.cs