static unsafe int QueryContextAttributes(SafeDeleteContext phContext, ContextAttribute attribute, byte[] buffer, Type handleType, out SafeHandle refHandle) { refHandle = null; if (handleType != null) { if (handleType == typeof(SafeFreeContextBuffer)) { refHandle = SafeFreeContextBuffer.CreateEmptyHandle(); } else if (handleType == typeof(SafeFreeCertContext)) { refHandle = new SafeFreeCertContext(); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("handleType", SR.GetString(SR.ValueMustBeOf2Types, typeof(SafeFreeContextBuffer).ToString(), typeof(SafeFreeCertContext).ToString()))); } } fixed(byte *bufferPtr = buffer) { return(SafeFreeContextBuffer.QueryContextAttributes(phContext, attribute, bufferPtr, refHandle)); } }
private static unsafe int QueryContextAttributes(SafeDeleteContext phContext, ContextAttribute attribute, byte[] buffer, Type handleType, out SafeHandle refHandle) { refHandle = null; if (handleType != null) { if (handleType != typeof(SafeFreeContextBuffer)) { if (handleType != typeof(SafeFreeCertContext)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("handleType", System.IdentityModel.SR.GetString("ValueMustBeOf2Types", new object[] { typeof(SafeFreeContextBuffer).ToString(), typeof(SafeFreeCertContext).ToString() }))); } refHandle = new SafeFreeCertContext(); } else { refHandle = SafeFreeContextBuffer.CreateEmptyHandle(); } } fixed(byte *numRef = buffer) { return(SafeFreeContextBuffer.QueryContextAttributes(phContext, attribute, numRef, refHandle)); } }
internal static X509Certificate2Collection GetStore(SafeFreeCertContext certContext) { X509Certificate2Collection result = new X509Certificate2Collection(); if (certContext.IsInvalid) return result; _CERT_CONTEXT context = (_CERT_CONTEXT)Marshal.PtrToStructure(certContext.DangerousGetHandle(), typeof(_CERT_CONTEXT)); if (context.hCertStore != IntPtr.Zero) { X509Store store = null; try { store = new X509Store(context.hCertStore); result = store.Certificates; } finally { if (store != null) store.Close(); } } return result; }
private static unsafe int QueryContextAttributes(SafeDeleteContext phContext, ContextAttribute attribute, byte[] buffer, Type handleType, out SafeHandle refHandle) { refHandle = null; if (handleType != null) { if (handleType != typeof(SafeFreeContextBuffer)) { if (handleType != typeof(SafeFreeCertContext)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("handleType", System.IdentityModel.SR.GetString("ValueMustBeOf2Types", new object[] { typeof(SafeFreeContextBuffer).ToString(), typeof(SafeFreeCertContext).ToString() }))); } refHandle = new SafeFreeCertContext(); } else { refHandle = SafeFreeContextBuffer.CreateEmptyHandle(); } } fixed (byte* numRef = buffer) { return SafeFreeContextBuffer.QueryContextAttributes(phContext, attribute, numRef, refHandle); } }