public override void PerformTest()
		{
			DerUtf8String contentDescription = new DerUtf8String("Description");
			DerObjectIdentifier contentType = new DerObjectIdentifier("1.2.2.3");

			ContentHints hints = new ContentHints(contentType);

			checkConstruction(hints, contentType, null);

			hints = new ContentHints(contentType, contentDescription);

			checkConstruction(hints, contentType, contentDescription);

			hints = ContentHints.GetInstance(null);

			if (hints != null)
			{
				Fail("null GetInstance() failed.");
			}

			try
			{
				ContentHints.GetInstance(new Object());

				Fail("GetInstance() failed to detect bad object.");
			}
			catch (ArgumentException)
			{
				// expected
			}
		}
		public ContentHints(
			DerObjectIdentifier	contentType,
			DerUtf8String		contentDescription)
		{
			this.contentType = contentType;
			this.contentDescription = contentDescription;
		}
Exemple #3
0
 public object[] GetValues()
 {
     if (ValueType == 1)
     {
         Asn1OctetString[] array = new Asn1OctetString[values.Count];
         for (int i = 0; i != array.Length; i++)
         {
             array[i] = (Asn1OctetString)values[i];
         }
         return(array);
     }
     if (ValueType == 2)
     {
         DerObjectIdentifier[] array2 = new DerObjectIdentifier[values.Count];
         for (int j = 0; j != array2.Length; j++)
         {
             array2[j] = (DerObjectIdentifier)values[j];
         }
         return(array2);
     }
     DerUtf8String[] array3 = new DerUtf8String[values.Count];
     for (int k = 0; k != array3.Length; k++)
     {
         array3[k] = (DerUtf8String)values[k];
     }
     return(array3);
 }
		public ITestResult Perform()
		{
			try
			{
				for (int i = 0; i < glyphs_utf16.Length; i++)
				{
					string s = new string(glyphs_utf16[i]);
					byte[] b1 = new DerUtf8String(s).GetEncoded();
					byte[] temp = new byte[b1.Length - 2];
					Array.Copy(b1, 2, temp, 0, b1.Length - 2);
					byte[] b2 = new DerUtf8String(new DerOctetString(temp).GetOctets()).GetEncoded();
					if (!Arrays.AreEqual(b1, b2))
					{
						return new SimpleTestResult(false, Name + ": failed UTF-8 encoding and decoding");
					}
					if (!Arrays.AreEqual(temp, glyphs_utf8[i]))
					{
						return new SimpleTestResult(false, Name + ": failed UTF-8 encoding and decoding");
					}
				}
			}
			catch (Exception e)
			{
				return new SimpleTestResult(false, Name + ": failed with Exception " + e.Message);
			}

			return new SimpleTestResult(true, Name + ": Okay");
		}
Exemple #5
0
        public SignerLocation(
            DerUtf8String countryName,
            DerUtf8String localityName,
            Asn1Sequence postalAddress)
        {
            if (postalAddress != null && postalAddress.Count > 6)
            {
                throw new ArgumentException("postal address must contain less than 6 strings");
            }

            if (countryName != null)
            {
                this.countryName = DerUtf8String.GetInstance(countryName.ToAsn1Object());
            }

            if (localityName != null)
            {
                this.localityName = DerUtf8String.GetInstance(localityName.ToAsn1Object());
            }

            if (postalAddress != null)
            {
                this.postalAddress = (Asn1Sequence)postalAddress.ToAsn1Object();
            }
        }
Exemple #6
0
 public ContentHints(
     DerObjectIdentifier contentType,
     DerUtf8String contentDescription)
 {
     this.contentType        = contentType;
     this.contentDescription = contentDescription;
 }
Exemple #7
0
        private static Asn1Encodable EncodeDnEntry(DnEntry dnEntry)
        {
            DerObjectIdentifier type  = new DerObjectIdentifier(dnEntry.Definition.Oid);
            Asn1Encodable       value = null;

            switch (dnEntry.Definition.ValueType)
            {
            case DnEntryValueType.PrintableString:
                value = new DerPrintableString(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            case DnEntryValueType.UniversalString:
                value = new DerUniversalString(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            case DnEntryValueType.Utf8String:
                value = new DerUtf8String(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            case DnEntryValueType.BmpString:
                value = new DerBmpString(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            default:
                // TODO - Does BC support DnEntryValueType.TeletexString ???
                throw new Exception("Unsupported type of DnEntry value");
            }

            return(new DerSet(new DerSequence(type, value)));
        }
Exemple #8
0
        public SignerLocation(
            Asn1Sequence seq)
        {
            foreach (Asn1TaggedObject obj in seq)
            {
                switch (obj.TagNo)
                {
                case 0:
                    this.countryName = DerUtf8String.GetInstance(obj, true);
                    break;

                case 1:
                    this.localityName = DerUtf8String.GetInstance(obj, true);
                    break;

                case 2:
                    bool isExplicit = obj.IsExplicit();                                 // handle erroneous implicitly tagged sequences
                    this.postalAddress = Asn1Sequence.GetInstance(obj, isExplicit);
                    if (postalAddress != null && postalAddress.Count > 6)
                    {
                        throw new ArgumentException("postal address must contain less than 6 strings");
                    }
                    break;

                default:
                    throw new ArgumentException("illegal tag");
                }
            }
        }
Exemple #9
0
 public MetaData(DerBoolean hashProtected, DerUtf8String fileName, DerIA5String mediaType, Attributes otherMetaData)
 {
     this.hashProtected = hashProtected;
     this.fileName      = fileName;
     this.mediaType     = mediaType;
     this.otherMetaData = otherMetaData;
 }
Exemple #10
0
 public SignerLocation(
     DerUtf8String countryName,
     DerUtf8String localityName,
     Asn1Sequence postalAddress)
     : this(DirectoryString.GetInstance(countryName), DirectoryString.GetInstance(localityName), postalAddress)
 {
 }
Exemple #11
0
        public SignerLocation(Asn1Sequence seq)
        {
            foreach (Asn1TaggedObject asn1TaggedObject in seq)
            {
                switch (asn1TaggedObject.TagNo)
                {
                case 0:
                    this.countryName = DerUtf8String.GetInstance(asn1TaggedObject, true);
                    break;

                case 1:
                    this.localityName = DerUtf8String.GetInstance(asn1TaggedObject, true);
                    break;

                case 2:
                {
                    bool explicitly = asn1TaggedObject.IsExplicit();
                    this.postalAddress = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly);
                    if (this.postalAddress != null && this.postalAddress.Count > 6)
                    {
                        throw new ArgumentException("postal address must contain less than 6 strings");
                    }
                    break;
                }

                default:
                    throw new ArgumentException("illegal tag");
                }
            }
        }
        public override void PerformTest()
        {
            DerUtf8String       contentDescription = new DerUtf8String("Description");
            DerObjectIdentifier contentType        = new DerObjectIdentifier("1.2.2.3");

            ContentHints hints = new ContentHints(contentType);

            checkConstruction(hints, contentType, null);

            hints = new ContentHints(contentType, contentDescription);

            checkConstruction(hints, contentType, contentDescription);

            hints = ContentHints.GetInstance(null);

            if (hints != null)
            {
                Fail("null GetInstance() failed.");
            }

            try
            {
                ContentHints.GetInstance(new Object());

                Fail("GetInstance() failed to detect bad object.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
        public ITestResult Perform()
        {
            try
            {
                for (int i = 0; i < glyphs_utf16.Length; i++)
                {
                    string s    = new string(glyphs_utf16[i]);
                    byte[] b1   = new DerUtf8String(s).GetEncoded();
                    byte[] temp = new byte[b1.Length - 2];
                    Array.Copy(b1, 2, temp, 0, b1.Length - 2);
                    byte[] b2 = new DerUtf8String(new DerOctetString(temp).GetOctets()).GetEncoded();
                    if (!Arrays.AreEqual(b1, b2))
                    {
                        return(new SimpleTestResult(false, Name + ": failed UTF-8 encoding and decoding"));
                    }
                    if (!Arrays.AreEqual(temp, glyphs_utf8[i]))
                    {
                        return(new SimpleTestResult(false, Name + ": failed UTF-8 encoding and decoding"));
                    }
                }
            }
            catch (Exception e)
            {
                return(new SimpleTestResult(false, Name + ": failed with Exception " + e.Message));
            }

            return(new SimpleTestResult(true, Name + ": Okay"));
        }
Exemple #14
0
 private void checkValues(
     ContentHints hints,
     DerObjectIdentifier contentType,
     DerUtf8String description)
 {
     checkMandatoryField("contentType", contentType, hints.ContentType);
     checkOptionalField("description", description, hints.ContentDescription);
 }
		private void checkValues(
			ContentHints		hints,
			DerObjectIdentifier	contentType,
			DerUtf8String		description)
		{
			checkMandatoryField("contentType", contentType, hints.ContentType);
			checkOptionalField("description", description, hints.ContentDescription);
		}
Exemple #16
0
 public EsPropertyInfo(DerInteger type, DerUtf8String name, Asn1Sequence certList, DerUtcTime createDate, DerUtcTime validStart, DerUtcTime validEnd)
 {
     Type       = type;
     Name       = name;
     CertList   = certList;
     CreateDate = createDate;
     ValidStart = validStart;
     ValidEnd   = validEnd;
 }
Exemple #17
0
    protected override bool Asn1Equals(Asn1Object asn1Object)
    {
        DerUtf8String derUtf8String = asn1Object as DerUtf8String;

        if (derUtf8String == null)
        {
            return(false);
        }
        return(str.Equals(derUtf8String.str));
    }
Exemple #18
0
        /// <summary>
        /// Método para crear el atributo que contiene el rol del firmante
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private BcCms.Attribute MakeSignerAttrAttribute(SignatureParameters parameters)
        {
            DerUtf8String[] roles = new DerUtf8String[1];
            roles[0] = new DerUtf8String(parameters.SignerRole);

            BcCms.Attribute claimedRolesAttr = new BcCms.Attribute(X509ObjectIdentifiers.id_at_name, new DerSet(roles));

            return(new BcCms.Attribute(PkcsObjectIdentifiers.IdAAEtsSignerAttr, new DerSet(new SignerAttribute
                                                                                               (new DerSequence(claimedRolesAttr)))));
        }
Exemple #19
0
		public MetaData(
			DerBoolean		hashProtected,
			DerUtf8String	fileName,
			DerIA5String	mediaType,
			Attributes		otherMetaData)
		{
			this.hashProtected = hashProtected;
			this.fileName = fileName;
			this.mediaType = mediaType;
			this.otherMetaData = otherMetaData;
		}
Exemple #20
0
        public EsPropertyInfo(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            Type       = DerInteger.GetInstance(e.Next());
            Name       = DerUtf8String.GetInstance(e.Next());
            CertList   = Asn1Sequence.GetInstance(e.Next());
            CreateDate = DerUtcTime.GetInstance(e.Next());
            ValidStart = DerUtcTime.GetInstance(e.Next());
            ValidEnd   = DerUtcTime.GetInstance(e.Next());
        }
        private ContentHints(Asn1Sequence seq)
        {
            IAsn1Convertible asn1Convertible = seq[0];

            if (asn1Convertible.ToAsn1Object() is DerUtf8String)
            {
                this.contentDescription = DerUtf8String.GetInstance(asn1Convertible);
                this.contentType        = DerObjectIdentifier.GetInstance(seq[1]);
                return;
            }
            this.contentType = DerObjectIdentifier.GetInstance(seq[0]);
        }
Exemple #22
0
        public SesPropertyInfo(Asn1Sequence sequence)
        {
            IEnumerator e = sequence.GetEnumerator();

            Type         = DerInteger.GetInstance(e.Next());
            Name         = DerUtf8String.GetInstance(e.Next());
            CertListType = DerInteger.GetInstance(e.Next());
            CertList     = SesCertCollect.GetInstance(CertListType, e.Next());
            CreateDate   = DerGeneralizedTime.GetInstance(e.Next());
            ValidStart   = DerGeneralizedTime.GetInstance(e.Next());
            ValidEnd     = DerGeneralizedTime.GetInstance(e.Next());
        }
		/**
		 * constructor
		 */
		private ContentHints(
			Asn1Sequence seq)
		{
			IAsn1Convertible field = seq[0];
			if (field.ToAsn1Object() is DerUtf8String)
			{
				contentDescription = DerUtf8String.GetInstance(field);
				contentType = DerObjectIdentifier.GetInstance(seq[1]);
			}
			else
			{
				contentType = DerObjectIdentifier.GetInstance(seq[0]);
			}
		}
Exemple #24
0
        /**
         * constructor
         */
        private ContentHints(
            Asn1Sequence seq)
        {
            IAsn1Convertible field = seq[0];

            if (field.ToAsn1Object() is DerUtf8String)
            {
                contentDescription = DerUtf8String.GetInstance(field);
                contentType        = DerObjectIdentifier.GetInstance(seq[1]);
            }
            else
            {
                contentType = DerObjectIdentifier.GetInstance(seq[0]);
            }
        }
Exemple #25
0
 public SesPropertyInfo(DerInteger type,
                        DerUtf8String name,
                        DerInteger certListType,
                        SesCertCollect certList,
                        DerGeneralizedTime createDate,
                        DerGeneralizedTime validStart,
                        DerGeneralizedTime validEnd)
 {
     Type         = type;
     Name         = name;
     CertList     = certList;
     CertListType = certListType;
     CreateDate   = createDate;
     ValidEnd     = validEnd;
     ValidStart   = validStart;
 }
        public SignerLocation(Asn1Sequence seq)
        {
            //IL_0086: Unknown result type (might be due to invalid IL or missing references)
            //IL_0091: Unknown result type (might be due to invalid IL or missing references)
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)enumerator.get_Current();
                    switch (asn1TaggedObject.TagNo)
                    {
                    case 0:
                        countryName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 1:
                        localityName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 2:
                    {
                        bool explicitly = asn1TaggedObject.IsExplicit();
                        postalAddress = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly);
                        if (postalAddress != null && postalAddress.Count > 6)
                        {
                            throw new ArgumentException("postal address must contain less than 6 strings");
                        }
                        break;
                    }

                    default:
                        throw new ArgumentException("illegal tag");
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Exemple #27
0
        private MetaData(Asn1Sequence seq)
        {
            hashProtected = DerBoolean.GetInstance(seq[0]);
            int num = 1;

            if (num < seq.Count && seq[num] is DerUtf8String)
            {
                fileName = DerUtf8String.GetInstance(seq[num++]);
            }
            if (num < seq.Count && seq[num] is DerIA5String)
            {
                mediaType = DerIA5String.GetInstance(seq[num++]);
            }
            if (num < seq.Count)
            {
                otherMetaData = Attributes.GetInstance(seq[num++]);
            }
        }
Exemple #28
0
        private void checkConstruction(
            ContentHints hints,
            DerObjectIdentifier contentType,
            DerUtf8String description)
        {
            checkValues(hints, contentType, description);

            hints = ContentHints.GetInstance(hints);

            checkValues(hints, contentType, description);

            Asn1InputStream aIn = new Asn1InputStream(hints.ToAsn1Object().GetEncoded());

            Asn1Sequence seq = (Asn1Sequence)aIn.ReadObject();

            hints = ContentHints.GetInstance(seq);

            checkValues(hints, contentType, description);
        }
Exemple #29
0
        private MetaData(Asn1Sequence seq)
        {
            this.hashProtected = DerBoolean.GetInstance(seq[0]);

            int index = 1;

            if (index < seq.Count && seq[index] is DerUtf8String)
            {
                this.fileName = DerUtf8String.GetInstance(seq[index++]);
            }
            if (index < seq.Count && seq[index] is DerIA5String)
            {
                this.mediaType = DerIA5String.GetInstance(seq[index++]);
            }
            if (index < seq.Count)
            {
                this.otherMetaData = Attributes.GetInstance(seq[index++]);
            }
        }
        private void CheckConstruction(
            SignerLocation sl,
            DerUtf8String countryName,
            DerUtf8String localityName,
            Asn1Sequence postalAddress)
        {
            CheckValues(sl, countryName, localityName, postalAddress);

            sl = SignerLocation.GetInstance(sl);

            CheckValues(sl, countryName, localityName, postalAddress);

            Asn1Sequence seq = (Asn1Sequence)Asn1Object.FromByteArray(
                sl.ToAsn1Object().GetEncoded());

            sl = SignerLocation.GetInstance(seq);

            CheckValues(sl, countryName, localityName, postalAddress);
        }
		private void checkConstruction(
			ContentHints		hints,
			DerObjectIdentifier	contentType,
			DerUtf8String		description)
		{
			checkValues(hints, contentType, description);

			hints = ContentHints.GetInstance(hints);

			checkValues(hints, contentType, description);

			Asn1InputStream aIn = new Asn1InputStream(hints.ToAsn1Object().GetEncoded());

			Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject();

			hints = ContentHints.GetInstance(seq);

			checkValues(hints, contentType, description);
		}
Exemple #32
0
		private MetaData(Asn1Sequence seq)
		{
			this.hashProtected = DerBoolean.GetInstance(seq[0]);

			int index = 1;

			if (index < seq.Count && seq[index] is DerUtf8String)
			{
				this.fileName = DerUtf8String.GetInstance(seq[index++]);
			}
			if (index < seq.Count && seq[index] is DerIA5String)
			{
				this.mediaType = DerIA5String.GetInstance(seq[index++]);
			}
			if (index < seq.Count)
			{
				this.otherMetaData = Attributes.GetInstance(seq[index++]);
			}
		}
        private void CheckValues(
            SignerLocation sl,
            DerUtf8String countryName,
            DerUtf8String localityName,
            Asn1Sequence postalAddress)
        {
            if (countryName != null)
            {
                if (!countryName.Equals(sl.CountryName))
                {
                    Fail("countryNames don't match.");
                }
            }
            else if (sl.CountryName != null)
            {
                Fail("countryName found when none expected.");
            }

            if (localityName != null)
            {
                if (!localityName.Equals(sl.LocalityName))
                {
                    Fail("localityNames don't match.");
                }
            }
            else if (sl.LocalityName != null)
            {
                Fail("localityName found when none expected.");
            }

            if (postalAddress != null)
            {
                if (!postalAddress.Equals(sl.PostalAddress))
                {
                    Fail("postalAddresses don't match.");
                }
            }
            else if (sl.PostalAddress != null)
            {
                Fail("postalAddress found when none expected.");
            }
        }
 public SignerLocation(DerUtf8String countryName, DerUtf8String localityName, Asn1Sequence postalAddress)
 {
     //IL_0017: Unknown result type (might be due to invalid IL or missing references)
     if (postalAddress != null && postalAddress.Count > 6)
     {
         throw new ArgumentException("postal address must contain less than 6 strings");
     }
     if (countryName != null)
     {
         this.countryName = DerUtf8String.GetInstance(countryName.ToAsn1Object());
     }
     if (localityName != null)
     {
         this.localityName = DerUtf8String.GetInstance(localityName.ToAsn1Object());
     }
     if (postalAddress != null)
     {
         this.postalAddress = (Asn1Sequence)postalAddress.ToAsn1Object();
     }
 }
        internal CertificateTrustBlock(byte[] encoded)
        {
            Asn1Sequence seq = Asn1Sequence.GetInstance(encoded);

            for (IEnumerator en = seq.GetEnumerator(); en.MoveNext();)
            {
                Asn1Encodable obj = (Asn1Encodable)en.Current;

                if (obj is Asn1Sequence)
                {
                    this.uses = Asn1Sequence.GetInstance(obj);
                }
                else if (obj is Asn1TaggedObject)
                {
                    this.prohibitions = Asn1Sequence.GetInstance((Asn1TaggedObject)obj, false);
                }
                else if (obj is DerUtf8String)
                {
                    this.alias = DerUtf8String.GetInstance(obj).GetString();
                }
            }
        }
Exemple #36
0
        /// <summary>
        /// Return a control value of the specified type.
        /// </summary>
        /// <param name="type">the type OID for the control value we are checking for.</param>
        /// <returns>the control value if present, null otherwise.</returns>
        public IControl GetControl(DerObjectIdentifier type)
        {
            AttributeTypeAndValue found = FindControl(type);

            if (found != null)
            {
                if (found.Type.Equals(CrmfObjectIdentifiers.id_regCtrl_pkiArchiveOptions))
                {
                    return(new PkiArchiveControl(PkiArchiveOptions.GetInstance(found.Value)));
                }

                if (found.Type.Equals(CrmfObjectIdentifiers.id_regCtrl_regToken))
                {
                    return(new RegTokenControl(DerUtf8String.GetInstance(found.Value)));
                }

                if (found.Type.Equals(CrmfObjectIdentifiers.id_regCtrl_authenticator))
                {
                    return(new AuthenticatorControl(DerUtf8String.GetInstance(found.Value)));
                }
            }
            return(null);
        }
Exemple #37
0
        public object[] GetValues()
        {
            if (this.ValueType == ValueOctets)
            {
                Asn1OctetString[] tmp = new Asn1OctetString[values.Count];

                for (int i = 0; i != tmp.Length; i++)
                {
                    tmp[i] = (Asn1OctetString)values[i];
                }

                return(tmp);
            }

            if (this.ValueType == ValueOid)
            {
                DerObjectIdentifier[] tmp = new DerObjectIdentifier[values.Count];

                for (int i = 0; i != tmp.Length; i++)
                {
                    tmp[i] = (DerObjectIdentifier)values[i];
                }

                return(tmp);
            }

            {
                DerUtf8String[] tmp = new DerUtf8String[values.Count];

                for (int i = 0; i != tmp.Length; i++)
                {
                    tmp[i] = (DerUtf8String)values[i];
                }

                return(tmp);
            }
        }
Exemple #38
0
 public EncKeyWithID(PrivateKeyInfo privKeyInfo, DerUtf8String str)
 {
     this.privKeyInfo = privKeyInfo;
     this.identifier  = str;
 }
Exemple #39
0
		public PkiFreeText(
			DerUtf8String p)
		{
			strings = new DerSequence(p);
		}
 public EncKeyWithID(PrivateKeyInfo privKeyInfo, DerUtf8String str)
 {
     this.privKeyInfo = privKeyInfo;
     this.identifier = str;
 }
Exemple #41
0
		public override void PerformTest()
		{
			doTestEncodingPrintableString(X509Name.C, "AU");
			doTestEncodingPrintableString(X509Name.SerialNumber, "123456");
			doTestEncodingPrintableString(X509Name.DnQualifier, "123456");
			doTestEncodingIA5String(X509Name.EmailAddress, "*****@*****.**");
			doTestEncodingIA5String(X509Name.DC, "test");
			// correct encoding
			doTestEncodingGeneralizedTime(X509Name.DateOfBirth, "#180F32303032303132323132323232305A");
			// compatability encoding
			doTestEncodingGeneralizedTime(X509Name.DateOfBirth, "20020122122220Z");

			//
			// composite
			//
			IDictionary attrs = new Hashtable();
			attrs.Add(X509Name.C, "AU");
			attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
			attrs.Add(X509Name.L, "Melbourne");
			attrs.Add(X509Name.ST, "Victoria");
			attrs.Add(X509Name.E, "*****@*****.**");

			IList order = new ArrayList();
			order.Add(X509Name.C);
			order.Add(X509Name.O);
			order.Add(X509Name.L);
			order.Add(X509Name.ST);
			order.Add(X509Name.E);

			X509Name name1 = new X509Name(order, attrs);

			if (!name1.Equivalent(name1))
			{
				Fail("Failed same object test");
			}

			if (!name1.Equivalent(name1, true))
			{
				Fail("Failed same object test - in Order");
			}

			X509Name name2 = new X509Name(order, attrs);

			if (!name1.Equivalent(name2))
			{
				Fail("Failed same name test");
			}

			if (!name1.Equivalent(name2, true))
			{
				Fail("Failed same name test - in Order");
			}

			if (name1.GetHashCode() != name2.GetHashCode())
			{
				Fail("Failed same name test - in Order");
			}

			IList ord1 = new ArrayList();

			ord1.Add(X509Name.C);
			ord1.Add(X509Name.O);
			ord1.Add(X509Name.L);
			ord1.Add(X509Name.ST);
			ord1.Add(X509Name.E);

			IList ord2 = new ArrayList();

			ord2.Add(X509Name.E);
			ord2.Add(X509Name.ST);
			ord2.Add(X509Name.L);
			ord2.Add(X509Name.O);
			ord2.Add(X509Name.C);

			name1 = new X509Name(ord1, attrs);
			name2 = new X509Name(ord2, attrs);

			if (!name1.Equivalent(name2))
			{
				Fail("Failed reverse name test");
			}

			// FIXME Sort out X509Name hashcode problem
//			if (name1.GetHashCode() != name2.GetHashCode())
//			{
//				Fail("Failed reverse name test GetHashCode");
//			}

			if (name1.Equivalent(name2, true))
			{
				Fail("Failed reverse name test - in Order");
			}

			if (!name1.Equivalent(name2, false))
			{
				Fail("Failed reverse name test - in Order false");
			}

			IList oids = name1.GetOidList();
			if (!CompareVectors(oids, ord1))
			{
				Fail("oid comparison test");
			}

			IList val1 = new ArrayList();

			val1.Add("AU");
			val1.Add("The Legion of the Bouncy Castle");
			val1.Add("Melbourne");
			val1.Add("Victoria");
			val1.Add("*****@*****.**");

			name1 = new X509Name(ord1, val1);

			IList values = name1.GetValueList();
			if (!CompareVectors(values, val1))
			{
				Fail("value comparison test");
			}

			ord2 = new ArrayList();

			ord2.Add(X509Name.ST);
			ord2.Add(X509Name.ST);
			ord2.Add(X509Name.L);
			ord2.Add(X509Name.O);
			ord2.Add(X509Name.C);

			name1 = new X509Name(ord1, attrs);
			name2 = new X509Name(ord2, attrs);

			if (name1.Equivalent(name2))
			{
				Fail("Failed different name test");
			}

			ord2 = new ArrayList();

			ord2.Add(X509Name.ST);
			ord2.Add(X509Name.L);
			ord2.Add(X509Name.O);
			ord2.Add(X509Name.C);

			name1 = new X509Name(ord1, attrs);
			name2 = new X509Name(ord2, attrs);

			if (name1.Equivalent(name2))
			{
				Fail("Failed subset name test");
			}


			compositeTest();


			//
			// getValues test
			//
			ArrayList v1 = name1.GetValues(X509Name.O);

			if (v1.Count != 1 || !v1[0].Equals("The Legion of the Bouncy Castle"))
			{
				Fail("O test failed");
			}

			ArrayList v2 = name1.GetValues(X509Name.L);

			if (v2.Count != 1 || !v2[0].Equals("Melbourne"))
			{
				Fail("L test failed");
			}

			//
			// general subjects test
			//
			for (int i = 0; i != subjects.Length; i++)
			{
				X509Name name = new X509Name(subjects[i]);
				byte[] encodedName = name.GetEncoded();
				name = X509Name.GetInstance(Asn1Object.FromByteArray(encodedName));

				if (!name.ToString().Equals(subjects[i]))
				{
					Fail("Failed regeneration test " + i);
				}
			}

			//
			// sort test
			//
			X509Name unsorted = new X509Name("SERIALNUMBER=BBB + CN=AA");

			if (!FromBytes(unsorted.GetEncoded()).ToString().Equals("CN=AA+SERIALNUMBER=BBB"))
			{
				Fail("Failed sort test 1");
			}

			unsorted = new X509Name("CN=AA + SERIALNUMBER=BBB");

			if (!FromBytes(unsorted.GetEncoded()).ToString().Equals("CN=AA+SERIALNUMBER=BBB"))
			{
				Fail("Failed sort test 2");
			}

			unsorted = new X509Name("SERIALNUMBER=B + CN=AA");

			if (!FromBytes(unsorted.GetEncoded()).ToString().Equals("SERIALNUMBER=B+CN=AA"))
			{
				Fail("Failed sort test 3");
			}

			unsorted = new X509Name("CN=AA + SERIALNUMBER=B");

			if (!FromBytes(unsorted.GetEncoded()).ToString().Equals("SERIALNUMBER=B+CN=AA"))
			{
				Fail("Failed sort test 4");
			}

			//
			// equality tests
			//
			equalityTest(new X509Name("CN=The     Legion"), new X509Name("CN=The Legion"));
			equalityTest(new X509Name("CN=   The Legion"), new X509Name("CN=The Legion"));
			equalityTest(new X509Name("CN=The Legion   "), new X509Name("CN=The Legion"));
			equalityTest(new X509Name("CN=  The     Legion "), new X509Name("CN=The Legion"));
			equalityTest(new X509Name("CN=  the     legion "), new X509Name("CN=The Legion"));

			// # test

			X509Name n1 = new X509Name("SERIALNUMBER=8,O=ABC,CN=ABC Class 3 CA,C=LT");
			X509Name n2 = new X509Name("2.5.4.5=8,O=ABC,CN=ABC Class 3 CA,C=LT");
			X509Name n3 = new X509Name("2.5.4.5=#130138,O=ABC,CN=ABC Class 3 CA,C=LT");

			equalityTest(n1, n2);
			equalityTest(n2, n3);
			equalityTest(n3, n1);

			n1 = new X509Name(true, "2.5.4.5=#130138,CN=SSC Class 3 CA,O=UAB Skaitmeninio sertifikavimo centras,C=LT");
			n2 = new X509Name(true, "SERIALNUMBER=#130138,CN=SSC Class 3 CA,O=UAB Skaitmeninio sertifikavimo centras,C=LT");
			n3 = X509Name.GetInstance(Asn1Object.FromByteArray(Hex.Decode("3063310b3009060355040613024c54312f302d060355040a1326"
				+ "55414220536b6169746d656e696e696f20736572746966696b6176696d6f2063656e74726173311730150603550403130e53534320436c6173732033204341310a30080603550405130138")));

			equalityTest(n1, n2);
			equalityTest(n2, n3);
			equalityTest(n3, n1);

			n1 = new X509Name("SERIALNUMBER=8,O=XX,CN=ABC Class 3 CA,C=LT");
			n2 = new X509Name("2.5.4.5=8,O=,CN=ABC Class 3 CA,C=LT");

			if (n1.Equivalent(n2))
			{
				Fail("empty inequality check failed");
			}

			n1 = new X509Name("SERIALNUMBER=8,O=,CN=ABC Class 3 CA,C=LT");
			n2 = new X509Name("2.5.4.5=8,O=,CN=ABC Class 3 CA,C=LT");

			equalityTest(n1, n2);

			//
			// inequality to sequences
			//
			name1 = new X509Name("CN=The Legion");

			if (name1.Equals(DerSequence.Empty))
			{
				Fail("inequality test with sequence");
			}

			if (name1.Equals(new DerSequence(DerSet.Empty)))
			{
				Fail("inequality test with sequence and set");
			}

			Asn1EncodableVector v = new Asn1EncodableVector(
				new DerObjectIdentifier("1.1"),
				new DerObjectIdentifier("1.1"));

			if (name1.Equals(new DerSequence(new DerSet(new DerSet(v)))))
			{
				Fail("inequality test with sequence and bad set");
			}

//			if (name1.Equals(new DerSequence(new DerSet(new DerSet(v))), true))
//			{
//				Fail("inequality test with sequence and bad set");
//			}
			try
			{
				X509Name.GetInstance(new DerSequence(new DerSet(new DerSet(v))));
				Fail("GetInstance should reject bad sequence");
			}
			catch (ArgumentException)
			{
				//expected
			}

			if (name1.Equals(new DerSequence(new DerSet(DerSequence.Empty))))
			{
				Fail("inequality test with sequence and short sequence");
			}

//			if (name1.Equals(new DerSequence(new DerSet(DerSequence.Empty)), true))
//			{
//				Fail("inequality test with sequence and short sequence");
//			}
			try
			{
				X509Name.GetInstance(new DerSequence(new DerSet(DerSequence.Empty)));
				Fail("GetInstance should reject short sequence");
			}
			catch (ArgumentException)
			{
				//expected
			}

			v = new Asn1EncodableVector(
				new DerObjectIdentifier("1.1"),
				DerSequence.Empty);

			if (name1.Equals(new DerSequence(new DerSet(new DerSequence(v)))))
			{
				Fail("inequality test with sequence and bad sequence");
			}

			if (name1.Equivalent(null))
			{
				Fail("inequality test with null");
			}

			if (name1.Equivalent(null, true))
			{
				Fail("inequality test with null");
			}

			//
			// this is contrived but it checks sorting of sets with equal elements
			//
			unsorted = new X509Name("CN=AA + CN=AA + CN=AA");

			//
			// tagging test - only works if CHOICE implemented
			//
			/*
			ASN1TaggedObject tag = new DERTaggedObject(false, 1, new X509Name("CN=AA"));

			if (!tag.isExplicit())
			{
				Fail("failed to explicitly tag CHOICE object");
			}

			X509Name name = X509Name.getInstance(tag, false);

			if (!name.equals(new X509Name("CN=AA")))
			{
				Fail("failed to recover tagged name");
			}
			*/

			DerUtf8String testString = new DerUtf8String("The Legion of the Bouncy Castle");
			byte[] encodedBytes = testString.GetEncoded();
			string hexEncodedString = "#" + Hex.ToHexString(encodedBytes);

			DerUtf8String converted = (DerUtf8String)
				new X509DefaultEntryConverter().GetConvertedValue(
				X509Name.L , hexEncodedString);

			if (!converted.Equals(testString))
			{
				Fail("Failed X509DefaultEntryConverter test");
			}

			//
			// try escaped.
			//
			converted = (DerUtf8String) new X509DefaultEntryConverter().GetConvertedValue(
				X509Name.L , "\\" + hexEncodedString);

			if (!converted.Equals(new DerUtf8String(hexEncodedString)))
			{
				Fail("Failed X509DefaultEntryConverter test got " + converted + " expected: " + hexEncodedString);
			}

			//
			// try a weird value
			//
			X509Name n = new X509Name("CN=\\#nothex#string");

			if (!n.ToString().Equals("CN=\\#nothex#string"))
			{
				Fail("# string not properly escaped.");
			}

			ArrayList vls = n.GetValues(X509Name.CN);
			if (vls.Count != 1 || !vls[0].Equals("#nothex#string"))
			{
				Fail("Escaped # not reduced properly");
			}

			n = new X509Name("CN=\"a+b\"");

			vls = n.GetValues(X509Name.CN);
			if (vls.Count != 1 || !vls[0].Equals("a+b"))
			{
				Fail("Escaped + not reduced properly");
			}

			n = new X509Name("CN=a\\+b");

			vls = n.GetValues(X509Name.CN);
			if (vls.Count != 1 || !vls[0].Equals("a+b"))
			{
				Fail("Escaped + not reduced properly");
			}

			if (!n.ToString().Equals("CN=a\\+b"))
			{
				Fail("+ in string not properly escaped.");
			}

			n = new X509Name("CN=a\\=b");

			vls = n.GetValues(X509Name.CN);
			if (vls.Count != 1 || !vls[0].Equals("a=b"))
			{
				Fail("Escaped = not reduced properly");
			}

			if (!n.ToString().Equals("CN=a\\=b"))
			{
				Fail("= in string not properly escaped.");
			}

	        n = new X509Name("TELEPHONENUMBER=\"+61999999999\"");

	        vls = n.GetValues(X509Name.TelephoneNumber);
	        if (vls.Count != 1 || !vls[0].Equals("+61999999999"))
	        {
	            Fail("telephonenumber escaped + not reduced properly");
	        }

	        n = new X509Name("TELEPHONENUMBER=\\+61999999999");

	        vls = n.GetValues(X509Name.TelephoneNumber);
	        if (vls.Count != 1 || !vls[0].Equals("+61999999999"))
	        {
	            Fail("telephonenumber escaped + not reduced properly");
	        }

	        n = new X509Name(@"TELEPHONENUMBER=\+61999999999");

	        vls = n.GetValues(X509Name.TelephoneNumber);
	        if (vls.Count != 1 || !vls[0].Equals("+61999999999"))
	        {
	            Fail("telephonenumber escaped + not reduced properly");
	        }
		}
		public ContentHints(
			DerObjectIdentifier contentType)
		{
			this.contentType = contentType;
			this.contentDescription = null;
		}