01: package org.bouncycastle.asn1.x9;
02:
03: import org.bouncycastle.asn1.ASN1Choice;
04: import org.bouncycastle.asn1.ASN1Encodable;
05: import org.bouncycastle.asn1.ASN1Null;
06: import org.bouncycastle.asn1.ASN1TaggedObject;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09:
10: public class X962Parameters extends ASN1Encodable implements ASN1Choice {
11: private DERObject params = null;
12:
13: public static X962Parameters getInstance(Object obj) {
14: if (obj == null || obj instanceof X962Parameters) {
15: return (X962Parameters) obj;
16: }
17:
18: if (obj instanceof DERObject) {
19: return new X962Parameters((DERObject) obj);
20: }
21:
22: throw new IllegalArgumentException(
23: "unknown object in getInstance()");
24: }
25:
26: public static X962Parameters getInstance(ASN1TaggedObject obj,
27: boolean explicit) {
28: return getInstance(obj.getObject()); // must be explicitly tagged
29: }
30:
31: public X962Parameters(X9ECParameters ecParameters) {
32: this .params = ecParameters.getDERObject();
33: }
34:
35: public X962Parameters(DERObjectIdentifier namedCurve) {
36: this .params = namedCurve;
37: }
38:
39: public X962Parameters(DERObject obj) {
40: this .params = obj;
41: }
42:
43: public boolean isNamedCurve() {
44: return (params instanceof DERObjectIdentifier);
45: }
46:
47: public boolean isImplicitlyCA() {
48: return (params instanceof ASN1Null);
49: }
50:
51: public DERObject getParameters() {
52: return params;
53: }
54:
55: /**
56: * Produce an object suitable for an ASN1OutputStream.
57: * <pre>
58: * Parameters ::= CHOICE {
59: * ecParameters ECParameters,
60: * namedCurve CURVES.&id({CurveNames}),
61: * implicitlyCA NULL
62: * }
63: * </pre>
64: */
65: public DERObject toASN1Object() {
66: return params;
67: }
68: }
|