Esempio n. 1
0
        private void CheckConstruction(
            SignerLocation sl,
            DirectoryString countryName,
            DirectoryString 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);
        }
Esempio n. 2
0
        public override void PerformTest()
        {
            DerUtf8String countryName = new DerUtf8String("Australia");

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

            CheckConstruction(sl, DirectoryString.GetInstance(countryName), null, null);

            DerUtf8String localityName = new DerUtf8String("Melbourne");

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

            CheckConstruction(sl, null, DirectoryString.GetInstance(localityName), null);

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

            CheckConstruction(sl, DirectoryString.GetInstance(countryName), DirectoryString.GetInstance(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, DirectoryString.GetInstance(countryName), null, postalAddress);

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

            CheckConstruction(sl, DirectoryString.GetInstance(countryName), DirectoryString.GetInstance(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
            }
        }