ASN1

Pure-PHP ASN.1 Parser

author

Jim Wigginton terrafrost@php.net

package

Default

Methods

ASN.1 Map

asn1map(array $decoded,array $mapping,array $special = array()): array|boolean|\phpseclib3\File\ASN1\Element|string|null
static

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.

Arguments

$decoded

array

$mapping

array

$special

array

Response

array|boolean|\phpseclib3\File\ASN1\Element|string|null

String type conversion

convert(string $in,integer $from = self::TYPE_UTF8_STRING,integer $to = self::TYPE_UTF8_STRING): string
static

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

Arguments

$in

string

$from

integer

$to

integer

Response

string

Parse BER-encoding (Helper function)

decode_ber(string $encoded,integer $start,integer $encoded_pos): array|boolean
static

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.

Arguments

$encoded

string

$start

integer

$encoded_pos

integer

Response

array|boolean

Parse BER-encoding

decodeBER(\phpseclib3\File\ASN1\Element|string $encoded): \phpseclib3\File\?array
static

Serves a similar purpose to openssl's asn1parse

Arguments

Response

\phpseclib3\File\?array

DER-decode the length

decodeLength(string &$string): integer
static

DER supports lengths up to (28)127, however, we'll only support lengths up to (28)4. See X.690 paragraph 8.1.3 for more information.

Arguments

$string

string

Response

integer

BER-decode the OID

decodeOID(string $content): string
static

Called by _decode_ber()

Arguments

$content

string

Response

string

BER-decode the time

decodeTime(string $content,integer $tag): \DateTime|false
static

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

Arguments

$content

string

$tag

integer

Response

\DateTime|false

ASN.1 Encode (Helper function)

encode_der(\phpseclib3\File\ASN1\Element|string|array|null $source,array $mapping,integer $idx = null,array $special = array()): string
static

Arguments

$source

\phpseclib3\File\ASN1\Element|string|array|null

$mapping

array

$idx

integer

$special

array

Response

string

ASN.1 Encode

encodeDER(\phpseclib3\File\ASN1\Element|string|array $source,array $mapping,array $special = array()): string
static

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.

Arguments

$source

\phpseclib3\File\ASN1\Element|string|array

$mapping

array

$special

array

Response

string

DER-encode the length

encodeLength(integer $length): string
static

DER supports lengths up to (28)127, however, we'll only support lengths up to (28)4. See X.690 paragraph 8.1.3 for more information.

Arguments

$length

integer

Response

string

DER-encode the OID

encodeOID(string $source): string
static

Called by _encode_der()

Arguments

$source

string

Response

string

Extract raw BER from Base64 encoding

extractBER(string $str): string
static

Arguments

$str

string

Response

string

Returns the OID corresponding to a name

getOID(string $name): string
static

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'

Arguments

$name

string

Response

string

Load OIDs

loadOIDs(array $oids)
static

Load the relevant OIDs for a particular ASN.1 semantic mapping. Previously loaded OIDs are retained.

Arguments

$oids

array

Set filters

setFilters(array $filters)
static

See \phpseclib3\File\X509, etc, for an example. Previously loaded filters are not retained.

Arguments

$filters

array

Set the time format

setTimeFormat(string $format)
static

Sets the time / date format for asn1map().

Arguments

$format

string

Constants

CLASS_UNIVERSAL

CLASS_UNIVERSAL

CLASS_APPLICATION

CLASS_APPLICATION

CLASS_CONTEXT_SPECIFIC

CLASS_CONTEXT_SPECIFIC

CLASS_PRIVATE

CLASS_PRIVATE

TYPE_BOOLEAN

TYPE_BOOLEAN

TYPE_INTEGER

TYPE_INTEGER

TYPE_BIT_STRING

TYPE_BIT_STRING

TYPE_OCTET_STRING

TYPE_OCTET_STRING

TYPE_NULL

TYPE_NULL

TYPE_OBJECT_IDENTIFIER

TYPE_OBJECT_IDENTIFIER

TYPE_REAL

TYPE_REAL

TYPE_ENUMERATED

TYPE_ENUMERATED

TYPE_UTF8_STRING

TYPE_UTF8_STRING

TYPE_SEQUENCE

TYPE_SEQUENCE

TYPE_SET

TYPE_SET

TYPE_NUMERIC_STRING

TYPE_NUMERIC_STRING

TYPE_PRINTABLE_STRING

TYPE_PRINTABLE_STRING

TYPE_TELETEX_STRING

TYPE_TELETEX_STRING

TYPE_VIDEOTEX_STRING

TYPE_VIDEOTEX_STRING

TYPE_IA5_STRING

TYPE_IA5_STRING

TYPE_UTC_TIME

TYPE_UTC_TIME

TYPE_GENERALIZED_TIME

TYPE_GENERALIZED_TIME

TYPE_GRAPHIC_STRING

TYPE_GRAPHIC_STRING

TYPE_VISIBLE_STRING

TYPE_VISIBLE_STRING

TYPE_GENERAL_STRING

TYPE_GENERAL_STRING

TYPE_UNIVERSAL_STRING

TYPE_UNIVERSAL_STRING

TYPE_BMP_STRING

TYPE_BMP_STRING

TYPE_CHOICE

TYPE_CHOICE

TYPE_ANY

TYPE_ANY

Type mapping table for the ANY type.

ANY_MAP

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.

var

String type to character size mapping table.

STRING_TYPE_SIZE

Non-convertable types are absent from this table. size == 0 indicates variable length encoding.

var

Properties

ASN.1 object identifiers

oids :array
static

ASN.1 object identifier reverse mapping

reverseOIDs :array
static
var

Type(s)

array

Default date format

format :string
static
var
link

http://php.net/class.datetime

Type(s)

string

Filters

filters :array
static

If the mapping type is self::TYPE_ANY what do we actually encode it as?

var
see

Type(s)

array

Current Location of most recent ASN.1 encode process

location :array
static

Useful for debug purposes

var
see

Type(s)

array

DER Encoded String

encoded :string
static

In case we need to create ASN1\Element object's..

var
see

Type(s)

string