Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2014-03-11 00:44:30 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-03-11 00:44:30 +0400
commitdf07c4638519fbced4171ac0e9d46cd7d3030085 (patch)
treeeb2a1c843b51503e33c031103d226793c582ea9a /core/src/main/java/org/bouncycastle
parent2eb924609525dad448daa893571b18c737c0af8f (diff)
Formatting
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/x500/style/AbstractX500NameStyle.java176
1 files changed, 91 insertions, 85 deletions
diff --git a/core/src/main/java/org/bouncycastle/asn1/x500/style/AbstractX500NameStyle.java b/core/src/main/java/org/bouncycastle/asn1/x500/style/AbstractX500NameStyle.java
index 092e3d77..a411f9ca 100644
--- a/core/src/main/java/org/bouncycastle/asn1/x500/style/AbstractX500NameStyle.java
+++ b/core/src/main/java/org/bouncycastle/asn1/x500/style/AbstractX500NameStyle.java
@@ -5,10 +5,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import org.bouncycastle.asn1.ASN1Encodable;
-import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
-import org.bouncycastle.asn1.DERIA5String;
-import org.bouncycastle.asn1.DERPrintableString;
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.x500.AttributeTypeAndValue;
import org.bouncycastle.asn1.x500.RDN;
@@ -19,70 +16,79 @@ import org.bouncycastle.asn1.x500.X500NameStyle;
* This class provides some default behavior and common implementation for a
* X500NameStyle. It should be easily extendible to support implementing the
* desired X500NameStyle.
- *
*/
-public abstract class AbstractX500NameStyle implements X500NameStyle {
-
- /**
- * Tool function to shallow copy a Hashtable.
- *
- * @param paramsMap table to copy
- * @return the copy of the table
- */
- public static Hashtable copyHashTable(Hashtable paramsMap) {
- Hashtable newTable = new Hashtable();
-
- Enumeration keys = paramsMap.keys();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- newTable.put(key, paramsMap.get(key));
- }
-
- return newTable;
- }
-
- private int calcHashCode(ASN1Encodable enc) {
- String value = IETFUtils.valueToString(enc);
- value = IETFUtils.canonicalize(value);
- return value.hashCode();
- }
-
- public int calculateHashCode(X500Name name) {
- int hashCodeValue = 0;
- RDN[] rdns = name.getRDNs();
-
- // this needs to be order independent, like equals
- for (int i = 0; i != rdns.length; i++) {
- if (rdns[i].isMultiValued()) {
- AttributeTypeAndValue[] atv = rdns[i].getTypesAndValues();
-
- for (int j = 0; j != atv.length; j++) {
- hashCodeValue ^= atv[j].getType().hashCode();
- hashCodeValue ^= calcHashCode(atv[j].getValue());
- }
- } else {
- hashCodeValue ^= rdns[i].getFirst().getType().hashCode();
- hashCodeValue ^= calcHashCode(rdns[i].getFirst().getValue());
- }
- }
-
- return hashCodeValue;
- }
-
-
- /**
- * For all string values starting with '#' is assumed, that these are
- * already valid ASN.1 objects encoded in hex.
- *
- * All other string values are send to
- * {@link AbstractX500NameStyle#encodeStringValue(ASN1ObjectIdentifier, String)}.
- *
- * Subclasses should overwrite
- * {@link AbstractX500NameStyle#encodeStringValue(ASN1ObjectIdentifier, String)}
- * to change the encoding of specific types.
- *
- */
- public ASN1Encodable stringToValue(ASN1ObjectIdentifier oid, String value)
+public abstract class AbstractX500NameStyle
+ implements X500NameStyle
+{
+
+ /**
+ * Tool function to shallow copy a Hashtable.
+ *
+ * @param paramsMap table to copy
+ * @return the copy of the table
+ */
+ public static Hashtable copyHashTable(Hashtable paramsMap)
+ {
+ Hashtable newTable = new Hashtable();
+
+ Enumeration keys = paramsMap.keys();
+ while (keys.hasMoreElements())
+ {
+ Object key = keys.nextElement();
+ newTable.put(key, paramsMap.get(key));
+ }
+
+ return newTable;
+ }
+
+ private int calcHashCode(ASN1Encodable enc)
+ {
+ String value = IETFUtils.valueToString(enc);
+ value = IETFUtils.canonicalize(value);
+ return value.hashCode();
+ }
+
+ public int calculateHashCode(X500Name name)
+ {
+ int hashCodeValue = 0;
+ RDN[] rdns = name.getRDNs();
+
+ // this needs to be order independent, like equals
+ for (int i = 0; i != rdns.length; i++)
+ {
+ if (rdns[i].isMultiValued())
+ {
+ AttributeTypeAndValue[] atv = rdns[i].getTypesAndValues();
+
+ for (int j = 0; j != atv.length; j++)
+ {
+ hashCodeValue ^= atv[j].getType().hashCode();
+ hashCodeValue ^= calcHashCode(atv[j].getValue());
+ }
+ }
+ else
+ {
+ hashCodeValue ^= rdns[i].getFirst().getType().hashCode();
+ hashCodeValue ^= calcHashCode(rdns[i].getFirst().getValue());
+ }
+ }
+
+ return hashCodeValue;
+ }
+
+
+ /**
+ * For all string values starting with '#' is assumed, that these are
+ * already valid ASN.1 objects encoded in hex.
+ * <p/>
+ * All other string values are send to
+ * {@link AbstractX500NameStyle#encodeStringValue(ASN1ObjectIdentifier, String)}.
+ * <p/>
+ * Subclasses should overwrite
+ * {@link AbstractX500NameStyle#encodeStringValue(ASN1ObjectIdentifier, String)}
+ * to change the encoding of specific types.
+ */
+ public ASN1Encodable stringToValue(ASN1ObjectIdentifier oid, String value)
{
if (value.length() != 0 && value.charAt(0) == '#')
{
@@ -95,7 +101,7 @@ public abstract class AbstractX500NameStyle implements X500NameStyle {
throw new RuntimeException("can't recode value for oid " + oid.getId());
}
}
-
+
if (value.length() != 0 && value.charAt(0) == '\\')
{
value = value.substring(1);
@@ -103,21 +109,22 @@ public abstract class AbstractX500NameStyle implements X500NameStyle {
return encodeStringValue(oid, value);
}
-
- /**
- * Encoded every value into a UTF8String.
- *
- * Subclasses should overwrite
- * this method to change the encoding of specific types.
- *
- * @param oid of the value
- * @param value to encode
- * @return a the value encoded into a ASN.1 object. Never returns <code>null</code>.
- */
- protected ASN1Encodable encodeStringValue(ASN1ObjectIdentifier oid, String value) {
- return new DERUTF8String(value);
- }
-
+
+ /**
+ * Encoded every value into a UTF8String.
+ * <p/>
+ * Subclasses should overwrite
+ * this method to change the encoding of specific types.
+ *
+ * @param oid of the value
+ * @param value to encode
+ * @return a the value encoded into a ASN.1 object. Never returns <code>null</code>.
+ */
+ protected ASN1Encodable encodeStringValue(ASN1ObjectIdentifier oid, String value)
+ {
+ return new DERUTF8String(value);
+ }
+
public boolean areEqual(X500Name name1, X500Name name2)
{
RDN[] rdns1 = name1.getRDNs();
@@ -145,7 +152,7 @@ public abstract class AbstractX500NameStyle implements X500NameStyle {
return true;
}
-
+
private boolean foundMatch(boolean reverse, RDN rdn, RDN[] possRDNs)
{
if (reverse)
@@ -173,10 +180,9 @@ public abstract class AbstractX500NameStyle implements X500NameStyle {
return false;
}
-
+
protected boolean rdnAreEqual(RDN rdn1, RDN rdn2)
{
return IETFUtils.rDNAreEqual(rdn1, rdn2);
}
-
}