<div dir="ltr">Hi Ben, thanks for having a whack at this.<br><br>Some tests would be nice.<div><br>-static HCERTCHAINENGINE CRYPT_defaultChainEngine;<br>+/* There are two default chain engines which correspond to HCCE_CURRENT_USER and<br>
+ * HCCE_LOCAL_MACHINE.<br>+*/<br>+static HCERTCHAINENGINE CRYPT_defaultChainEngine[2] = { NULL, NULL };<br><br>C automatically initializes statics to 0, so the initialization here is unnecessary. I'm also a little uncertain about the use of an array of two objects, I'm not sure that two distinct objects wouldn't be easier to follow, but I'm not religious on this point.</div>
<div><br></div>+ if (hChainEngine > HCCE_LOCAL_MACHINE<br>+ � � � �&& InterlockedDecrement(&engine->ref) == 0)<div><br></div><div>I think a function that returns whether an HCERTCHAINENGINE is one of the special ones would make this easier to read, e.g.:</div>
<div><br></div><div>static int is_special_chain_engine(HCERTCHAINENGINE h)</div><div>{</div><div>� � return h == HCCE_CURRENT_USER || h == HCCE_LOCAL_MACHINE;</div><div>}</div><div><br></div><div>then:</div><div>+ if (is_special_chain_engine(hChainEngine)<br>
+ � � � �&& InterlockedDecrement(&engine->ref) == 0)</div><div><br></div><div>+static HCERTCHAINENGINE CRYPT_GetDefaultChainEngine(HCERTCHAINENGINE h)<br>�{<br>- � �if (!CRYPT_defaultChainEngine)<br>+ � �if (!CRYPT_defaultChainEngine[(int)h])</div>
<div>The constant casting is a little awkward. At least introduce a local pointer to the one you intend to modify, so we're not constantly having to re-read that cast.</div><div><br>+ � �if (hChainEngine <= HCCE_LOCAL_MACHINE)<br>
+ � � � �engine = (CertificateChainEngine*)CRYPT_GetDefaultChainEngine(<br>+ � � � � hChainEngine);<br>� � �if (TRACE_ON(chain))<br>� � � � �dump_chain_para(pChainPara);<br>� � �/* FIXME: what about HCCE_LOCAL_MACHINE? */</div>
<div><br></div><div>See my earlier suggestion on is_special_chain_engine. Also, what about that comment three lines down? Can't it be removed?</div><div><br><div>-void default_chain_engine_free(void)<br>+void default_chain_engine_free(HCERTCHAINENGINE h)<br>
�{<br>- � �CertFreeCertificateChainEngine(CRYPT_defaultChainEngine);<br>+ � �CertFreeCertificateChainEngine(CRYPT_defaultChainEngine[(int)h]);<br><br>The function default_chain_engine_free is a thin wrapper around CryptFreeCertificateChainEngine; its intended use is to clear memory at shutdown. Rather than shift the responsibility of knowing which engines to free to the caller, just have it free the two engines itself.</div>
</div><div><br></div><div>Thanks,</div><div>--Juan</div></div>