Fields Summary |
---|
public static final int | CONTEXTASN context specific flag used in types (0x80). |
public static final int | CONSTRUCTEDASN constructed flag used in types (0x20). |
public static final int | EXPLICITASN constructed flag used in types (0x20). |
public static final int | ANY_STRING_TYPEANY_STRING type used as a place holder. [UNIVERSAL 0] |
public static final int | BOOLEAN_TYPEASN BOOLEAN type used in certificate parsing. [UNIVERSAL 1] |
public static final int | INTEGER_TYPEASN INTEGER type used in certificate parsing. [UNIVERSAL 2] |
public static final int | BITSTRING_TYPEASN BIT STRING type used in certificate parsing. [UNIVERSAL 3] |
public static final int | OCTETSTR_TYPEASN OCTET STRING type used in certificate parsing. [UNIVERSAL 4] |
public static final int | NULL_TYPEASN NULL type used in certificate parsing. [UNIVERSAL 5] |
public static final int | OID_TYPEASN OBJECT ID type used in certificate parsing. [UNIVERSAL 6] |
public static final int | ENUMERATED_TYPEASN ENUMERATED type. [UNIVERSAL 10] |
public static final int | UTF8STR_TYPEASN UTF8String type used in certificate parsing. [UNIVERSAL 12] |
public static final int | SEQUENCE_TYPEASN SEQUENCE type used in certificate parsing.
[UNIVERSAL CONSTRUCTED 16] |
public static final int | SET_TYPEASN SET type used in certificate parsing.
[UNIVERSAL CONSTRUCTED 17] |
public static final int | PRINTSTR_TYPEASN PrintableString type used in certificate parsing. [UNIVERSAL 19] |
public static final int | TELETEXSTR_TYPEASN TELETEX STRING type used in certificate parsing. [UNIVERSAL 20] |
public static final int | IA5STR_TYPEASN IA5 STRING type used in certificate parsing. [UNIVERSAL 22] |
public static final int | UCT_TIME_TYPEASN UCT time type used in certificate parsing. [UNIVERSAL 23] |
public static final int | GEN_TIME_TYPEASN Generalized time type used in certificate parsing.
[UNIVERSAL 24] |
public static final int | UNIVSTR_TYPEASN UniversalString type used in certificate parsing.
[UNIVERSAL 28]. |
public static final int | BMPSTR_TYPEASN BIT STRING type used in certificate parsing. [UNIVERSAL 30] |
public static final int | VERSION_TYPEContext specific explicit type for certificate version.
[CONTEXT EXPLICIT 0] |
public static final int | EXTENSIONS_TYPEContext specific explicit type for certificate extensions.
[CONTEXT EXPLICIT 3] |
public int | typeRaw DER type. |
public int | lengthNumber of bytes that make up the value. |
public int | valueOffsetOffset of the value. |
public TLV | childNon-null for constructed types, the first child TLV. |
public TLV | nextThe next TLV in the parent sequence. |
public byte[] | dataBuffer that contains the DER encoded TLV. |
Methods Summary |
---|
public boolean | checkFlag(int index)Returns the value of flag stored in bitsring value.
if (type != BITSTRING_TYPE) {
throw new TLVException("invalid type - checkFlag");
}
int i = (length - 1) * 8 - data[valueOffset];
if (index >= i) {
return false;
}
return ((data[valueOffset + 1 + (index/8)] << index % 8) & 0x80)
!= 0;
|
public com.sun.satsa.util.TLV | copy()Creates a copy of this TLV. The value of field next of the new
TLV is null.
try {
return new TLV(getDERData(), 0);
} catch (TLVException e) {}
return null;
|
public static com.sun.satsa.util.TLV | createIA5String(java.lang.String s)Creates TLV object of type IA5 string.
int len = (s == null ? 0 : s.length());
if (len == 0) {
return new TLV(TLV.IA5STR_TYPE, new byte[] {});
}
byte[] b = new byte[len];
for (int i = 0; i < len; i++) {
char c = s.charAt(i);
if (c >= 0 && c <= 127) {
b[i] = (byte)c;
} else {
throw new TLVException("Illegal string for IA5:" + s);
}
}
return new TLV(TLV.IA5STR_TYPE, b);
|
public static com.sun.satsa.util.TLV | createInteger(long value)Creates TLV object of type integer.
int check = (value < 0) ? -1 : 0;
int i = 1;
while (i < 8) {
if (value >> (i * 8) == check) {
byte v = (byte) (value >> ((i - 1) * 8));
if (value < 0 ? v > 0 : v < 0) {
i++;
}
break;
}
i++;
}
byte[] data = new byte[i];
while (i > 0) {
i--;
data[i] = (byte) value;
value = value >> 8;
}
return new TLV(TLV.INTEGER_TYPE, data);
|
public static com.sun.satsa.util.TLV | createInteger(byte[] data)Creates TLV object of type integer.
return new TLV(INTEGER_TYPE, data);
|
public static com.sun.satsa.util.TLV | createOID(java.lang.String oid)Creates TLV object of type OID.
return new TLV(TLV.OID_TYPE, Utils.StringToOID(oid));
|
public static com.sun.satsa.util.TLV | createOctetString(byte[] data)Creates TLV object of type octet string.
return new TLV(OCTETSTR_TYPE, data);
|
public static com.sun.satsa.util.TLV | createSequence()Creates TLV object of type sequence.
return new TLV(SEQUENCE_TYPE);
|
public static com.sun.satsa.util.TLV | createUTCTime(java.util.Calendar time)Creates UTCTime TLV structure for given date.
byte[] data = new byte[13];
putDigits(data, 0, time.get(Calendar.YEAR));
putDigits(data, 2, time.get(Calendar.MONTH) + 1);
putDigits(data, 4, time.get(Calendar.DAY_OF_MONTH));
putDigits(data, 6, time.get(Calendar.HOUR_OF_DAY));
putDigits(data, 8, time.get(Calendar.MINUTE));
putDigits(data, 10, time.get(Calendar.SECOND));
data[12] = 0x5a;
return new TLV(UCT_TIME_TYPE, data);
|
public static com.sun.satsa.util.TLV | createUTF8String(java.lang.String s)Creates TLV object of type UTF8 string.
return new TLV(TLV.UTF8STR_TYPE, Utils.stringToBytes(s));
|
public byte[] | getDERData()Returns DER encoded TLV.
byte[] x = new byte[getDERSize()];
getDERData_(x, 0);
return x;
|
public int | getDERData(byte[] buffer, int offset)Returns DER encoded TLV.
getDERSize();
return getDERData_(buffer, offset);
|
private int | getDERData_(byte[] buffer, int offset)Returns DER encoded TLV.
int initialOffset = offset;
offset = putHeader(buffer, offset);
if (data == null) {
TLV c = child;
while (c != null) {
offset += c.getDERData_(buffer, offset);
c = c.next;
}
} else {
System.arraycopy(data, valueOffset, buffer, offset, length);
offset += length;
}
return (offset - initialOffset);
|
public int | getDERSize()Returns the size of DER encoded TLV.
if (data == null) {
length = 0;
TLV c = child;
while (c != null) {
length += c.getDERSize();
c = c.next;
}
}
return length + getTLSize();
|
public int | getEnumerated()Returns the value of enumerated type.
if (type != ENUMERATED_TYPE) {
throw new TLVException("invalid type - getEnumerated");
}
return getIntegerValue();
|
public int | getId()Returns octet string value as integer.
if (type != OCTETSTR_TYPE) {
throw new TLVException("invalid type - getId");
}
return getIntegerValue();
|
public int | getInteger()Returns integer value.
if (type != INTEGER_TYPE && ((type & 0xf0) != 0x80)) {
throw new TLVException("invalid type - getInteger");
}
return getIntegerValue();
|
private int | getIntegerValue()Returns the value of TLV as integer.
int l = data[valueOffset] < 0 ? -1 : 0;
int check = l << 24;
for (int i = 0; i < length; i++) {
if ((l & 0xff000000) != check) {
throw new TLVException("Integer value is too big");
}
l = (l << 8) | (data[valueOffset + i] & 0xff);
}
return l;
|
private int | getTLSize()Returns the size of tag and length encoding.
int TLSize = 2;
if (length >= 128) {
int i = length;
while (i != 0) {
TLSize++;
i = i >> 8;
}
}
return TLSize;
|
public java.util.Calendar | getTime()Returns time represented by this TLV.
if (type != GEN_TIME_TYPE &&
type != UCT_TIME_TYPE) {
throw new TLVException("invalid type - getType");
}
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
int offset;
int year;
if (type == GEN_TIME_TYPE) {
year = getTimeComponent(0, 4);
offset = 4;
} else {
year = getTimeComponent(0, 2);
year += (year >= 50) ? 1900 : 2000;
offset = 2;
}
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, getTimeComponent(offset, 2) - 1);
offset += 2;
c.set(Calendar.DAY_OF_MONTH, getTimeComponent(offset, 2));
offset += 2;
c.set(Calendar.HOUR_OF_DAY, getTimeComponent(offset, 2));
offset += 2;
c.set(Calendar.MINUTE, getTimeComponent(offset, 2));
offset += 2;
c.set(Calendar.SECOND, getTimeComponent(offset, 2));
return c;
|
private int | getTimeComponent(int offset, int len)Returns decoded BCD value.
int value = 0;
while (len-- > 0) {
value = value * 10 + (data[valueOffset + offset++] - 0x30);
}
return value;
|
public java.lang.String | getUTF8()Returns string represented by this UTF8 string.
if (type != UTF8STR_TYPE && ((type & 0xf0) != 0x80)) {
throw new TLVException("invalid type - getUTF8");
}
try {
return new String(data, valueOffset, length, Utils.utf8);
} catch (UnsupportedEncodingException e) {
throw new TLVException("invalid encoding");
}
|
public byte[] | getValue()Returns the value field of this TLV.
if (data == null) {
getDERSize();
}
byte[] x = new byte[length];
getValue_(x, 0);
return x;
|
private int | getValue_(byte[] buffer, int offset)Places the value field of this TLV into the buffer.
if (data == null) {
TLV c = child;
while (c != null) {
offset += c.getDERData(buffer, offset);
c = c.next;
}
} else {
System.arraycopy(data, valueOffset, buffer, offset, length);
}
return length;
|
public boolean | isString()Returns true if this value represents string.
return (type == TELETEXSTR_TYPE ||
type == PRINTSTR_TYPE ||
type == UNIVSTR_TYPE ||
type == UTF8STR_TYPE ||
type == BMPSTR_TYPE);
|
public boolean | match(com.sun.satsa.util.TLV t)Compares this object with other TLV object.
if (type != t.type) {
return false;
}
if (t.data == null) {
t = t.copy();
}
if (data == null) {
t.match(this);
}
return Utils.byteMatch(data, valueOffset, length,
t.data, t.valueOffset, t.length);
|
private static void | putDigits(byte[] data, int offset, int value)Places two ASCII encoded decimal digits into byte array.
value = value % 100;
data[offset++] = (byte) (0x30 | (value / 10));
data[offset++] = (byte) (0x30 | (value % 10));
|
private int | putHeader(byte[] x, int i)Places tag and length values into the buffer.
x[i++] = (byte) type;
if (length < 128) {
x[i++] = (byte) length;
} else
if (length < 256) {
x[i++] = (byte) 0x81;
x[i++] = (byte) length;
} else {
x[i++] = (byte) 0x82;
x[i++] = (byte) (length >> 8);
x[i++] = (byte) length;
}
return i;
|
public com.sun.satsa.util.TLV | setChild(com.sun.satsa.util.TLV child)Sets child element for this TLV object.
this.child = child;
return child;
|
public com.sun.satsa.util.TLV | setNext(com.sun.satsa.util.TLV next)Sets next element for this TLV object.
this.next = next;
return next;
|
public com.sun.satsa.util.TLV | setTag(int tag)Sets the (implicit) tag value for this object.
this.type = tag;
return this;
|
public com.sun.satsa.util.TLV | skipOptional(int type)Skips optional element of DER structure with given tag.
if (this.type == type) {
return next;
}
return this;
|
public boolean | valueEquals(byte[] data)Compares the value of this TLV with given value.
return Utils.byteMatch(this.data, valueOffset, length,
data, 0, data.length);
|