ASN1
class ASN1 (View source)
Pure-PHP ASN.1 Parser
Constants
CLASS_UNIVERSAL |
|
CLASS_APPLICATION |
|
CLASS_CONTEXT_SPECIFIC |
|
CLASS_PRIVATE |
|
TYPE_BOOLEAN |
|
TYPE_INTEGER |
|
TYPE_BIT_STRING |
|
TYPE_OCTET_STRING |
|
TYPE_NULL |
|
TYPE_OBJECT_IDENTIFIER |
|
TYPE_REAL |
|
TYPE_ENUMERATED |
|
TYPE_UTF8_STRING |
|
TYPE_SEQUENCE |
|
TYPE_SET |
|
TYPE_NUMERIC_STRING |
|
TYPE_PRINTABLE_STRING |
|
TYPE_TELETEX_STRING |
|
TYPE_VIDEOTEX_STRING |
|
TYPE_IA5_STRING |
|
TYPE_UTC_TIME |
|
TYPE_GENERALIZED_TIME |
|
TYPE_GRAPHIC_STRING |
|
TYPE_VISIBLE_STRING |
|
TYPE_GENERAL_STRING |
|
TYPE_UNIVERSAL_STRING |
|
TYPE_BMP_STRING |
|
TYPE_CHOICE |
|
TYPE_ANY |
|
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
Parse BER-encoding
Parse BER-encoding (Helper function)
ASN.1 Map
ASN.1 Encode
ASN.1 Encode (Helper function)
DER-encode the length
BER-decode the OID
DER-encode the OID
BER-decode the time
Set the time format
Load OIDs
Load filters
String Shift
String type conversion
Details
array
decodeBER(string $encoded)
Parse BER-encoding
Serves a similar purpose to openssl's asn1parse
array
_decode_ber(string $encoded, int $start = 0, int $encoded_pos = 0)
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 self::TYPE_BIT_STRING and self::TYPE_OCTET_STRING. In those cases, the indefinite length is used.
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.
string
encodeDER(string $source, string $mapping, array $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.
string
_encode_der(string $source, string $mapping, int $idx = null, array $special = array())
ASN.1 Encode (Helper function)
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.
string
_decodeOID(string $content)
BER-decode the OID
Called by _decode_ber()
string
_encodeOID(string $source)
DER-encode the OID
Called by _encode_der()
string
_decodeTime(string $content, int $tag)
BER-decode the time
Called by _decode_ber() and in the case of implicit tags asn1map().
setTimeFormat(string $format)
Set the time format
Sets the time / date format for asn1map().
loadOIDs(array $oids)
Load OIDs
Load the relevant OIDs for a particular ASN.1 semantic mapping.
loadFilters(array $filters)
Load filters
See \phpseclib\File\X509, etc, for an example.
string
_string_shift(string $string, int $index = 1)
String Shift
Inspired by array_shift
string
convert(string $in, int $from = self::TYPE_UTF8_STRING, int $to = self::TYPE_UTF8_STRING)
String type conversion
This is a lazy conversion, dealing only with character size. No real conversion table is used.