Decode using ASN.1 DER (Distinguished Encoding Representation) ASN.1: Abstract Syntax Notation 1
This module does not completely decode all DER data types,
the following is a list of supported data types in this implementation:
INTEGER,
BIT_STRING,
NULL,
OBJECT_IDENTIFIER,
GeneralizedTime,
Strings (OCTET STRING, PrintableString, etc.)
SEQUENCE OF,
SEQUENCE,
DER unpack object
Usage:
from packet.derunpack import DERunpack
x = DERunpack(buffer)
# Get the decoded object structure for the stream bytes in buffer
obj = x.get_item()
Where obj is of the form:
obj = {
application = {
context-tag0 = int|list|dictionary,
context-tag1 = int|list|dictionary,
...
context-tagN = int|list|dictionary,
}
}
Example:
For the following ASN.1 definition:
TEST ::= [APPLICATION 10] SEQUENCE {
id [0] INTEGER,
numbers [1] SEQUENCE OF INTEGER,
data [2] SEQUENCE {
-- NOTE: first tag is [1], not [0]
type [1] INTEGER,
value [2] PrintableString,
},
}
Using the streamed bytes of the above ASN.1 definition,
the following is returned by get_item():
obj = {
10 = { # Application 10
0: 53, # id: context-tag=0, value=53
1: [1,2,3], # numbers: context-tag=1, value=[1,2,3]
2: { # data: context-tag=1, value=structure
1: 2, # id: context-tag=1, value=2
2: "test", # id: context-tag=2, value="test"
}
}
}
Methods defined here:
---------------------
der_date(self, size)
Return a date time of type GeneralizedTime
Type GeneralizedTime takes values of the year, month, day, hour,
minute, second, and second fraction in any of following three forms:
Local time: "YYYYMMDDHH[MM[SS[.fff]]]"
Universal time (UTC): "YYYYMMDDHH[MM[SS[.fff]]]Z"
Difference between local and UTC times" "YYYYMMDDHH[MM[SS[.fff]]]+|-HHMM".
Where the optional fff is accurate to three decimal places
der_integer(self, size=None, unsigned=False)
Return an integer given the size of the integer in bytes