phpseclib API Documentation
Class

File_ASN1

class File_ASN1

Pure-PHP ASN.1 Parser

Properties

array $oids ASN.1 object identifier
string $format Default date format
array $encoded Default date format
array $filters Filters
array $ANYmap Type mapping table for the ANY type.
array $stringTypeSize String type to character size mapping table.

Methods

__construct()

Default Constructor.

File_ASN1()

PHP4 compatible Default Constructor.

array decodeBER(string $encoded)

Parse BER-encoding

array _decode_ber(string $encoded, int $start, int $encoded_pos)

Parse BER-encoding (Helper function)

array asn1map(array $decoded, array $mapping, array $special = array())

ASN.1 Map

string encodeDER($source, $mapping, $special = array())

ASN.1 Encode

string _encode_der($source, $mapping, $idx = null, $special = array())

ASN.1 Encode (Helper function)

string _encodeLength(int $length)

DER-encode the length

string _decodeOID(string $content)

BER-decode the OID

string _encodeOID($source)

DER-encode the OID

string _decodeUnixTime(string $content, int $tag)

BER-decode the time (using UNIX time)

string _decodeDateTime(string $content, int $tag)

BER-decode the time (using DateTime)

setTimeFormat(string $format)

Set the time format

loadOIDs(array $oids)

Load OIDs

loadFilters(array $filters)

Load filters

string _string_shift(string $string, int $index = 1)

String Shift

string convert(string $in, int $from = FILE_ASN1_TYPE_UTF8_STRING, int $to = FILE_ASN1_TYPE_UTF8_STRING)

String type conversion

Details

at line 260
public __construct()

Default Constructor.

at line 277
public File_ASN1()

PHP4 compatible Default Constructor.

See also

self::__construct()

at line 291
public array decodeBER(string $encoded)

Parse BER-encoding

Serves a similar purpose to openssl's asn1parse

Parameters

string $encoded

Return Value

array

at line 315
public array _decode_ber(string $encoded, int $start, int $encoded_pos)

Parse BER-encoding (Helper function)

Sometimes we want to get the BER encoding of a particular tag. $start lets us do that without having to reencode. $encoded is passed by reference for the recursive calls done for FILEASN1TYPEBITSTRING and FILEASN1TYPEOCTETSTRING. In those cases, the indefinite length is used.

Parameters

string $encoded
int $start
int $encoded_pos

Return Value

array

at line 578
public array asn1map(array $decoded, array $mapping, array $special = array())

ASN.1 Map

Provides an ASN.1 semantic mapping ($mapping) from a parsed BER-encoding to a human readable format.

"Special" mappings may be applied on a per tag-name basis via $special.

Parameters

array $decoded
array $mapping
array $special

Return Value

array

at line 890
public string encodeDER($source, $mapping, $special = array())

ASN.1 Encode

DER-encodes an ASN.1 semantic mapping ($mapping). Some libraries would probably call this function an ASN.1 compiler.

"Special" mappings can be applied via $special.

Parameters

$source
$mapping
$special

Return Value

string

at line 905
public string _encode_der($source, $mapping, $idx = null, $special = array())

ASN.1 Encode (Helper function)

Parameters

$source
$mapping
$idx
$special

Return Value

string

at line 1197
public string _encodeLength(int $length)

DER-encode the length

DER supports lengths up to (28)127, however, we'll only support lengths up to (28)4. See {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.

Parameters

int $length

Return Value

string

at line 1216
public string _decodeOID(string $content)

BER-decode the OID

Called by decodeber()

Parameters

string $content

Return Value

string

at line 1264
public string _encodeOID($source)

DER-encode the OID

Called by encodeder()

Parameters

$source

Return Value

string

at line 1319
public string _decodeUnixTime(string $content, int $tag)

BER-decode the time (using UNIX time)

Called by decodeber() and in the case of implicit tags asn1map().

Parameters

string $content
int $tag

Return Value

string

at line 1369
public string _decodeDateTime(string $content, int $tag)

BER-decode the time (using DateTime)

Called by decodeber() and in the case of implicit tags asn1map().

Parameters

string $content
int $tag

Return Value

string

at line 1415
public setTimeFormat(string $format)

Set the time format

Sets the time / date format for asn1map().

Parameters

string $format

at line 1428
public loadOIDs(array $oids)

Load OIDs

Load the relevant OIDs for a particular ASN.1 semantic mapping.

Parameters

array $oids

at line 1441
public loadFilters(array $filters)

Load filters

See File_X509, etc, for an example.

Parameters

array $filters

at line 1456
public string _string_shift(string $string, int $index = 1)

String Shift

Inspired by array_shift

Parameters

string $string
int $index

Return Value

string

at line 1475
public string convert(string $in, int $from = FILE_ASN1_TYPE_UTF8_STRING, int $to = FILE_ASN1_TYPE_UTF8_STRING)

String type conversion

This is a lazy conversion, dealing only with character size. No real conversion table is used.

Parameters

string $in
int $from
int $to

Return Value

string