ASN1
in package
Pure-PHP ASN.1 Parser
Tags
Table of Contents
- CLASS_APPLICATION = 1
- CLASS_CONTEXT_SPECIFIC = 2
- CLASS_PRIVATE = 3
- CLASS_UNIVERSAL = 0
- TYPE_ANY = -2
- TYPE_BIT_STRING = 3
- TYPE_BMP_STRING = 30
- TYPE_BOOLEAN = 1
- TYPE_CHOICE = -1
- TYPE_ENUMERATED = 10
- TYPE_GENERAL_STRING = 27
- TYPE_GENERALIZED_TIME = 24
- TYPE_GRAPHIC_STRING = 25
- TYPE_IA5_STRING = 22
- TYPE_INTEGER = 2
- TYPE_NULL = 5
- TYPE_NUMERIC_STRING = 18
- TYPE_OBJECT_IDENTIFIER = 6
- TYPE_OCTET_STRING = 4
- TYPE_PRINTABLE_STRING = 19
- TYPE_REAL = 9
- TYPE_SEQUENCE = 16
- TYPE_SET = 17
- TYPE_TELETEX_STRING = 20
- TYPE_UNIVERSAL_STRING = 28
- TYPE_UTC_TIME = 23
- TYPE_UTF8_STRING = 12
- TYPE_VIDEOTEX_STRING = 21
- TYPE_VISIBLE_STRING = 26
- $ANYmap : array<string|int, mixed>
- Type mapping table for the ANY type.
- $encoded : array<string|int, mixed>
- Default date format
- $filters : array<string|int, mixed>
- Filters
- $format : string
- Default date format
- $oids : array<string|int, mixed>
- ASN.1 object identifier
- $stringTypeSize : array<string|int, mixed>
- String type to character size mapping table.
- _decode_ber() : array<string|int, mixed>
- Parse BER-encoding (Helper function)
- _decodeOID() : string
- BER-decode the OID
- _decodeTime() : string
- BER-decode the time
- _encode_der() : string
- ASN.1 Encode (Helper function)
- _encodeLength() : string
- DER-encode the length
- _encodeOID() : string
- DER-encode the OID
- _string_shift() : string
- String Shift
- asn1map() : array<string|int, mixed>
- ASN.1 Map
- convert() : string
- String type conversion
- decodeBER() : array<string|int, mixed>
- Parse BER-encoding
- encodeDER() : string
- ASN.1 Encode
- loadFilters() : mixed
- Load filters
- loadOIDs() : mixed
- Load OIDs
- setTimeFormat() : mixed
- Set the time format
Constants
CLASS_APPLICATION
public
mixed
CLASS_APPLICATION
= 1
CLASS_CONTEXT_SPECIFIC
public
mixed
CLASS_CONTEXT_SPECIFIC
= 2
CLASS_PRIVATE
public
mixed
CLASS_PRIVATE
= 3
CLASS_UNIVERSAL
public
mixed
CLASS_UNIVERSAL
= 0
TYPE_ANY
public
mixed
TYPE_ANY
= -2
TYPE_BIT_STRING
public
mixed
TYPE_BIT_STRING
= 3
TYPE_BMP_STRING
public
mixed
TYPE_BMP_STRING
= 30
TYPE_BOOLEAN
public
mixed
TYPE_BOOLEAN
= 1
TYPE_CHOICE
public
mixed
TYPE_CHOICE
= -1
TYPE_ENUMERATED
public
mixed
TYPE_ENUMERATED
= 10
TYPE_GENERAL_STRING
public
mixed
TYPE_GENERAL_STRING
= 27
TYPE_GENERALIZED_TIME
public
mixed
TYPE_GENERALIZED_TIME
= 24
TYPE_GRAPHIC_STRING
public
mixed
TYPE_GRAPHIC_STRING
= 25
TYPE_IA5_STRING
public
mixed
TYPE_IA5_STRING
= 22
TYPE_INTEGER
public
mixed
TYPE_INTEGER
= 2
TYPE_NULL
public
mixed
TYPE_NULL
= 5
TYPE_NUMERIC_STRING
public
mixed
TYPE_NUMERIC_STRING
= 18
TYPE_OBJECT_IDENTIFIER
public
mixed
TYPE_OBJECT_IDENTIFIER
= 6
TYPE_OCTET_STRING
public
mixed
TYPE_OCTET_STRING
= 4
TYPE_PRINTABLE_STRING
public
mixed
TYPE_PRINTABLE_STRING
= 19
TYPE_REAL
public
mixed
TYPE_REAL
= 9
TYPE_SEQUENCE
public
mixed
TYPE_SEQUENCE
= 16
TYPE_SET
public
mixed
TYPE_SET
= 17
TYPE_TELETEX_STRING
public
mixed
TYPE_TELETEX_STRING
= 20
TYPE_UNIVERSAL_STRING
public
mixed
TYPE_UNIVERSAL_STRING
= 28
TYPE_UTC_TIME
public
mixed
TYPE_UTC_TIME
= 23
TYPE_UTF8_STRING
public
mixed
TYPE_UTF8_STRING
= 12
TYPE_VIDEOTEX_STRING
public
mixed
TYPE_VIDEOTEX_STRING
= 21
TYPE_VISIBLE_STRING
public
mixed
TYPE_VISIBLE_STRING
= 26
Properties
$ANYmap
Type mapping table for the ANY type.
public
array<string|int, mixed>
$ANYmap
= array(
self::TYPE_BOOLEAN => true,
self::TYPE_INTEGER => true,
self::TYPE_BIT_STRING => 'bitString',
self::TYPE_OCTET_STRING => 'octetString',
self::TYPE_NULL => 'null',
self::TYPE_OBJECT_IDENTIFIER => 'objectIdentifier',
self::TYPE_REAL => true,
self::TYPE_ENUMERATED => 'enumerated',
self::TYPE_UTF8_STRING => 'utf8String',
self::TYPE_NUMERIC_STRING => 'numericString',
self::TYPE_PRINTABLE_STRING => 'printableString',
self::TYPE_TELETEX_STRING => 'teletexString',
self::TYPE_VIDEOTEX_STRING => 'videotexString',
self::TYPE_IA5_STRING => 'ia5String',
self::TYPE_UTC_TIME => 'utcTime',
self::TYPE_GENERALIZED_TIME => 'generalTime',
self::TYPE_GRAPHIC_STRING => 'graphicString',
self::TYPE_VISIBLE_STRING => 'visibleString',
self::TYPE_GENERAL_STRING => 'generalString',
self::TYPE_UNIVERSAL_STRING => 'universalString',
//self::TYPE_CHARACTER_STRING => 'characterString',
self::TYPE_BMP_STRING => 'bmpString',
)
Structured or unknown types are mapped to a \phpseclib\File\ASN1\Element. Unambiguous types get the direct mapping (int/real/bool). Others are mapped as a choice, with an extra indexing level.
Tags
$encoded
Default date format
public
array<string|int, mixed>
$encoded
Tags
$filters
Filters
public
array<string|int, mixed>
$filters
If the mapping type is self::TYPE_ANY what do we actually encode it as?
Tags
$format
Default date format
public
string
$format
= 'D, d M Y H:i:s O'
Tags
$oids
ASN.1 object identifier
public
array<string|int, mixed>
$oids
= array()
Tags
$stringTypeSize
String type to character size mapping table.
public
array<string|int, mixed>
$stringTypeSize
= array(self::TYPE_UTF8_STRING => 0, self::TYPE_BMP_STRING => 2, self::TYPE_UNIVERSAL_STRING => 4, self::TYPE_PRINTABLE_STRING => 1, self::TYPE_TELETEX_STRING => 1, self::TYPE_IA5_STRING => 1, self::TYPE_VISIBLE_STRING => 1)
Non-convertable types are absent from this table. size == 0 indicates variable length encoding.
Tags
Methods
_decode_ber()
Parse BER-encoding (Helper function)
public
_decode_ber(string $encoded, int $start, int $encoded_pos) : array<string|int, mixed>
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.
Parameters
- $encoded : string
- $start : int
- $encoded_pos : int
Tags
Return values
array<string|int, mixed> —_decodeOID()
BER-decode the OID
public
_decodeOID(string $content) : string
Called by _decode_ber()
Parameters
- $content : string
Tags
Return values
string —_decodeTime()
BER-decode the time
public
_decodeTime(string $content, int $tag) : string
Called by _decode_ber() and in the case of implicit tags asn1map().
Parameters
- $content : string
- $tag : int
Tags
Return values
string —_encode_der()
ASN.1 Encode (Helper function)
public
_encode_der(string $source, string $mapping[, int $idx = null ][, mixed $special = array() ]) : string
Parameters
- $source : string
- $mapping : string
- $idx : int = null
- $special : mixed = array()
Tags
Return values
string —_encodeLength()
DER-encode the length
public
_encodeLength(int $length) : string
DER supports lengths up to (2**8)127, however, we'll only support lengths up to (28)**4. See X.690 paragraph 8.1.3 for more information.
Parameters
- $length : int
Tags
Return values
string —_encodeOID()
DER-encode the OID
public
_encodeOID(mixed $source) : string
Called by _encode_der()
Parameters
- $source : mixed
Tags
Return values
string —_string_shift()
String Shift
public
_string_shift(string &$string[, int $index = 1 ]) : string
Inspired by array_shift
Parameters
- $string : string
- $index : int = 1
Tags
Return values
string —asn1map()
ASN.1 Map
public
asn1map(array<string|int, mixed> $decoded, array<string|int, mixed> $mapping[, array<string|int, mixed> $special = array() ]) : array<string|int, mixed>
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
- $decoded : array<string|int, mixed>
- $mapping : array<string|int, mixed>
- $special : array<string|int, mixed> = array()
Tags
Return values
array<string|int, mixed> —convert()
String type conversion
public
convert(string $in[, int $from = self::TYPE_UTF8_STRING ][, int $to = self::TYPE_UTF8_STRING ]) : string
This is a lazy conversion, dealing only with character size. No real conversion table is used.
Parameters
- $in : string
- $from : int = self::TYPE_UTF8_STRING
- $to : int = self::TYPE_UTF8_STRING
Tags
Return values
string —decodeBER()
Parse BER-encoding
public
decodeBER(string $encoded) : array<string|int, mixed>
Serves a similar purpose to openssl's asn1parse
Parameters
- $encoded : string
Tags
Return values
array<string|int, mixed> —encodeDER()
ASN.1 Encode
public
encodeDER(string $source, string $mapping[, mixed $special = array() ]) : string
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 : string
- $mapping : string
- $special : mixed = array()
Tags
Return values
string —loadFilters()
Load filters
public
loadFilters(array<string|int, mixed> $filters) : mixed
See \phpseclib\File\X509, etc, for an example.
Parameters
- $filters : array<string|int, mixed>
Tags
Return values
mixed —loadOIDs()
Load OIDs
public
loadOIDs(array<string|int, mixed> $oids) : mixed
Load the relevant OIDs for a particular ASN.1 semantic mapping.
Parameters
- $oids : array<string|int, mixed>
Tags
Return values
mixed —setTimeFormat()
Set the time format
public
setTimeFormat(string $format) : mixed
Sets the time / date format for asn1map().
Parameters
- $format : string