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
- BaseHashHelper.cs
- CommandDesigner.cs
- ProjectionPruner.cs
- CatalogZoneBase.cs
- ReadOnlyDictionary.cs
- HtmlPanelAdapter.cs
- ModelTreeEnumerator.cs
- EventWaitHandle.cs
- Site.cs
- HMACSHA256.cs
- JpegBitmapDecoder.cs
- ApplicationBuildProvider.cs
- AutomationPropertyInfo.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- TypefaceMetricsCache.cs
- ProtocolsConfigurationEntry.cs
- TreeViewCancelEvent.cs
- PenLineCapValidation.cs
- SplitterPanel.cs
- _AutoWebProxyScriptEngine.cs
- DefaultPropertyAttribute.cs
- RawUIStateInputReport.cs
- SendKeys.cs
- LowerCaseStringConverter.cs
- SqlUtil.cs
- MimeBasePart.cs
- DriveInfo.cs
- MonthCalendarDesigner.cs
- ValueTypeFixupInfo.cs
- RoutedEventConverter.cs
- ViewCellSlot.cs
- ButtonBaseAutomationPeer.cs
- ThicknessAnimationUsingKeyFrames.cs
- WindowsSolidBrush.cs
- BuildProvider.cs
- RangeValueProviderWrapper.cs
- WindowsSysHeader.cs
- ColorTransformHelper.cs
- TreeNodeCollectionEditorDialog.cs
- MdImport.cs
- ArrangedElementCollection.cs
- Clause.cs
- OutputCacheProfile.cs
- LocalBuilder.cs
- DetailsViewPagerRow.cs
- TraceSource.cs
- ResolveNameEventArgs.cs
- ParallelQuery.cs
- XmlElementList.cs
- MimeTypeMapper.cs
- LayoutEvent.cs
- BufferedGraphicsContext.cs
- OperatingSystem.cs
- InstanceOwnerException.cs
- InstanceCreationEditor.cs
- BoundPropertyEntry.cs
- XmlCharacterData.cs
- XmlSchemaValidator.cs
- ExtentKey.cs
- LabelAutomationPeer.cs
- AncestorChangedEventArgs.cs
- NativeObjectSecurity.cs
- IntegerFacetDescriptionElement.cs
- DialogResultConverter.cs
- DataMisalignedException.cs
- DesignTimeParseData.cs
- SqlNamer.cs
- ErrorWrapper.cs
- Matrix.cs
- ZoneMembershipCondition.cs
- Transform.cs
- NameValuePair.cs
- ProviderManager.cs
- XsdDataContractExporter.cs
- ThemeDictionaryExtension.cs
- HtmlUtf8RawTextWriter.cs
- LogWriteRestartAreaAsyncResult.cs
- Italic.cs
- NativeBuffer.cs
- FixedSOMLineRanges.cs
- EntityDataSourceStatementEditorForm.cs
- SchemaCollectionCompiler.cs
- SoapInteropTypes.cs
- PositiveTimeSpanValidatorAttribute.cs
- DoubleIndependentAnimationStorage.cs
- SymDocumentType.cs
- COAUTHIDENTITY.cs
- SqlRemoveConstantOrderBy.cs
- SafeCertificateContext.cs
- Emitter.cs
- TypeElementCollection.cs
- HMACSHA1.cs
- __Error.cs
- DataGrid.cs
- PersistenceMetadataNamespace.cs
- FrameAutomationPeer.cs
- WindowsIPAddress.cs
- FixedBufferAttribute.cs
- KerberosSecurityTokenProvider.cs
- UpdateCommand.cs