001package org.apache.commons.ssl.org.bouncycastle.asn1.x9; 002 003import java.util.Enumeration; 004import java.util.Vector; 005 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier; 007import org.apache.commons.ssl.org.bouncycastle.asn1.nist.NISTNamedCurves; 008import org.apache.commons.ssl.org.bouncycastle.asn1.sec.SECNamedCurves; 009import org.apache.commons.ssl.org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves; 010 011/** 012 * A general class that reads all X9.62 style EC curve tables. 013 */ 014public class ECNamedCurveTable 015{ 016 /** 017 * return a X9ECParameters object representing the passed in named 018 * curve. The routine returns null if the curve is not present. 019 * 020 * @param name the name of the curve requested 021 * @return an X9ECParameters object or null if the curve is not available. 022 */ 023 public static X9ECParameters getByName( 024 String name) 025 { 026 X9ECParameters ecP = X962NamedCurves.getByName(name); 027 028 if (ecP == null) 029 { 030 ecP = SECNamedCurves.getByName(name); 031 } 032 033 if (ecP == null) 034 { 035 ecP = TeleTrusTNamedCurves.getByName(name); 036 } 037 038 if (ecP == null) 039 { 040 ecP = NISTNamedCurves.getByName(name); 041 } 042 043 return ecP; 044 } 045 046 /** 047 * return the object identifier signified by the passed in name. Null 048 * if there is no object identifier associated with name. 049 * 050 * @return the object identifier associated with name, if present. 051 */ 052 public static ASN1ObjectIdentifier getOID( 053 String name) 054 { 055 ASN1ObjectIdentifier oid = X962NamedCurves.getOID(name); 056 057 if (oid == null) 058 { 059 oid = SECNamedCurves.getOID(name); 060 } 061 062 if (oid == null) 063 { 064 oid = TeleTrusTNamedCurves.getOID(name); 065 } 066 067 if (oid == null) 068 { 069 oid = NISTNamedCurves.getOID(name); 070 } 071 072 return oid; 073 } 074 075 /** 076 * return a X9ECParameters object representing the passed in named 077 * curve. 078 * 079 * @param oid the object id of the curve requested 080 * @return an X9ECParameters object or null if the curve is not available. 081 */ 082 public static X9ECParameters getByOID( 083 ASN1ObjectIdentifier oid) 084 { 085 X9ECParameters ecP = X962NamedCurves.getByOID(oid); 086 087 if (ecP == null) 088 { 089 ecP = SECNamedCurves.getByOID(oid); 090 } 091 092 if (ecP == null) 093 { 094 ecP = TeleTrusTNamedCurves.getByOID(oid); 095 } 096 097 // NOTE: All the NIST curves are currently from SEC, so no point in redundant OID lookup 098 099 return ecP; 100 } 101 102 /** 103 * return an enumeration of the names of the available curves. 104 * 105 * @return an enumeration of the names of the available curves. 106 */ 107 public static Enumeration getNames() 108 { 109 Vector v = new Vector(); 110 111 addEnumeration(v, X962NamedCurves.getNames()); 112 addEnumeration(v, SECNamedCurves.getNames()); 113 addEnumeration(v, NISTNamedCurves.getNames()); 114 addEnumeration(v, TeleTrusTNamedCurves.getNames()); 115 116 return v.elements(); 117 } 118 119 private static void addEnumeration( 120 Vector v, 121 Enumeration e) 122 { 123 while (e.hasMoreElements()) 124 { 125 v.addElement(e.nextElement()); 126 } 127 } 128}