SSE4E

Home

GPError
GPSystem
ByteString
ByteBuffer
TLV
TLVList
Card
Atr
Key
Crypto
Application GPApplication GPSecDomain

ASN1
CardFile
IsoSecureChannel
ApplFactory
GPXML
JsScript
CardSim

X509
CRL
KeyStore
CMSSignedData
CMSGenerator
XMLSignature
OCSPQuery
LDAP
SOAP
URLConnection

PKCS11Provider
PKCS11Session
PKCS11Object

OutlineNode

OpenSCDP

ByteBuffer - Reference Documentation

Implementation of a mutuable byte buffer.

Index of Methods

Properties

TypeNameDescription
NumberlengthNumber of bytes in the ByteBuffer

Constructor

Prototype

ByteBuffer()

ByteBuffer(String stringValue, Number encoding)

ByteBuffer(ByteString byteString)

Description

Create a empty ByteBuffer object or a ByteBuffer object containing the data from stringValue decoded according to format defined in argument encoding or a ByteBuffer object containing the ByteString object passed as argument

The following encoding formats can be used for the stringValue argument:

HEX - A string containing hexadecimal characters and arbitrary delimiters.

ASCII - A string containing ASCII characters and characters from Latin-1.

UTF8 - A string containing Unicode characters.

BASE64 - A string containing BASE-64 encoded data.

OID - A string containing an object identifier in dotted notation or separated by blanks (This is a proprietary extension to Global Platform Scripting).

Arguments

TypeNameDescription
StringstringValueString containing the encoded binary data
NumberencodingEncoding format. Must be one of HEX, ASCII, UTF8, BASE64 or OID
ByteStringbyteStringByteString object with data

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_ENCODINGThe argument encoding contains an unknown encoding format
GPErrorGPError.INVALID_DATAThe argument stringValue contains characters not compatible with the encoding format
GPErrorGPError.INVALID_ARGUMENTSToo many arguments given

Example


x = new ByteBuffer();

assert(x != null);
assert(x instanceof ByteBuffer);


x = new ByteBuffer("1234", HEX);

assert(x.length == 2);
assert(x.toString() == "12 34");


x = new ByteBuffer("0x1234 56.78.90+AB#cd'EF", HEX);

assert(x.length == 8);
assert(x.toString() == "12 34 56 78 90 AB CD EF");


x = new ByteBuffer("1234ABCDÄÖÜß", ASCII);

assert(x.length == 12);
assert(x.toString() == "31 32 33 34 41 42 43 44 C4 D6 DC DF");


x = new ByteBuffer("1234ABCDÄÖÜß", UTF8);

assert(x.length == 16);
assert(x.toString() == "31 32 33 34 41 42 43 44 C3 84 C3 96 C3 9C C3 9F");


x = new ByteBuffer("SGVsbG8gV29ybGQ=", BASE64);

assert(x.length == 11);
assert(x.toString(ASCII) == "Hello World");


x = new ByteBuffer(new ByteString("1234", HEX));

assert(x.length == 2);
assert(x.toString() == "12 34");


x = new ByteBuffer("1.2.840.113549.1.1.2", OID);

assert(x.length == 9);
assert(x.toString(OID) == "1.2.840.113549.1.1.2");
assert(x.toString(HEX) == "2A864886F70D010102"); 


x = new ByteBuffer("1 2 840 113549 1 1 2", OID);

assert(x.toString(HEX) == "2A864886F70D010102"); 


toString()

Prototype

String toString(Number encoding)

Description

Return string containing binary data in given encoding

Arguments

TypeNameDescription
NumberencodingEncoding to present the binary data in. Must be one of ASCII, HEX, UTF8, BASE64 or CN.

Return

StringString representing data from ByteBuffer

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


x = new ByteBuffer("41 42 43", HEX);
assert(x.toString(HEX) == "414243");

x = new ByteBuffer("41 42 43 C4 D6 DC DF", HEX);
assert(x.toString(ASCII) == "ABCÄÖÜß");

x = new ByteBuffer("C3 84 C3 96 C3 9C C3 9F", HEX);
assert(x.toString(UTF8) == "ÄÖÜß");

x = new ByteBuffer("Hello World", ASCII);
assert(x.toString(BASE64) == "SGVsbG8gV29ybGQ=");

append()

Prototype

ByteBuffer append(ByteBuffer byteBuffer)

ByteBuffer append(ByteString byteString)

ByteBuffer append(Number byteValue)

ByteBuffer append(String stringValue)

Description

Append to the ByteBuffer at the end the content of the ByteBuffer or ByteString object, the ASCII encoded string or the byte given as argument.

Arguments

TypeNameDescription
ByteBufferbyteBufferByteBuffer object to be appended to ByteBuffer
ByteStringbyteStringByteString object to be appended to ByteBuffer
StringstringValueString containing ASCII characters to be appended to ByteBuffer
NumberbyteValueSingle byte value

Return

ByteBufferReturns the ByteBuffer object this method is applied to

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


x = new ByteBuffer();

x.append(new ByteBuffer("ABC", ASCII));
assert(x.toString() == "41 42 43");

x.append("123");
assert(x.toString() == "41 42 43 31 32 33");

x.append(new ByteString("ABC", ASCII));
assert(x.toString() == "41 42 43 31 32 33 41 42 43");

str = 0x20;
x.append(str);
assert(x.toString() == "41 42 43 31 32 33 41 42 43 20");

byteAt()

Prototype

Number byteAt(Number offset)

Description

Return the byte at the zero based offset in the ByteBuffer

Arguments

TypeNameDescription
NumberoffsetZero based offset

Return

NumberValue of byte as unsigned integer

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXArgument offset is out of range

Example


x = new ByteBuffer("123ABCÄÖÜ", ASCII);
assert(typeof(x.byteAt(0) == "number"));
assert(x.byteAt(0) == 0x31);
assert(x.byteAt(3) == 0x41);
assert(x.byteAt(6) == 0xC4);

clear()

Prototype

ByteBuffer clear()

ByteBuffer clear(Number offset)

ByteBuffer clear(Number offset, Number length)

Description

Clears the area specified by offset and length in the ByteBuffer. Bytes behind the cleared area are moved to offset. If length is missing, then the remaining length from offset to the end of the ByteBuffer is cleared. If offset and length are missing from the argument list, then the whole ByteBuffer is cleared.

Arguments

TypeNameDescription
NumberoffsetThe zero based offset in the ByteBuffer where the clear operation is started. Zero is assumed if offset is missing.
NumberlengthThe length of the area to be cleared. If length is missing, then the maximum number of bytes up to the end of the ByteBuffer is assumed.

Return

ByteBufferThe ByteBuffer object the method is applied to

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXArgument offset is out of range
GPErrorGPError.INVALID_LENGTHArgument length is out of range

Example


x = new ByteBuffer("123456", ASCII);

x.clear(2, 2);
assert(x.toString(ASCII) == "1256");

x.clear(2);
assert(x.toString(ASCII) == "12");

x.clear();
assert(x.length == 0);

copy()

Prototype

ByteBuffer copy(Number offset, ByteBuffer byteBuffer)

ByteBuffer copy(Number offset, ByteString byteString)

ByteBuffer copy(Number offset, Number byteValue)

ByteBuffer copy(Number offset, String stringValue)

Description

Copy the bytes from the argument into the ByteBuffer at offset and replace the bytes contained. The length of the ByteBuffer is not changed.

Arguments

TypeNameDescription
NumberoffsetZero based offset at which the bytes from the argument are copied to
ByteBufferbyteBuffer
ByteStringbyteString
NumberbyteValueValue of a single unsigned byte
NumberstringValueASCII encoded string

Return

ByteBufferThe ByteBuffer object this method is applied to

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXThe argument offset is out of range
GPErrorGPError.INVALID_LENGTHThe offset plus the length of the argument exceeds the end of the ByteBuffer

Example


x = new ByteBuffer("123456", ASCII);

x.copy(0, "AB");
assert(x.toString(ASCII) == "AB3456");

y = new ByteBuffer("CD", ASCII);
x.copy(2, y);
assert(x.toString(ASCII) == "ABCD56");

y = new ByteString("EF", ASCII);
x.copy(4, y);
assert(x.toString(ASCII) == "ABCDEF");

find()

Prototype

Number find(ByteString value)

Number find(ByteString value, Number offset)

Description

Find the first occurence of the value starting at offset.

Arguments

TypeNameDescription
ByteStringvalueByteString to locate in ByteBuffer
NumberoffsetZero based offset to start search at. Zero is assumed if argument is missing.

Return

NumberZero based offset at which the ByteString is found or -1 if the ByteString is not found.

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_INDEXArgument offset is out of range
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


x = new ByteBuffer("ABCDABCD", ASCII);
y = new ByteString("BC", ASCII);

assert(x.find(y) == 1);
assert(x.find(y, 2) == 5);
assert(x.find(y, -2) == 1);

y = new ByteString("CD", ASCII);
assert(x.find(y, 4) == 6);

y = new ByteString("CD", ASCII);
assert(x.find(y, 6) == 6);

y = new ByteString("CB", ASCII);
assert(x.find(y) == -1);

y = new ByteString("BCDE", ASCII);
assert(x.find(y) == -1);

y = new ByteString("", ASCII);
assert(x.find(y) == 0);

x = new ByteBuffer("", ASCII);
y = new ByteString("", ASCII);
assert(x.find(y) == 0);
assert(x.find(y, 0) == 0);

insert()

Prototype

ByteBuffer insert(Number offset, ByteBuffer byteBuffer)

ByteBuffer insert(Number offset, ByteString byteString)

ByteBuffer insert(Number offset, Number byteValue)

ByteBuffer insert(Number offset, String stringValue)

Description

Insert the bytes from the argument at offset.

Arguments

TypeNameDescription
NumberoffsetZero based offset at which the bytes are inserted
ByteBufferbyteBufferByteBuffer object to be appended to ByteBuffer
ByteStringbyteStringByteString object to be appended to ByteBuffer
StringstringValueString containing ASCII characters to be appended to ByteBuffer
NumberbyteValueSingle byte value

Return

ByteBufferReturns the ByteBuffer object this method is applied to

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXThe argument offset is out of range

Example


x = new ByteBuffer("123456", ASCII);

x.insert(0, "AB");
assert(x.toString(ASCII) == "AB123456");

y = new ByteBuffer("CD", ASCII);
x.insert(2, y);
assert(x.toString(ASCII) == "ABCD123456");

y = new ByteString("EF", ASCII);
x.insert(10, y);
assert(x.toString(ASCII) == "ABCD123456EF");

x.insert(1, 0x31);
assert(x.toString(ASCII) == "A1BCD123456EF");

toByteString()

Prototype

ByteString toByteString()

ByteString toByteString(Number offset)

ByteString toByteString(Number offset, Number count)

Description

Return all or a fraction of the ByteBuffer as ByteString.

Arguments

TypeNameDescription
NumberoffsetZero based offset in ByteBuffer. Default is 0.
NumbercountNumber of bytes to return. Default is all.

Return

ByteStringBytes as ByteString object

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXThe argument offset is out of range
GPErrorGPError.INVALID_LENGTHThe argument count is out of range

Example


x = new ByteBuffer("123456", ASCII);

y = x.toByteString();
assert(y.toString(ASCII) == "123456");

y = x.toByteString(3);
assert(y.toString(ASCII) == "456");

y = x.toByteString(2, 2);
assert(y.toString(ASCII) == "34");

y = x.toByteString(6, 0);
assert(y.toString(ASCII) == "");