1 package org.bouncycastle.asn1.x9;
2 
3 import org.bouncycastle.asn1.ASN1Choice;
4 import org.bouncycastle.asn1.ASN1Null;
5 import org.bouncycastle.asn1.ASN1Object;
6 import org.bouncycastle.asn1.ASN1ObjectIdentifier;
7 import org.bouncycastle.asn1.ASN1Primitive;
8 import org.bouncycastle.asn1.ASN1TaggedObject;
9 
10 public class X962Parameters
11     extends ASN1Object
12     implements ASN1Choice
13 {
14     private ASN1Primitive           params = null;
15 
getInstance( Object obj)16     public static X962Parameters getInstance(
17         Object obj)
18     {
19         if (obj == null || obj instanceof X962Parameters)
20         {
21             return (X962Parameters)obj;
22         }
23 
24         if (obj instanceof ASN1Primitive)
25         {
26             return new X962Parameters((ASN1Primitive)obj);
27         }
28 
29         throw new IllegalArgumentException("unknown object in getInstance()");
30     }
31 
getInstance( ASN1TaggedObject obj, boolean explicit)32     public static X962Parameters getInstance(
33         ASN1TaggedObject obj,
34         boolean          explicit)
35     {
36         return getInstance(obj.getObject()); // must be explicitly tagged
37     }
38 
X962Parameters( X9ECParameters ecParameters)39     public X962Parameters(
40         X9ECParameters      ecParameters)
41     {
42         this.params = ecParameters.toASN1Primitive();
43     }
44 
X962Parameters( ASN1ObjectIdentifier namedCurve)45     public X962Parameters(
46         ASN1ObjectIdentifier  namedCurve)
47     {
48         this.params = namedCurve;
49     }
50 
X962Parameters( ASN1Primitive obj)51     public X962Parameters(
52         ASN1Primitive           obj)
53     {
54         this.params = obj;
55     }
56 
isNamedCurve()57     public boolean isNamedCurve()
58     {
59         return (params instanceof ASN1ObjectIdentifier);
60     }
61 
isImplicitlyCA()62     public boolean isImplicitlyCA()
63     {
64         return (params instanceof ASN1Null);
65     }
66 
getParameters()67     public ASN1Primitive getParameters()
68     {
69         return params;
70     }
71 
72     /**
73      * Produce an object suitable for an ASN1OutputStream.
74      * <pre>
75      * Parameters ::= CHOICE {
76      *    ecParameters ECParameters,
77      *    namedCurve   CURVES.&amp;id({CurveNames}),
78      *    implicitlyCA NULL
79      * }
80      * </pre>
81      */
toASN1Primitive()82     public ASN1Primitive toASN1Primitive()
83     {
84         return (ASN1Primitive)params;
85     }
86 }
87