private void CommonStuff (CryptographicAttributeObjectCollection coll) { Assert.IsFalse (coll.IsSynchronized, "IsSynchronized"); Assert.AreSame (coll, coll.SyncRoot, "SyncRoot"); Assert.IsNotNull (coll.GetEnumerator (), "GetEnumerator"); int i = coll.Count; Oid o1 = new Oid ("1.2.840.113549.1.7.3"); AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x05, 0x00 }); Assert.AreEqual (i, coll.Add (aed), "Add(AsnEncodedData)"); Assert.IsTrue ((coll[i++] is CryptographicAttributeObject), "converted"); Oid o2 = new Oid ("1.2.840.113549.1.7.2"); CryptographicAttributeObject cao = new CryptographicAttributeObject (o2); Assert.AreEqual (i, coll.Add (cao), "Add(CryptographicAttributeObject)"); CryptographicAttributeObject[] array = new CryptographicAttributeObject [coll.Count]; coll.CopyTo (array, 0); Array a = (Array) new object [coll.Count]; ICollection c = (ICollection) coll; c.CopyTo (a, 0); IEnumerable e = (IEnumerable) coll; Assert.IsNotNull (e.GetEnumerator (), "GetEnumerator"); coll.Remove (cao); Assert.AreEqual (i, coll.Count, "Remove(CryptographicAttributeObject)"); }
private static unsafe void AddCryptAttribute(CryptographicAttributeObjectCollection collection, CRYPT_ATTRIBUTE* pCryptAttribute) { string oidValue = pCryptAttribute->pszObjId.ToStringAnsi(); Oid oid = new Oid(oidValue); for (int i = 0; i < pCryptAttribute->cValue; i++) { byte[] encodedAttribute = pCryptAttribute->rgValue[i].ToByteArray(); AsnEncodedData attributeObject = Helpers.CreateBestPkcs9AttributeObjectAvailable(oid, encodedAttribute); collection.Add(attributeObject); } }
public void Remove_MultipleSameOid_Last () { Oid o = new Oid (defaultOid); CryptographicAttributeObject cao = new CryptographicAttributeObject (o); CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao); Oid o1 = new Oid (defaultOid); AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) 0 }); coll.Add (aed); aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) 0 }); coll.Add (aed); Oid o2 = new Oid (defaultOid); CryptographicAttributeObject last = new CryptographicAttributeObject (o2); coll.Add (last); Assert.AreEqual (1, coll.Count, "before Remove"); coll.Remove (last); Assert.AreEqual (1, coll.Count, "after Remove"); }
public void Add_MultipleSameOid () { Oid o = new Oid (defaultOid); CryptographicAttributeObject cao = new CryptographicAttributeObject (o); CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao); int i = 0; while (i < 10) { Assert.AreEqual (1, coll.Count, String.Format ("Count-{0}", i)); Assert.AreEqual (i * 2, coll[0].Values.Count, String.Format ("Values.Count-{0}", i++)); Oid o1 = new Oid (defaultOid); AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte)i }); coll.Add (aed); aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) i }); coll.Add (aed); Oid o2 = new Oid (defaultOid); coll.Add (new CryptographicAttributeObject (o2)); } }
public void Two_Both () { coll = new CryptographicAttributeObjectCollection (); Oid o1 = new Oid (defaultOid + ".1"); AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x05, 0x00 }); coll.Add (aed); Oid o2 = new Oid (defaultOid + ".2"); coll.Add (new CryptographicAttributeObject (o2)); Count (2); }
public void One_AsnEncodedData () { Oid o = new Oid (defaultOid); AsnEncodedData aed = new AsnEncodedData (o, new byte[] { 0x05, 0x00 }); coll = new CryptographicAttributeObjectCollection (); coll.Add (aed); Count (1); }