1package org.bouncycastle.asn1.x509.qualified;
2
3import org.bouncycastle.asn1.ASN1Choice;
4import org.bouncycastle.asn1.ASN1Encodable;
5import org.bouncycastle.asn1.DEREncodable;
6import org.bouncycastle.asn1.DERInteger;
7import org.bouncycastle.asn1.DERObject;
8import org.bouncycastle.asn1.DERObjectIdentifier;
9
10/**
11 * The TypeOfBiometricData object.
12 * <pre>
13 * TypeOfBiometricData ::= CHOICE {
14 *   predefinedBiometricType   PredefinedBiometricType,
15 *   biometricDataOid          OBJECT IDENTIFIER }
16 *
17 * PredefinedBiometricType ::= INTEGER {
18 *   picture(0),handwritten-signature(1)}
19 *   (picture|handwritten-signature)
20 * </pre>
21 */
22public class TypeOfBiometricData
23    extends ASN1Encodable
24    implements ASN1Choice
25{
26    public static final int PICTURE                     = 0;
27    public static final int HANDWRITTEN_SIGNATURE       = 1;
28
29    DEREncodable      obj;
30
31    public static TypeOfBiometricData getInstance(Object obj)
32    {
33        if (obj == null || obj instanceof TypeOfBiometricData)
34        {
35            return (TypeOfBiometricData)obj;
36        }
37
38        if (obj instanceof DERInteger)
39        {
40            DERInteger predefinedBiometricTypeObj = DERInteger.getInstance(obj);
41            int  predefinedBiometricType = predefinedBiometricTypeObj.getValue().intValue();
42
43            return new TypeOfBiometricData(predefinedBiometricType);
44        }
45        else if (obj instanceof DERObjectIdentifier)
46        {
47            DERObjectIdentifier BiometricDataID = DERObjectIdentifier.getInstance(obj);
48            return new TypeOfBiometricData(BiometricDataID);
49        }
50
51        throw new IllegalArgumentException("unknown object in getInstance");
52    }
53
54    public TypeOfBiometricData(int predefinedBiometricType)
55    {
56        if (predefinedBiometricType == PICTURE || predefinedBiometricType == HANDWRITTEN_SIGNATURE)
57        {
58                obj = new DERInteger(predefinedBiometricType);
59        }
60        else
61        {
62            throw new IllegalArgumentException("unknow PredefinedBiometricType : " + predefinedBiometricType);
63        }
64    }
65
66    public TypeOfBiometricData(DERObjectIdentifier BiometricDataID)
67    {
68        obj = BiometricDataID;
69    }
70
71    public boolean isPredefined()
72    {
73        return obj instanceof DERInteger;
74    }
75
76    public int getPredefinedBiometricType()
77    {
78        return ((DERInteger)obj).getValue().intValue();
79    }
80
81    public DERObjectIdentifier getBiometricDataOid()
82    {
83        return (DERObjectIdentifier)obj;
84    }
85
86    public DERObject toASN1Object()
87    {
88        return obj.getDERObject();
89    }
90}
91