상속: Org.BouncyCastle.Asn1.Asn1Encodable
예제 #1
0
        private LdsSecurityObject(Asn1Sequence seq)
        {
            if (seq == null || seq.Count == 0)
            {
                throw new ArgumentException("null or empty sequence passed.");
            }
            IEnumerator enumerator = seq.GetEnumerator();

            enumerator.MoveNext();
            this.version = DerInteger.GetInstance(enumerator.Current);
            enumerator.MoveNext();
            this.digestAlgorithmIdentifier = AlgorithmIdentifier.GetInstance(enumerator.Current);
            enumerator.MoveNext();
            Asn1Sequence instance = Asn1Sequence.GetInstance(enumerator.Current);

            if (this.version.Value.Equals(BigInteger.One))
            {
                enumerator.MoveNext();
                this.versionInfo = LdsVersionInfo.GetInstance(enumerator.Current);
            }
            this.CheckDatagroupHashSeqSize(instance.Count);
            this.datagroupHash = new DataGroupHash[instance.Count];
            for (int i = 0; i < instance.Count; i++)
            {
                this.datagroupHash[i] = DataGroupHash.GetInstance(instance[i]);
            }
        }
		public override void PerformTest()
        {
            int dataGroupNumber = 1;
            Asn1OctetString dataHash = new DerOctetString(GenerateHash());
            DataGroupHash dg = new DataGroupHash(dataGroupNumber, dataHash);

            CheckConstruction(dg, dataGroupNumber, dataHash);

			try
			{
				DataGroupHash.GetInstance(null);
			}
			catch (Exception)
			{
				Fail("GetInstance() failed to handle null.");
			}

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

				Fail("GetInstance() failed to detect bad object.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
예제 #3
0
        private LdsSecurityObject(Asn1Sequence seq)
        {
            //IL_0022: Unknown result type (might be due to invalid IL or missing references)
            if (seq == null || seq.Count == 0)
            {
                throw new ArgumentException("null or empty sequence passed.");
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            version = DerInteger.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            digestAlgorithmIdentifier = AlgorithmIdentifier.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            Asn1Sequence instance = Asn1Sequence.GetInstance(enumerator.get_Current());

            if (version.Value.Equals(BigInteger.One))
            {
                enumerator.MoveNext();
                versionInfo = LdsVersionInfo.GetInstance(enumerator.get_Current());
            }
            CheckDatagroupHashSeqSize(instance.Count);
            datagroupHash = new DataGroupHash[instance.Count];
            for (int i = 0; i < instance.Count; i++)
            {
                datagroupHash[i] = DataGroupHash.GetInstance(instance[i]);
            }
        }
        private LdsSecurityObject(
            Asn1Sequence seq)
        {
            if (seq == null || seq.Count == 0)
            {
                throw new ArgumentException("null or empty sequence passed.");
            }

            IEnumerator e = seq.GetEnumerator();

            // version
            e.MoveNext();
            version = DerInteger.GetInstance(e.Current);
            // digestAlgorithmIdentifier
            e.MoveNext();
            digestAlgorithmIdentifier = AlgorithmIdentifier.GetInstance(e.Current);

            e.MoveNext();
            Asn1Sequence datagroupHashSeq = Asn1Sequence.GetInstance(e.Current);

            if (version.HasValue(1))
            {
                e.MoveNext();
                versionInfo = LdsVersionInfo.GetInstance(e.Current);
            }

            CheckDatagroupHashSeqSize(datagroupHashSeq.Count);

            datagroupHash = new DataGroupHash[datagroupHashSeq.Count];
            for (int i = 0; i < datagroupHashSeq.Count; i++)
            {
                datagroupHash[i] = DataGroupHash.GetInstance(datagroupHashSeq[i]);
            }
        }
예제 #5
0
		public LdsSecurityObject(
            AlgorithmIdentifier	digestAlgorithmIdentifier,
            DataGroupHash[]		datagroupHash)
        {
            this.digestAlgorithmIdentifier = digestAlgorithmIdentifier;
            this.datagroupHash = datagroupHash;

			CheckDatagroupHashSeqSize(datagroupHash.Length);
        }
        public LdsSecurityObject(
			AlgorithmIdentifier	digestAlgorithmIdentifier,
			DataGroupHash[]		datagroupHash,
			LdsVersionInfo		versionInfo)
        {
            this.version = new DerInteger(1);
            this.digestAlgorithmIdentifier = digestAlgorithmIdentifier;
            this.datagroupHash = datagroupHash;
            this.versionInfo = versionInfo;

            CheckDatagroupHashSeqSize(datagroupHash.Length);
        }
		private void CheckValues(
            DataGroupHash	dg,
            int				dataGroupNumber,
            Asn1OctetString	dataGroupHashValue)
        {
            if (dg.DataGroupNumber != dataGroupNumber)
            {
                Fail("group number don't match.");
            }

			if (!dg.DataGroupHashValue.Equals(dataGroupHashValue))
            {
                Fail("hash value don't match.");
            }
        }
		private void CheckConstruction(
            DataGroupHash dg,
            int dataGroupNumber,
            Asn1OctetString     dataGroupHashValue)
        {
            CheckValues(dg, dataGroupNumber, dataGroupHashValue);

			dg = DataGroupHash.GetInstance(dg);

			CheckValues(dg, dataGroupNumber, dataGroupHashValue);

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

			dg = DataGroupHash.GetInstance(seq);

			CheckValues(dg, dataGroupNumber, dataGroupHashValue);
        }
        public override void PerformTest()
        {
            AlgorithmIdentifier  algoId = new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1);
            DataGroupHash[] datas = new DataGroupHash[2];

            datas[0] = new DataGroupHash(1, new DerOctetString(GenerateHash()));
            datas[1] = new DataGroupHash(2, new DerOctetString(GenerateHash()));

            LdsSecurityObject so = new LdsSecurityObject(algoId, datas);

			CheckConstruction(so, algoId, datas);

			LdsVersionInfo versionInfo = new LdsVersionInfo("Hello", "world");

			so = new LdsSecurityObject(algoId, datas, versionInfo);

			CheckConstruction(so, algoId, datas, versionInfo);

			try
			{
				LdsSecurityObject.GetInstance(null);
			}
			catch (Exception)
			{
				Fail("GetInstance() failed to handle null.");
			}

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

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

			try
            {
				LdsSecurityObject.GetInstance(DerSequence.Empty);

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

			try
            {
                new LdsSecurityObject(algoId, new DataGroupHash[1]);

				Fail("constructor failed to detect small DataGroupHash array.");
            }
            catch (ArgumentException)
            {
                // expected
            }

			try
            {
                new LdsSecurityObject(algoId, new DataGroupHash[LdsSecurityObject.UBDataGroups + 1]);

				Fail("constructor failed to out of bounds DataGroupHash array.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
		private void CheckStatement(
            LdsSecurityObject	so,
            AlgorithmIdentifier	digestAlgorithmIdentifier,
            DataGroupHash[]		datagroupHash,
			LdsVersionInfo		versionInfo)
        {
            if (digestAlgorithmIdentifier != null)
            {
                if (!so.DigestAlgorithmIdentifier.Equals(digestAlgorithmIdentifier))
                {
                    Fail("ids don't match.");
                }
            }
            else if (so.DigestAlgorithmIdentifier != null)
            {
                Fail("digest algorithm Id found when none expected.");
            }

			if (datagroupHash != null)
            {
                DataGroupHash[] datas = so.GetDatagroupHash();

                for (int i = 0; i != datas.Length; i++)
                {
                    if (!datagroupHash[i].Equals(datas[i]))
                    {
                        Fail("name registration authorities don't match.");
                    }
                }
            }
            else if (so.GetDatagroupHash() != null)
            {
                Fail("data hash groups found when none expected.");
            }

			if (versionInfo != null)
			{
				if (!versionInfo.Equals(so.VersionInfo))
				{
					Fail("versionInfo doesn't match");
				}
			}
			else if (so.VersionInfo != null)
			{
				Fail("version info found when none expected.");
			}
        }
		private void CheckConstruction(
			LdsSecurityObject	so,
			AlgorithmIdentifier	digestAlgorithmIdentifier,
			DataGroupHash[]		datagroupHash,
			LdsVersionInfo		versionInfo)
		{
			if (!so.Version.Equals(BigInteger.One))
			{
				Fail("version number not 1");
			}

			CheckStatement(so, digestAlgorithmIdentifier, datagroupHash, versionInfo);

			so = LdsSecurityObject.GetInstance(so);

			CheckStatement(so, digestAlgorithmIdentifier, datagroupHash, versionInfo);

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

			so = LdsSecurityObject.GetInstance(seq);

			CheckStatement(so, digestAlgorithmIdentifier, datagroupHash, versionInfo);
		}
		private void CheckConstruction(
            LdsSecurityObject	so,
            AlgorithmIdentifier	digestAlgorithmIdentifier,
            DataGroupHash[]		datagroupHash)
        {
            CheckStatement(so, digestAlgorithmIdentifier, datagroupHash, null);

			so = LdsSecurityObject.GetInstance(so);

			CheckStatement(so, digestAlgorithmIdentifier, datagroupHash, null);

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

			so = LdsSecurityObject.GetInstance(seq);

			CheckStatement(so, digestAlgorithmIdentifier, datagroupHash, null);
        }