Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / clr / src / BCL / System / Security / Cryptography / SafeCryptoHandles.cs / 1 / SafeCryptoHandles.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // SafeCryptoHandles.cs // namespace System.Security.Cryptography { using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using Microsoft.Win32.SafeHandles; // Since we need sometimes to delete the key container created in the // context of the CSP, the handle used in this class is actually a pointer // to a CRYPT_PROV_CTX unmanaged structure defined in COMCryptography.h internal sealed class SafeProvHandle : SafeHandleZeroOrMinusOneIsInvalid { // 0 is an Invalid Handle private SafeProvHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeProvHandle InvalidHandle { get { return new SafeProvHandle(IntPtr.Zero); } } // This method handles the case where pProvCtx == NULL [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] // The handle here is actually a pointer to a CRYPT_PROV_CTX unmanaged structure private static extern void _FreeCSP(IntPtr pProvCtx); override protected bool ReleaseHandle() { _FreeCSP(handle); return true; } } // Since we need to delete the key handle before the provider is released // we need to actually hold a pointer to a CRYPT_KEY_CTX unmanaged structure // whose destructor decrements a refCount. Only when the provider refCount is 0 // it is deleted. This way, we loose a race in the internal sealed class SafeKeyHandle : SafeHandleZeroOrMinusOneIsInvalid { // 0 is an Invalid Handle private SafeKeyHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeKeyHandle InvalidHandle { get { return new SafeKeyHandle(IntPtr.Zero); } } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] // The handle here is actually a pointer to a CRYPT_KEY_CTX unmanaged structure private static extern void _FreeHKey(IntPtr pKeyCtx); override protected bool ReleaseHandle() { _FreeHKey(handle); return true; } } internal sealed class SafeHashHandle : SafeHandleZeroOrMinusOneIsInvalid { // 0 is an Invalid Handle private SafeHashHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeHashHandle InvalidHandle { get { return new SafeHashHandle(IntPtr.Zero); } } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] // The handle here is actually a pointer to a CRYPT_HASH_CTX unmanaged structure private static extern void _FreeHash(IntPtr pHashCtx); override protected bool ReleaseHandle() { _FreeHash(handle); return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConfigXmlElement.cs
- BooleanFacetDescriptionElement.cs
- CheckBoxFlatAdapter.cs
- ReferenceService.cs
- XmlParserContext.cs
- SchemaImporter.cs
- _PooledStream.cs
- FlagsAttribute.cs
- XMLUtil.cs
- SerialReceived.cs
- TransactionScope.cs
- UnaryExpression.cs
- PseudoWebRequest.cs
- HeaderedContentControl.cs
- Track.cs
- UInt32Converter.cs
- DataGridViewBand.cs
- ObjectDataSourceView.cs
- RepeatBehaviorConverter.cs
- BooleanToVisibilityConverter.cs
- DesignerOptions.cs
- ColumnResizeUndoUnit.cs
- MobilePage.cs
- PropertyFilterAttribute.cs
- ResourcesGenerator.cs
- WhiteSpaceTrimStringConverter.cs
- TransformConverter.cs
- InstanceCompleteException.cs
- BehaviorEditorPart.cs
- XPathAxisIterator.cs
- CryptoApi.cs
- FixedElement.cs
- BookmarkNameHelper.cs
- NumberSubstitution.cs
- TextCollapsingProperties.cs
- ListChangedEventArgs.cs
- KnownTypes.cs
- FontStretchConverter.cs
- NetPipeSectionData.cs
- PageContent.cs
- ElementHostAutomationPeer.cs
- PackagePartCollection.cs
- safesecurityhelperavalon.cs
- ComPlusTypeLoader.cs
- MailWebEventProvider.cs
- DbProviderServices.cs
- Grant.cs
- WebZone.cs
- ObjectParameterCollection.cs
- LocalBuilder.cs
- ConvertEvent.cs
- AuthenticationServiceManager.cs
- ResourceDictionary.cs
- DataRecordObjectView.cs
- RC2.cs
- WebPartZoneCollection.cs
- DependencyPropertyValueSerializer.cs
- Int32Animation.cs
- PassportAuthenticationModule.cs
- RuleSettings.cs
- SdlChannelSink.cs
- ConfigXmlCDataSection.cs
- UnsafeMethods.cs
- NameValuePair.cs
- RectKeyFrameCollection.cs
- TimeoutValidationAttribute.cs
- ActivityValidator.cs
- RequestDescription.cs
- MemberDescriptor.cs
- ContainerSelectorBehavior.cs
- CellRelation.cs
- SourceElementsCollection.cs
- IPPacketInformation.cs
- DataGridViewComboBoxCell.cs
- RTTrackingProfile.cs
- UrlMappingsModule.cs
- MouseGestureConverter.cs
- CqlBlock.cs
- IisTraceWebEventProvider.cs
- SelectionListComponentEditor.cs
- MarginCollapsingState.cs
- SystemResources.cs
- MediaCommands.cs
- ViewCellRelation.cs
- QueryTask.cs
- WmlPanelAdapter.cs
- GridViewCommandEventArgs.cs
- RegexCharClass.cs
- DataViewManager.cs
- ConnectionsZoneAutoFormat.cs
- ScopelessEnumAttribute.cs
- DrawingGroupDrawingContext.cs
- JsonReader.cs
- ExpressionWriter.cs
- MdiWindowListItemConverter.cs
- CopyCodeAction.cs
- InternalRelationshipCollection.cs
- FileSystemWatcher.cs
- TraceHwndHost.cs
- GridViewUpdateEventArgs.cs