Inheritance: Org.BouncyCastle.Asn1.Asn1Encodable, IAsn1Choice
Ejemplo n.º 1
0
 public BiometricData(TypeOfBiometricData typeOfBiometricData, AlgorithmIdentifier hashAlgorithm, Asn1OctetString biometricDataHash)
 {
     this.typeOfBiometricData = typeOfBiometricData;
     this.hashAlgorithm       = hashAlgorithm;
     this.biometricDataHash   = biometricDataHash;
     this.sourceDataUri       = null;
 }
        private void CheckValues(
            BiometricData       bd,
            TypeOfBiometricData dataType,
            AlgorithmIdentifier algID,
            Asn1OctetString     dataHash,
            DerIA5String        sourceDataURI)
        {
            if (!bd.TypeOfBiometricData.Equals(dataType))
            {
                Fail("types don't match.");
            }

            if (!bd.HashAlgorithm.Equals(algID))
            {
                Fail("hash algorithms don't match.");
            }

            if (!bd.BiometricDataHash.Equals(dataHash))
            {
                Fail("hash algorithms don't match.");
            }

            if (sourceDataURI != null)
            {
                if (!bd.SourceDataUri.Equals(sourceDataURI))
                {
                    Fail("data uris don't match.");
                }
            }
            else if (bd.SourceDataUri != null)
            {
                Fail("data uri found when none expected.");
            }
        }
		public override void PerformTest()
        {
            TypeOfBiometricData dataType = new TypeOfBiometricData(TypeOfBiometricData.HandwrittenSignature);
            AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1, DerNull.Instance);
            Asn1OctetString     dataHash = new DerOctetString(GenerateHash());
            BiometricData       bd = new BiometricData(dataType, hashAlgorithm, dataHash);

            CheckConstruction(bd, dataType, hashAlgorithm, dataHash, null);

            DerIA5String dataUri = new DerIA5String("http://test");

            bd = new BiometricData(dataType, hashAlgorithm, dataHash, dataUri);

            CheckConstruction(bd, dataType, hashAlgorithm, dataHash, dataUri);

            bd = BiometricData.GetInstance(null);

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

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

                Fail("GetInstance() failed to detect bad object.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
Ejemplo n.º 4
0
 public BiometricData(
     TypeOfBiometricData	typeOfBiometricData,
     AlgorithmIdentifier	hashAlgorithm,
     Asn1OctetString		biometricDataHash)
 {
     this.typeOfBiometricData = typeOfBiometricData;
     this.hashAlgorithm = hashAlgorithm;
     this.biometricDataHash = biometricDataHash;
     this.sourceDataUri = null;
 }
Ejemplo n.º 5
0
 private BiometricData(Asn1Sequence seq)
 {
     this.typeOfBiometricData = TypeOfBiometricData.GetInstance(seq[0]);
     this.hashAlgorithm       = AlgorithmIdentifier.GetInstance(seq[1]);
     this.biometricDataHash   = Asn1OctetString.GetInstance(seq[2]);
     if (seq.Count > 3)
     {
         this.sourceDataUri = DerIA5String.GetInstance(seq[3]);
     }
 }
Ejemplo n.º 6
0
		private BiometricData(
			Asn1Sequence seq)
        {
			typeOfBiometricData = TypeOfBiometricData.GetInstance(seq[0]);
			hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
			biometricDataHash = Asn1OctetString.GetInstance(seq[2]);

			if (seq.Count > 3)
			{
				sourceDataUri = DerIA5String.GetInstance(seq[3]);
			}
        }
        private void CheckConstruction(
            BiometricData bd,
            TypeOfBiometricData dataType,
            AlgorithmIdentifier hashAlgorithm,
            Asn1OctetString dataHash,
            DerIA5String dataUri)
        {
            CheckValues(bd, dataType, hashAlgorithm, dataHash, dataUri);

            bd = BiometricData.GetInstance(bd);

            CheckValues(bd, dataType, hashAlgorithm, dataHash, dataUri);

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

			bd = BiometricData.GetInstance(seq);

			CheckValues(bd, dataType, hashAlgorithm, dataHash, dataUri);
        }
		private void CheckPredefinedType(
            int predefinedType)
        {
            TypeOfBiometricData type = new TypeOfBiometricData(predefinedType);

            CheckPredefined(type, predefinedType);

            type = TypeOfBiometricData.GetInstance(type);

			CheckPredefined(type, predefinedType);

			Asn1Object obj = Asn1Object.FromByteArray(type.ToAsn1Object().GetEncoded());

			type = TypeOfBiometricData.GetInstance(obj);

			CheckPredefined(type, predefinedType);
        }
		public override void PerformTest()
        {
            //
            // predefined
            //
            CheckPredefinedType(TypeOfBiometricData.Picture);

            CheckPredefinedType(TypeOfBiometricData.HandwrittenSignature);

			//
            // non-predefined
            //
            DerObjectIdentifier localType = new DerObjectIdentifier("1.1");

			TypeOfBiometricData type = new TypeOfBiometricData(localType);

			CheckNonPredefined(type, localType);

            type = TypeOfBiometricData.GetInstance(type);

            CheckNonPredefined(type, localType);

            Asn1Object obj = type.ToAsn1Object();

            type = TypeOfBiometricData.GetInstance(obj);

            CheckNonPredefined(type, localType);

            type = TypeOfBiometricData.GetInstance(null);

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

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

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

            try
            {
                new TypeOfBiometricData(100);

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

			// Call Equals to avoid unreachable code warning
            if (!Equals(TypeOfBiometricData.Picture, 0))
            {
                Fail("predefined picture should be 0");
            }

			// Call Equals to avoid unreachable code warning
			if (!Equals(TypeOfBiometricData.HandwrittenSignature, 1))
			{
                Fail("predefined handwritten signature should be 1");
            }
        }
		private void CheckNonPredefined(
            TypeOfBiometricData type,
            DerObjectIdentifier val)
        {
            if (type.IsPredefined)
            {
                Fail("predefined type found when not expected.");
            }

			if (!type.BiometricDataOid.Equals(val))
            {
                Fail("data oid does not match.");
            }
        }
		private void CheckPredefined(
            TypeOfBiometricData	type,
            int					val)
        {
            if (!type.IsPredefined)
            {
                Fail("predefined type expected but not found.");
            }

			if (type.PredefinedBiometricType != val)
            {
                Fail("predefined type does not match.");
            }
        }