コード例 #1
0
		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)");
		}
        public int Add(CryptographicAttributeObject attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            int    existing = -1;
            string oid      = attribute.Oid.Value;

            for (int i = 0; i < _list.Count; i++)
            {
                if ((_list[i] as CryptographicAttributeObject).Oid.Value == oid)
                {
                    existing = i;
                    break;
                }
            }
            if (existing >= 0)
            {
                CryptographicAttributeObject cao = this[existing];
                foreach (AsnEncodedData value in attribute.Values)
                {
                    cao.Values.Add(value);
                }
                return(existing);
            }
            else
            {
                return(_list.Add(attribute));
            }
        }
		public int Add (CryptographicAttributeObject attribute)
		{
			if (attribute == null)
				throw new ArgumentNullException ("attribute");

			return _list.Add (attribute);
		}
コード例 #4
0
		public void One_CryptographicAttributeObject () 
		{
			Oid o = new Oid (defaultOid);
			CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
			coll = new CryptographicAttributeObjectCollection (cao);
			Count (1);
		}
コード例 #5
0
        public void Remove(CryptographicAttributeObject attribute)
        {
            if (attribute == null)
                throw new ArgumentNullException(nameof(attribute));

            _list.Remove(attribute);
        }
 public void Remove(CryptographicAttributeObject attribute)
 {
     if (attribute == null)
     {
         throw new ArgumentNullException("attribute");
     }
     this.m_list.Remove(attribute);
 }
コード例 #7
0
		public void ConstructorOid () 
		{
			Oid o = new Oid (defaultOid);
			CryptographicAttributeObject ca = new CryptographicAttributeObject (o);
			Assert.AreEqual (defaultName, ca.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (defaultOid, ca.Oid.Value, "Oid.Value");
			Assert.AreEqual (0, ca.Values.Count, "Values");
		}
コード例 #8
0
        public void Remove(CryptographicAttributeObject attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            _list.Remove(attribute);
        }
コード例 #9
0
		public void Constructor_CryptographicAttributeObject () 
		{
			Oid o = new Oid (defaultOid);
			CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
			CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);
			Assert.AreEqual (1, coll.Count, "Count");
			Assert.AreSame (cao, coll[0], "this[int]");
			CommonStuff (coll);
		}
コード例 #10
0
		public void ConstructorOidCollection () 
		{
			Oid o = new Oid (defaultOid);
			AsnEncodedDataCollection coll = new AsnEncodedDataCollection ();
			CryptographicAttributeObject ca = new CryptographicAttributeObject (o, coll);
			Assert.AreEqual (defaultName, ca.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (defaultOid, ca.Oid.Value, "Oid.Value");
			Assert.AreEqual (0, ca.Values.Count, "Values - 0");
			coll.Add (new AsnEncodedData (new byte [0]));
			Assert.AreEqual (1, ca.Values.Count, "Values - 1");
		}
コード例 #11
0
		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");
		}
コード例 #12
0
 // Perform a deep copy of an existing collection
 private CryptographicAttributeObjectCollection(CryptographicAttributeObjectCollection other)
 {
     m_list = new ArrayList(other.m_list.Count);
     foreach (CryptographicAttributeObject attribute in other.m_list)
     {
         CryptographicAttributeObject attributeCopy = new CryptographicAttributeObject(attribute.Oid);
         foreach (AsnEncodedData encodedData in attribute.Values)
         {
             attributeCopy.Values.Add(new AsnEncodedData(encodedData.Oid, encodedData.RawData));
         }
         m_list.Add(attributeCopy);
     }
 }
        public int Add(CryptographicAttributeObject attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }
            string strA = null;

            if (attribute.Oid != null)
            {
                strA = attribute.Oid.Value;
            }
            for (int i = 0; i < this.m_list.Count; i++)
            {
                CryptographicAttributeObject obj2 = (CryptographicAttributeObject)this.m_list[i];
                if (obj2.Values == attribute.Values)
                {
                    throw new InvalidOperationException(SecurityResources.GetResourceString("InvalidOperation_DuplicateItemNotAllowed"));
                }
                string strB = null;
                if (obj2.Oid != null)
                {
                    strB = obj2.Oid.Value;
                }
                if ((strA == null) && (strB == null))
                {
                    AsnEncodedDataEnumerator enumerator = attribute.Values.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        AsnEncodedData current = enumerator.Current;
                        obj2.Values.Add(current);
                    }
                    return(i);
                }
                if (((strA != null) && (strB != null)) && (string.Compare(strA, strB, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    if (string.Compare(strA, "1.2.840.113549.1.9.5", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Pkcs9_MultipleSigningTimeNotAllowed"));
                    }
                    AsnEncodedDataEnumerator enumerator2 = attribute.Values.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        AsnEncodedData asnEncodedData = enumerator2.Current;
                        obj2.Values.Add(asnEncodedData);
                    }
                    return(i);
                }
            }
            return(this.m_list.Add(attribute));
        }
 public int Add(CryptographicAttributeObject attribute)
 {
     if (attribute == null)
     {
         throw new ArgumentNullException("attribute");
     }
     string strA = null;
     if (attribute.Oid != null)
     {
         strA = attribute.Oid.Value;
     }
     for (int i = 0; i < this.m_list.Count; i++)
     {
         CryptographicAttributeObject obj2 = (CryptographicAttributeObject) this.m_list[i];
         if (obj2.Values == attribute.Values)
         {
             throw new InvalidOperationException(SecurityResources.GetResourceString("InvalidOperation_DuplicateItemNotAllowed"));
         }
         string strB = null;
         if (obj2.Oid != null)
         {
             strB = obj2.Oid.Value;
         }
         if ((strA == null) && (strB == null))
         {
             AsnEncodedDataEnumerator enumerator = attribute.Values.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 AsnEncodedData current = enumerator.Current;
                 obj2.Values.Add(current);
             }
             return i;
         }
         if (((strA != null) && (strB != null)) && (string.Compare(strA, strB, StringComparison.OrdinalIgnoreCase) == 0))
         {
             if (string.Compare(strA, "1.2.840.113549.1.9.5", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Pkcs9_MultipleSigningTimeNotAllowed"));
             }
             AsnEncodedDataEnumerator enumerator2 = attribute.Values.GetEnumerator();
             while (enumerator2.MoveNext())
             {
                 AsnEncodedData asnEncodedData = enumerator2.Current;
                 obj2.Values.Add(asnEncodedData);
             }
             return i;
         }
     }
     return this.m_list.Add(attribute);
 }
 private void Reset(uint originatorChoice, uint version, System.Security.Cryptography.CAPI.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO encryptedKeyInfo, uint subIndex)
 {
     this.m_encryptedKeyInfo = encryptedKeyInfo;
     this.m_originatorChoice = originatorChoice;
     this.m_version = (int) version;
     this.m_originatorIdentifier = null;
     this.m_userKeyMaterial = new byte[0];
     this.m_encryptionAlgorithm = null;
     this.m_recipientIdentifier = null;
     this.m_encryptedKey = new byte[0];
     this.m_date = DateTime.MinValue;
     this.m_otherKeyAttribute = null;
     this.m_subIndex = subIndex;
 }
コード例 #16
0
        public int Add(CryptographicAttributeObject attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            //
            // Merge with existing attribute, if already existed, else add as new.
            //
            string szOid1 = attribute.Oid.Value;

            for (int index = 0; index < _list.Count; index++)
            {
                CryptographicAttributeObject existing = _list[index];

                // To prevent caller to add the existing item into the collection again
                // Otherwise the merge will be an infinite loop
                if (object.ReferenceEquals(existing.Values, attribute.Values))
                {
                    throw new InvalidOperationException(SR.InvalidOperation_DuplicateItemNotAllowed);
                }

                string szOid2 = existing.Oid.Value;
                if (string.Equals(szOid1, szOid2, StringComparison.OrdinalIgnoreCase))
                {
                    //
                    // Only allow one signing time, per RFC.
                    //
                    if (string.Equals(szOid1, Oids.SigningTime, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new CryptographicException(SR.Cryptography_Pkcs9_MultipleSigningTimeNotAllowed);
                    }

                    foreach (AsnEncodedData asnEncodedData in attribute.Values)
                    {
                        existing.Values.Add(asnEncodedData);
                    }
                    return(index);
                }
            }

            int indexOfNewItem = _list.Count;

            _list.Add(attribute);
            return(indexOfNewItem);
        }
コード例 #17
0
        public int Add(CryptographicAttributeObject attribute)
        {
            if (attribute == null)
                throw new ArgumentNullException(nameof(attribute));

            //
            // Merge with existing attribute, if already existed, else add as new.
            //
            string szOid1 = attribute.Oid.Value;
            for (int index = 0; index < _list.Count; index++)
            {
                CryptographicAttributeObject existing = _list[index];

                // To prevent caller to add the existing item into the collection again
                // Otherwise the merge will be an infinite loop
                if (object.ReferenceEquals(existing.Values, attribute.Values))
                    throw new InvalidOperationException(SR.InvalidOperation_DuplicateItemNotAllowed);

                string szOid2 = existing.Oid.Value;
                if (string.Equals(szOid1, szOid2, StringComparison.OrdinalIgnoreCase))
                {
                    //
                    // Only allow one signing time, per RFC.
                    //
                    if (string.Equals(szOid1, Oids.SigningTime, StringComparison.OrdinalIgnoreCase))
                        throw new CryptographicException(SR.Cryptography_Pkcs9_MultipleSigningTimeNotAllowed);

                    foreach (AsnEncodedData asnEncodedData in attribute.Values)
                    {
                        existing.Values.Add(asnEncodedData);
                    }
                    return index;
                }
            }

            int indexOfNewItem = _list.Count;
            _list.Add(attribute);
            return indexOfNewItem;
        }
コード例 #18
0
		public int Add (CryptographicAttributeObject attribute)
		{
			if (attribute == null)
				throw new ArgumentNullException ("attribute");

			int existing = -1;
			string oid = attribute.Oid.Value;
			for (int i=0; i < _list.Count; i++) {
				if ((_list[i] as CryptographicAttributeObject).Oid.Value == oid) {
					existing = i;
					break;
				}
			}
			if (existing >= 0) {
				CryptographicAttributeObject cao = this[existing];
				foreach (AsnEncodedData value in attribute.Values) {
					cao.Values.Add (value);
				}
				return existing;
			} else {
				return _list.Add (attribute);
			}
		}
コード例 #19
0
 public CryptographicAttributeObjectCollection(CryptographicAttributeObject attribute)
 {
     m_list = new ArrayList();
     m_list.Add(attribute);
 }
コード例 #20
0
		public void Remove (CryptographicAttributeObject attribute) 
		{
			_list.Remove (attribute);
		}
コード例 #21
0
		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));
			}
		}
コード例 #22
0
 public CryptographicAttributeObjectCollection(CryptographicAttributeObject attribute)
     : this()
 {
     _list.Add(attribute);
 }
コード例 #23
0
        public void CopyTo(CryptographicAttributeObject[] array, int index)
        {
            if (array == null)
                throw new ArgumentNullException(nameof(array));
            if (index < 0 || index >= array.Length)
                throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
            if (index > array.Length - Count)
                throw new ArgumentException(SR.Argument_InvalidOffLen);

            _list.CopyTo(array, index);
        }
コード例 #24
0
		public void ConstructorOidAsnEncodedDataCollectionNull ()
		{
			Oid o = new Oid (defaultOid);
			AsnEncodedDataCollection coll = null;
			CryptographicAttributeObject ca = new CryptographicAttributeObject (o, coll);
			Assert.AreEqual (defaultName, ca.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (defaultOid, ca.Oid.Value, "Oid.Value");
			Assert.AreEqual (0, ca.Values.Count, "Values");
		}
コード例 #25
0
 public CryptographicAttributeObjectCollection(CryptographicAttributeObject attribute)
 {
     _list = new List <CryptographicAttributeObject>();
     _list.Add(attribute);
 }
コード例 #26
0
 public static void CryptographicAttributeObjectPassNullValuesToCtor()
 {
     Oid oid = new Oid(Oids.DocumentDescription);
     // This is legal and equivalent to passing a zero-length AsnEncodedDataCollection.
     CryptographicAttributeObject cao = new CryptographicAttributeObject(oid, null);
     Assert.Equal(oid.Value, cao.Oid.Value);
     Assert.Equal(0, cao.Values.Count);
 }
 public CryptographicAttributeObjectCollection(CryptographicAttributeObject attribute)
 {
     this.m_list = new ArrayList();
     this.m_list.Add(attribute);
 }
コード例 #28
0
		public void Remove_WithDifferentInstance ()
		{
			Oid o = new Oid (defaultOid);
			CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
			CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);

			Assert.AreEqual (1, coll.Count, "before Remove");
			cao = new CryptographicAttributeObject (o);
			coll.Remove (cao);
			Assert.AreEqual (1, coll.Count, "after Remove");
		}
 public void Remove(CryptographicAttributeObject attribute)
 {
     if (attribute == null)
     {
         throw new ArgumentNullException("attribute");
     }
     this.m_list.Remove(attribute);
 }
 public void CopyTo(CryptographicAttributeObject[] array, int index)
 {
     ((ICollection) this).CopyTo(array, index);
 }
コード例 #31
0
		public void ConstructorOidNullCollection ()
		{
			AsnEncodedDataCollection coll = new AsnEncodedDataCollection ();
			CryptographicAttributeObject ca = new CryptographicAttributeObject (null, coll);
		}
コード例 #32
0
        public int Add(CryptographicAttributeObject attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            //
            // Merge with exisitng attribute, if already existed, else add as new.
            //

            string szOid1 = null;

            if (attribute.Oid != null)
            {
                szOid1 = attribute.Oid.Value;
            }

            for (int index = 0; index < m_list.Count; index++)
            {
                CryptographicAttributeObject existing = (CryptographicAttributeObject)m_list[index];

                // To prevent caller to add the existing item into the collection again
                // Otherwise the merge will be an infinite loop
                if ((Object)existing.Values == (Object)attribute.Values)
                {
                    throw new InvalidOperationException(SecurityResources.GetResourceString("InvalidOperation_DuplicateItemNotAllowed"));
                }

                // Merge either:
                // 1. both OIDs are null, or
                // 2. both not null and OIDs match.
                string szOid2 = null;
                if (existing.Oid != null)
                {
                    szOid2 = existing.Oid.Value;
                }

                if (szOid1 == null && szOid2 == null)
                {
                    foreach (AsnEncodedData asnEncodedData in attribute.Values)
                    {
                        existing.Values.Add(asnEncodedData);
                    }
                    return(index);
                }

                if ((szOid1 != null && szOid2 != null) && (String.Compare(szOid1, szOid2, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    //
                    // Only allow one signing time, per RFC.
                    //

                    if (String.Compare(szOid1, CAPI.szOID_RSA_signingTime, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Pkcs9_MultipleSigningTimeNotAllowed"));
                    }

                    foreach (AsnEncodedData asnEncodedData in attribute.Values)
                    {
                        existing.Values.Add(asnEncodedData);
                    }
                    return(index);
                }
            }

            return(m_list.Add(attribute));
        }
コード例 #33
0
		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");
		}
コード例 #34
0
 public static void CryptographicAttributeObjectOidCtor()
 {
     Oid oid = new Oid(Oids.DocumentDescription);
     CryptographicAttributeObject cao = new CryptographicAttributeObject(oid);
     Assert.Equal(oid.Value, cao.Oid.Value);
     Assert.Equal(0, cao.Values.Count);
 }
コード例 #35
0
		public CryptographicAttributeObjectCollection (CryptographicAttributeObject attribute)
			: this ()
		{
			_list.Add (attribute);
		}
コード例 #36
0
        public static void CryptographicAttributeObjectMismatch()
        {
            Oid oid = new Oid(Oids.DocumentDescription);
            Oid wrongOid = new Oid(Oids.DocumentName);

            AsnEncodedDataCollection col = new AsnEncodedDataCollection();
            col.Add(new AsnEncodedData(oid, new byte[3]));

            object ignore;
            Assert.Throws<InvalidOperationException>(() => ignore = new CryptographicAttributeObject(wrongOid, col));
        }
コード例 #37
0
		public void ConstructorOidNull () 
		{
			CryptographicAttributeObject ca = new CryptographicAttributeObject (null);
		}
コード例 #38
0
 public CryptographicAttributeObjectCollection(CryptographicAttributeObject attribute)
 {
     _list = new List<CryptographicAttributeObject>();
     _list.Add(attribute);
 }
コード例 #39
0
		public void CopyTo (CryptographicAttributeObject[] array, int index)
		{
			_list.CopyTo (array, index);
		}
コード例 #40
0
        public int Add (CryptographicAttributeObject attribute) {
            if (attribute == null)
                throw new ArgumentNullException("attribute");

            //
            // Merge with exisitng attribute, if already existed, else add as new.
            //

            string szOid1 = null;
            if (attribute.Oid != null)
                szOid1 = attribute.Oid.Value;

            for (int index = 0; index < m_list.Count; index++) {
                CryptographicAttributeObject existing = (CryptographicAttributeObject) m_list[index];

                // To prevent caller to add the existing item into the collection again
                // Otherwise the merge will be an infinite loop
                if ((Object) existing.Values == (Object) attribute.Values)
                    throw new InvalidOperationException(SecurityResources.GetResourceString("InvalidOperation_DuplicateItemNotAllowed"));

                // Merge either:
                // 1. both OIDs are null, or
                // 2. both not null and OIDs match.
                string szOid2 = null;
                if (existing.Oid != null)
                    szOid2 = existing.Oid.Value;

                if (szOid1 == null && szOid2 == null) {
                    foreach (AsnEncodedData asnEncodedData in attribute.Values) {
                        existing.Values.Add(asnEncodedData);
                    }
                    return index;
                }

                if ((szOid1 != null && szOid2 != null) && (String.Compare(szOid1, szOid2, StringComparison.OrdinalIgnoreCase) == 0)) {
                    //
                    // Only allow one signing time, per RFC.
                    //

                    if (String.Compare(szOid1, CAPI.szOID_RSA_signingTime, StringComparison.OrdinalIgnoreCase) == 0)
                        throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Pkcs9_MultipleSigningTimeNotAllowed"));

                    foreach (AsnEncodedData asnEncodedData in attribute.Values) {
                        existing.Values.Add(asnEncodedData);
                    }
                    return index;
                }
            }

            return m_list.Add(attribute);
        }
コード例 #41
0
 internal void AddWithoutMerge(CryptographicAttributeObject attribute)
 {
     Debug.Assert(attribute != null);
     _list.Add(attribute);
 }