internal static unsafe IntPtr CreateCryptAttributes(CryptographicAttributeObjectCollection attributes) { if (attributes.Count == 0) { return(IntPtr.Zero); } uint num = 0; uint num2 = AlignedLength((uint)Marshal.SizeOf(typeof(I_CRYPT_ATTRIBUTE))); uint num3 = AlignedLength((uint)Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB))); CryptographicAttributeObjectEnumerator enumerator = attributes.GetEnumerator(); while (enumerator.MoveNext()) { CryptographicAttributeObject current = enumerator.Current; num += num2; num += AlignedLength((uint)(current.Oid.Value.Length + 1)); AsnEncodedDataEnumerator enumerator2 = current.Values.GetEnumerator(); while (enumerator2.MoveNext()) { AsnEncodedData data = enumerator2.Current; num += num3; num += AlignedLength((uint)data.RawData.Length); } } System.Security.Cryptography.SafeLocalAllocHandle handle = System.Security.Cryptography.CAPI.LocalAlloc(0x40, new IntPtr((long)num)); I_CRYPT_ATTRIBUTE *i_crypt_attributePtr = (I_CRYPT_ATTRIBUTE *)handle.DangerousGetHandle(); IntPtr ptr = new IntPtr(((long)handle.DangerousGetHandle()) + (num2 * attributes.Count)); CryptographicAttributeObjectEnumerator enumerator3 = attributes.GetEnumerator(); while (enumerator3.MoveNext()) { CryptographicAttributeObject obj3 = enumerator3.Current; byte * numPtr = (byte *)ptr; byte[] bytes = new byte[obj3.Oid.Value.Length + 1]; System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB *cryptoapi_blobPtr = (System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB *)(numPtr + AlignedLength((uint)bytes.Length)); i_crypt_attributePtr->pszObjId = (IntPtr)numPtr; i_crypt_attributePtr->cValue = (uint)obj3.Values.Count; i_crypt_attributePtr->rgValue = (IntPtr)cryptoapi_blobPtr; Encoding.ASCII.GetBytes(obj3.Oid.Value, 0, obj3.Oid.Value.Length, bytes, 0); Marshal.Copy(bytes, 0, i_crypt_attributePtr->pszObjId, bytes.Length); IntPtr destination = new IntPtr(((long)((ulong)cryptoapi_blobPtr)) + (obj3.Values.Count * num3)); AsnEncodedDataEnumerator enumerator4 = obj3.Values.GetEnumerator(); while (enumerator4.MoveNext()) { byte[] rawData = enumerator4.Current.RawData; if (rawData.Length > 0) { cryptoapi_blobPtr->cbData = (uint)rawData.Length; cryptoapi_blobPtr->pbData = destination; Marshal.Copy(rawData, 0, destination, rawData.Length); destination = new IntPtr(((long)destination) + AlignedLength((uint)rawData.Length)); } cryptoapi_blobPtr++; } i_crypt_attributePtr++; ptr = destination; } GC.SuppressFinalize(handle); return(handle.DangerousGetHandle()); }
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 void Count(int count) { Assert.AreEqual(count, coll.Count, "Count"); int i = 0; foreach (CryptographicAttributeObject cao in coll) { i++; } Assert.AreEqual(count, i, "foreach"); i = 0; CryptographicAttributeObjectEnumerator e = coll.GetEnumerator(); while (e.MoveNext()) { if (e.Current is CryptographicAttributeObject) { i++; } } Assert.AreEqual(count, i, "GetEnumerator"); i = 0; e.Reset(); while (e.MoveNext()) { if (e.Current is CryptographicAttributeObject) { i++; } } Assert.AreEqual(count, i, "Reset"); }
public void LinkDemand_Deny_Unrestricted() { Oid o = new Oid(defaultOid); CryptographicAttributeObject cao = new CryptographicAttributeObject(o); CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection(cao); CryptographicAttributeObjectEnumerator e = coll.GetEnumerator(); MethodInfo mi = typeof(CryptographicAttributeObjectEnumerator).GetMethod("MoveNext"); Assert.IsNotNull(mi, "default .ctor()"); Assert.IsTrue((bool)mi.Invoke(e, null), "invoke"); }
private static void AssertEquals(CryptographicAttributeObjectCollection c, IList <CryptographicAttributeObject> expected) { Assert.Equal(expected.Count, c.Count); for (int i = 0; i < c.Count; i++) { Assert.Equal(expected[i], c[i], s_CryptographicAttributeObjectComparer); } int index = 0; foreach (CryptographicAttributeObject a in c) { Assert.Equal(expected[index++], a, s_CryptographicAttributeObjectComparer); } Assert.Equal(c.Count, index); ValidateEnumerator(c.GetEnumerator(), expected); ValidateEnumerator(((ICollection)c).GetEnumerator(), expected); { CryptographicAttributeObject[] dumped = new CryptographicAttributeObject[c.Count + 3]; c.CopyTo(dumped, 2); Assert.Null(dumped[0]); Assert.Null(dumped[1]); Assert.Null(dumped[dumped.Length - 1]); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i], dumped[i + 2], s_CryptographicAttributeObjectComparer); } } { CryptographicAttributeObject[] dumped = new CryptographicAttributeObject[c.Count + 3]; ((ICollection)c).CopyTo(dumped, 2); Assert.Null(dumped[0]); Assert.Null(dumped[1]); Assert.Null(dumped[dumped.Length - 1]); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i], dumped[i + 2], s_CryptographicAttributeObjectComparer); } } }