/// <summary> /// Creates an in memory <see cref="CertificateStore"/> with this <see cref="Certificate"/> in it. /// </summary> /// <param name="withParents"><b>true</b> if the parent certificates should be included [if possible], <b>false</b> otherwise.</param> /// <returns>A CertificateStore instance.</returns> private CertificateStore CreateCertStore(bool withParents) { CertificateStore store = new CertificateStore(); if (withParents) { Certificate[] c = this.GetCertificateChain().GetCertificates(); for (int i = 0; i < c.Length; i++) { store.AddCertificate(c[i]); } } else { store.AddCertificate(this); } return store; }
private int TestMethods() { Certificate c = null; CertificateStore cs = null; try { c = CertificateStore.CreateFromCerFile(@"certs\server.base64.cer").FindCertificateByUsage(new string[] {"1.3.6.1.5.5.7.3.1"}); cs = new CertificateStore(); } catch { AddError("CS-TM-0"); return 1; } // AddCertificate + EnumCertificates try { cs.AddCertificate(null); AddError("CS-TM-1"); } catch (ArgumentNullException) { } catch { AddError("CS-TM-2"); } try { cs.AddCertificate(c); if (cs.EnumCertificates().Length != 1) AddError("CS-TM-3"); else if (!cs.EnumCertificates()[0].Equals(c)) AddError("CS-TM-4"); } catch { AddError("CS-TM-5"); } // DeleteCertificate + EnumCertificates try { cs.DeleteCertificate(null); AddError("CS-TM-6"); } catch (ArgumentNullException) { } catch { AddError("CS-TM-7"); } try { cs.DeleteCertificate(c); if (cs.EnumCertificates().Length != 0) AddError("CS-TM-8"); } catch { AddError("CS-TM-9"); } // CreateFromPfxFile try { cs.AddCertificate(c); CertificateStore cs2 = CertificateStore.CreateFromPfxFile(cs.ToPfxBuffer("test", true), "test"); if (cs2.EnumCertificates().Length != 1) AddError("CS-TM-10"); if (!c.Equals(cs2.EnumCertificates()[0])) AddError("CS-TM-11"); } catch { AddError("CS-TM-12"); } // FindCertificate and the CreateFrom*File methods are // already tested in other blackbox classes return 12; }