001: package org.bouncycastle.asn1.x509.qualified;
002:
003: import java.util.Enumeration;
004:
005: import org.bouncycastle.asn1.ASN1Encodable;
006: import org.bouncycastle.asn1.ASN1OctetString;
007: import org.bouncycastle.asn1.ASN1Sequence;
008: import org.bouncycastle.asn1.ASN1EncodableVector;
009: import org.bouncycastle.asn1.DERIA5String;
010: import org.bouncycastle.asn1.DERObject;
011: import org.bouncycastle.asn1.DERSequence;
012: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
013:
014: /**
015: * The BiometricData object.
016: * <pre>
017: * BiometricData ::= SEQUENCE {
018: * typeOfBiometricData TypeOfBiometricData,
019: * hashAlgorithm AlgorithmIdentifier,
020: * biometricDataHash OCTET STRING,
021: * sourceDataUri IA5String OPTIONAL }
022: * </pre>
023: */
024: public class BiometricData extends ASN1Encodable {
025: TypeOfBiometricData typeOfBiometricData;
026: AlgorithmIdentifier hashAlgorithm;
027: ASN1OctetString biometricDataHash;
028: DERIA5String sourceDataUri;
029:
030: public static BiometricData getInstance(Object obj) {
031: if (obj == null || obj instanceof BiometricData) {
032: return (BiometricData) obj;
033: }
034:
035: if (obj instanceof ASN1Sequence) {
036: return new BiometricData(ASN1Sequence.getInstance(obj));
037: } else {
038: throw new IllegalArgumentException(
039: "unknown object in getInstance");
040: }
041: }
042:
043: public BiometricData(ASN1Sequence seq) {
044: Enumeration e = seq.getObjects();
045:
046: // typeOfBiometricData
047: typeOfBiometricData = TypeOfBiometricData.getInstance(e
048: .nextElement());
049: // hashAlgorithm
050: hashAlgorithm = AlgorithmIdentifier
051: .getInstance(e.nextElement());
052: // biometricDataHash
053: biometricDataHash = ASN1OctetString
054: .getInstance(e.nextElement());
055: // sourceDataUri
056: if (e.hasMoreElements()) {
057: sourceDataUri = DERIA5String.getInstance(e.nextElement());
058: }
059: }
060:
061: public BiometricData(TypeOfBiometricData typeOfBiometricData,
062: AlgorithmIdentifier hashAlgorithm,
063: ASN1OctetString biometricDataHash,
064: DERIA5String sourceDataUri) {
065: this .typeOfBiometricData = typeOfBiometricData;
066: this .hashAlgorithm = hashAlgorithm;
067: this .biometricDataHash = biometricDataHash;
068: this .sourceDataUri = sourceDataUri;
069: }
070:
071: public BiometricData(TypeOfBiometricData typeOfBiometricData,
072: AlgorithmIdentifier hashAlgorithm,
073: ASN1OctetString biometricDataHash) {
074: this .typeOfBiometricData = typeOfBiometricData;
075: this .hashAlgorithm = hashAlgorithm;
076: this .biometricDataHash = biometricDataHash;
077: this .sourceDataUri = null;
078: }
079:
080: public TypeOfBiometricData getTypeOfBiometricData() {
081: return typeOfBiometricData;
082: }
083:
084: public AlgorithmIdentifier getHashAlgorithm() {
085: return hashAlgorithm;
086: }
087:
088: public ASN1OctetString getBiometricDataHash() {
089: return biometricDataHash;
090: }
091:
092: public DERIA5String getSourceDataUri() {
093: return sourceDataUri;
094: }
095:
096: public DERObject toASN1Object() {
097: ASN1EncodableVector seq = new ASN1EncodableVector();
098: seq.add(typeOfBiometricData);
099: seq.add(hashAlgorithm);
100: seq.add(biometricDataHash);
101:
102: if (sourceDataUri != null) {
103: seq.add(sourceDataUri);
104: }
105:
106: return new DERSequence(seq);
107: }
108: }
|