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
- WeakEventTable.cs
- RootProfilePropertySettingsCollection.cs
- TreeViewImageIndexConverter.cs
- TextWriter.cs
- ListBoxChrome.cs
- ConfigurationElementProperty.cs
- TextTreeTextNode.cs
- ButtonField.cs
- SchemaSetCompiler.cs
- DataBindingHandlerAttribute.cs
- ParenthesizePropertyNameAttribute.cs
- CodeTypeDeclaration.cs
- SafeNativeMethods.cs
- OrderByQueryOptionExpression.cs
- Page.cs
- EpmContentSerializer.cs
- EventLogEntry.cs
- CustomAttributeFormatException.cs
- DataFormat.cs
- ListView.cs
- UndoEngine.cs
- CryptographicAttribute.cs
- XmlSortKeyAccumulator.cs
- smtppermission.cs
- ExpressionBuilderContext.cs
- DataGridViewColumnCollection.cs
- cookiecollection.cs
- DataBinder.cs
- XmlWrappingReader.cs
- GlobalItem.cs
- SqlGatherConsumedAliases.cs
- DirectoryGroupQuery.cs
- GeometryModel3D.cs
- SerializationEventsCache.cs
- ReadingWritingEntityEventArgs.cs
- MethodExpression.cs
- AuthenticationModulesSection.cs
- Cursor.cs
- CodeDirectionExpression.cs
- TextFormatterImp.cs
- ObjectDataSourceFilteringEventArgs.cs
- PlainXmlDeserializer.cs
- Listbox.cs
- AxDesigner.cs
- MD5.cs
- PropertyValueEditor.cs
- MenuItemBindingCollection.cs
- XmlSchemaAnnotated.cs
- FormViewUpdateEventArgs.cs
- OpCellTreeNode.cs
- RunClient.cs
- MdiWindowListStrip.cs
- ListViewDeletedEventArgs.cs
- QuaternionAnimation.cs
- HtmlWindow.cs
- WorkflowDesignerColors.cs
- CodePropertyReferenceExpression.cs
- Wildcard.cs
- CodeAttributeDeclaration.cs
- CodeAttributeArgumentCollection.cs
- _SSPISessionCache.cs
- ModifierKeysValueSerializer.cs
- FillRuleValidation.cs
- NavigationWindow.cs
- XmlTextReaderImpl.cs
- PeerCustomResolverSettings.cs
- OledbConnectionStringbuilder.cs
- IgnorePropertiesAttribute.cs
- FormCollection.cs
- HtmlWindow.cs
- HandlerFactoryCache.cs
- IndexedString.cs
- ISessionStateStore.cs
- TextServicesProperty.cs
- RemoteWebConfigurationHostServer.cs
- GlyphShapingProperties.cs
- XamlGridLengthSerializer.cs
- XPathSingletonIterator.cs
- SQLInt32.cs
- OleDbDataAdapter.cs
- TableLayoutPanel.cs
- COM2FontConverter.cs
- ReadOnlyDataSource.cs
- AsyncWaitHandle.cs
- SecurityDocument.cs
- UseLicense.cs
- odbcmetadatacollectionnames.cs
- RpcCryptoContext.cs
- WizardStepBase.cs
- _DynamicWinsockMethods.cs
- RestHandlerFactory.cs
- Update.cs
- SmiRecordBuffer.cs
- DBCSCodePageEncoding.cs
- AuthenticationService.cs
- ErasingStroke.cs
- ProfileEventArgs.cs
- FormViewDeletedEventArgs.cs
- CustomAttribute.cs
- XmlBindingWorker.cs