ASN1
abstract 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 |
|
ANY_MAP |
Type mapping table for the ANY type. Structured or unknown types are mapped to a \phpseclib3\File\ASN1\Element. Unambiguous types get the direct mapping (int/real/bool). Others are mapped as a choice, with an extra indexing level. |
STRING_TYPE_SIZE |
String type to character size mapping table. Non-convertable types are absent from this table. size == 0 indicates variable length encoding. |
Methods
Parse BER-encoding
ASN.1 Map
DER-decode the length
ASN.1 Encode
BER-decode the OID
DER-encode the OID
Set the time format
Load OIDs
Set filters
String type conversion
Extract raw BER from Base64 encoding
DER-encode the length
Returns the OID corresponding to a name
Details
static array
decodeBER(string $encoded)
Parse BER-encoding
Serves a similar purpose to openssl's asn1parse
static array|bool|Element
asn1map(array $decoded, array $mapping, array $special = [])
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.
static int
decodeLength(string $string)
DER-decode 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.
static string
encodeDER(Element|string|array $source, array $mapping, array $special = [])
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.
static string
decodeOID(string $content)
BER-decode the OID
Called by _decode_ber()
static string
encodeOID(string $source)
DER-encode the OID
Called by _encode_der()
static
setTimeFormat(string $format)
Set the time format
Sets the time / date format for asn1map().
static
loadOIDs(array $oids)
Load OIDs
Load the relevant OIDs for a particular ASN.1 semantic mapping. Previously loaded OIDs are retained.
static
setFilters(array $filters)
Set filters
See \phpseclib3\File\X509, etc, for an example. Previously loaded filters are not retained.
static 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.
static string
extractBER(string $str)
Extract raw BER from Base64 encoding
static 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.
static string
getOID(string $name)
Returns the OID corresponding to a name
What's returned in the associative array returned by loadX509() (or load*()) is either a name or an OID if no OID to name mapping is available. The problem with this is that what may be an unmapped OID in one version of phpseclib may not be unmapped in the next version, so apps that are looking at this OID may not be able to work from version to version.
This method will return the OID if a name is passed to it and if no mapping is avialable it'll assume that what's being passed to it already is an OID and return that instead. A few examples.
getOID('2.16.840.1.101.3.4.2.1') == '2.16.840.1.101.3.4.2.1' getOID('id-sha256') == '2.16.840.1.101.3.4.2.1' getOID('zzz') == 'zzz'