ASN1
Functions for interacting with ASN.1 data streams.
Note that this class only implements a small subset of the ASN.1 DER, and should not be used as a general-purpose ASN.1 encoder/decoder.
Table of Contents
Constants
- APPLICATION_CLASS = 0x40
- BIT_STRING = 0x3
- CONTEXT_CLASS = 0x80
- INTEGER_TYPE = 0x2
- NULL_TYPE = 0x5
- OCTET_STRING = 0x4
- OID = 0x6
- PRIVATE_CLASS = 0xc0
- SEQUENCE = 0x10
- UNIVERSAL_CLASS = 0x0
Methods
- decodeOID() : mixed
- Decodes a DER-encoded object identifier into a string.
- encodeDER() : string
- Encodes a value into a DER object.
- encodeOID() : mixed
- Encodes a string into a DER-encoded object identifier.
- readDER() : int
- Reads a DER stream and decodes a single object
Constants
APPLICATION_CLASS
public
mixed
APPLICATION_CLASS
= 0x40
BIT_STRING
public
mixed
BIT_STRING
= 0x3
CONTEXT_CLASS
public
mixed
CONTEXT_CLASS
= 0x80
INTEGER_TYPE
public
mixed
INTEGER_TYPE
= 0x2
NULL_TYPE
public
mixed
NULL_TYPE
= 0x5
OCTET_STRING
public
mixed
OCTET_STRING
= 0x4
OID
public
mixed
OID
= 0x6
PRIVATE_CLASS
public
mixed
PRIVATE_CLASS
= 0xc0
SEQUENCE
public
mixed
SEQUENCE
= 0x10
UNIVERSAL_CLASS
public
mixed
UNIVERSAL_CLASS
= 0x0
Methods
decodeOID()
Decodes a DER-encoded object identifier into a string.
public
static decodeOID(mixed $oid) : mixed
Parameters
- $oid : mixed
Tags
encodeDER()
Encodes a value into a DER object.
public
static encodeDER(int $type[, string $value = '' ][, bool $primitive = true ][, mixed $class = 0 ]) : string
Parameters
- $type : int
-
the DER tag of the object
- $value : string = ''
-
the value to encode
- $primitive : bool = true
-
whether the object is of a primitive or constructed type
- $class : mixed = 0
Return values
string —the encoded object
encodeOID()
Encodes a string into a DER-encoded object identifier.
public
static encodeOID(mixed $str) : mixed
Parameters
- $str : mixed
Tags
readDER()
Reads a DER stream and decodes a single object
public
static readDER(string $der, int $offset, mixed &$data[, bool $ignore_bit_strings = FALSE ]) : int
Parameters
- $der : string
-
the data stream
- $offset : int
-
the offset of the data stream containing the object to decode
- $data : mixed
-
the decoded object
- $ignore_bit_strings : bool = FALSE
-
whether to refrain from moving the offset when reading a bit string - this allows the caller to read the bit string manually
Return values
int —the number of bytes read, or 0 if there is an error