Inheritance: DerStringBase
示例#1
0
        public SignerLocation(
			Asn1Sequence seq)
        {
            foreach (DerTaggedObject o in seq)
            {
                switch (o.TagNo)
                {
                    case 0:
                        this.countryName = DerUtf8String.GetInstance(o, true);
                        break;
                    case 1:
                        this.localityName = DerUtf8String.GetInstance(o, true);
                        break;
                    case 2:
                        bool isExplicit = o.IsExplicit();	// handle erroneous implicitly tagged sequences
                        this.postalAddress = Asn1Sequence.GetInstance(o, 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");
                }
            }
        }
		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();
			}
		}
示例#3
0
        public static DerUtf8String GetInstance(Asn1TaggedObject obj, bool isExplicit)
        {
            Asn1Object @object = obj.GetObject();

            if (isExplicit || @object is DerUtf8String)
            {
                return(DerUtf8String.GetInstance(@object));
            }
            return(new DerUtf8String(Asn1OctetString.GetInstance(@object).GetOctets()));
        }
示例#4
0
        protected override bool Asn1Equals(Asn1Object asn1Object)
        {
            DerUtf8String derUtf8String = asn1Object as DerUtf8String;

            if (derUtf8String == null)
            {
                return(false);
            }
            return(str.Equals(derUtf8String.str));
        }
        protected override bool Asn1Equals(Asn1Object asn1Object)
        {
            DerUtf8String str = asn1Object as DerUtf8String;

            if (str == null)
            {
                return(false);
            }
            return(this.str.Equals(str.str));
        }
        protected override bool Asn1Equals(
            Asn1Object obj)
        {
            DerUtf8String other = obj as DerUtf8String;

            if (other == null)
            {
                return(false);
            }

            return(this.str.Equals(other.str));
        }
示例#7
0
        protected override bool Asn1Equals(Asn1Object asn1Object)
        {
            DerUtf8String derUtf8String = asn1Object as DerUtf8String;

            return(derUtf8String != null && this.str.Equals(derUtf8String.str));
        }
示例#8
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;
			}
        }
		public override void PerformTest()
        {
            DerUtf8String countryName = new DerUtf8String("Australia");

            SignerLocation sl = new SignerLocation(countryName, null, null);

            CheckConstruction(sl, countryName, null, null);

            DerUtf8String localityName = new DerUtf8String("Melbourne");

            sl = new SignerLocation(null, localityName, null);

			CheckConstruction(sl, null, localityName, null);

			sl = new SignerLocation(countryName, localityName, null);

			CheckConstruction(sl, countryName, localityName, null);

			Asn1Sequence postalAddress = new DerSequence(
				new DerUtf8String("line 1"),
				new DerUtf8String("line 2"));

            sl = new SignerLocation(null, null, postalAddress);

            CheckConstruction(sl, null, null, postalAddress);

            sl = new SignerLocation(countryName, null, postalAddress);

            CheckConstruction(sl, countryName, null, postalAddress);

            sl = new SignerLocation(countryName, localityName, postalAddress);

            CheckConstruction(sl, countryName, localityName, postalAddress);

            sl = SignerLocation.GetInstance(null);

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

            try
            {
                SignerLocation.GetInstance(new object());

                Fail("GetInstance() failed to detect bad object.");
            }
            catch (ArgumentException)
            {
                // expected
            }

            //
            // out of range postal address
            //
			postalAddress = new DerSequence(
				new DerUtf8String("line 1"),
				new DerUtf8String("line 2"),
				new DerUtf8String("line 3"),
				new DerUtf8String("line 4"),
				new DerUtf8String("line 5"),
				new DerUtf8String("line 6"),
				new DerUtf8String("line 7"));

			try
            {
                new SignerLocation(null, null, postalAddress);

                Fail("constructor failed to detect bad postalAddress.");
            }
            catch (ArgumentException)
            {
                // expected
            }

            try
            {
                new SignerLocation(new DerSequence(new DerTaggedObject(2, postalAddress)));

                Fail("sequence constructor failed to detect bad postalAddress.");
            }
            catch (ArgumentException)
            {
                // expected
            }

            try
            {
                new SignerLocation(new DerSequence(new DerTaggedObject(5, postalAddress)));

                Fail("sequence constructor failed to detect bad tag.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
		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.");
            }
        }
		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);
        }