Methods Summary |
---|
public boolean | equals(java.lang.Object o)Compares object with OID for equality.
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
return Arrays.equals(oid, ((ObjectIdentifier) o).oid);
|
public int[] | getOid()Returns array of integers.
return oid;
|
public int | hashCode()
// FIXME change me to Arrays.hashCode(int[])
int intHash = 0;
for (int i = 0; i < oid.length && i < 4; i++) {
intHash += oid[i] << (8 * i); //TODO what about to find better one?
}
return intHash & 0x7FFFFFFF; // only positive
|
public static boolean | isOID(java.lang.String str)Returns whether the given string is a valid ObjectIdentifier
(OID) representation.
String representation is defined as for {@link #toIntArray}.
return toIntArray(str, false) != null;
|
private static int[] | toIntArray(java.lang.String str, boolean shouldThrow)Gets ObjectIdentifier (OID) from string representation.
String representation is defined by the following syntax:
OID = subidentifier 1*("." subidentifier)
subidentifier = 1*(digit)
if (str == null) {
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(
Messages.getString("security.9D")); //$NON-NLS-1$
}
int length = str.length();
if (length == 0) {
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(Messages.getString("security.9E")); //$NON-NLS-1$
}
int count = 1; // number of subidentifiers
boolean wasDot = true; // indicates whether char before was dot or not.
char c; // current char
for (int i = 0; i < length; i++) {
c = str.charAt(i);
if (c == '.") {
if (wasDot) {
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(Messages.getString("security.9E")); //$NON-NLS-1$
}
wasDot = true;
count++;
} else if (c >= '0" && c <= '9") {
wasDot = false;
} else {
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(Messages.getString("security.9E")); //$NON-NLS-1$
}
}
if (wasDot) {
// the last char is dot
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(Messages.getString("security.9E")); //$NON-NLS-1$
}
if (count < 2) {
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(
Messages.getString("security.99")); //$NON-NLS-1$
}
int[] oid = new int[count];
for (int i = 0, j = 0; i < length; i++) {
c = str.charAt(i);
if (c == '.") {
j++;
} else {
oid[j] = oid[j] * 10 + c - 48; // '0' = 48
}
}
if (oid[0] > 2) {
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(
Messages.getString("security.9A")); //$NON-NLS-1$
} else if (oid[0] != 2 && oid[1] > 39) {
if (! shouldThrow) {
return null;
}
throw new IllegalArgumentException(
Messages.getString("security.9B")); //$NON-NLS-1$
}
return oid;
|
public static int[] | toIntArray(java.lang.String str)Gets ObjectIdentifier (OID) from string representation.
String representation is defined by the following syntax:
OID = subidentifier 1*("." subidentifier)
subidentifier = 1*(digit)
return toIntArray(str, true);
|
public java.lang.String | toString()
if (soid == null) {
soid = toString(oid);
}
return soid;
|
public static java.lang.String | toString(int[] oid)Returns string representation of OID.
Note: it is supposed that passed array of integers
contains valid OID value, so no checks are performed.
StringBuffer sb = new StringBuffer(3 * oid.length);
for (int i = 0; i < oid.length - 1; ++i) {
sb.append(oid[i]);
sb.append('.");
}
sb.append(oid[oid.length - 1]);
return sb.toString();
|
public static void | validate(int[] oid)Validates ObjectIdentifier (OID).
if (oid == null) {
throw new IllegalArgumentException(Messages.getString("security.98")); //$NON-NLS-1$
}
if (oid.length < 2) {
throw new IllegalArgumentException(
Messages.getString("security.99")); //$NON-NLS-1$
}
if (oid[0] > 2) {
throw new IllegalArgumentException(
Messages.getString("security.9A")); //$NON-NLS-1$
} else if (oid[0] != 2 && oid[1] > 39) {
throw new IllegalArgumentException(
Messages.getString("security.9B")); //$NON-NLS-1$
}
for (int i = 0; i < oid.length; i++) {
if (oid[i] < 0) {
throw new IllegalArgumentException(
Messages.getString("security.9C")); //$NON-NLS-1$
}
}
|