Library asn1
ASN.1 functions.
Large chunks of this code have been ripped right out from snmp.lua.
Author:
| Patrik Karlsson |
Copyright© Same as Nmap--See http://nmap.org/book/man-legal.html
Source: http://nmap.org/svn/nselib/asn1.lua
Functions
| BERtoInt (class, constructed, number) |
Converts a BER encoded type to a numeric value This allows it to be used in the encoding function |
| dec (self, encStr, pos) |
Decodes an SNMP packet or a part of it according to ASN.1 basic encoding rules. |
| decode (self, encStr, pos) |
Decodes the ASN.1's built-in simple types |
| decodeInt (encStr, len, pos) |
Decodes an Integer according to ASN.1 basic encoding rules. |
| decodeLength (encStr, pos) |
Decodes length part of encoded value according to ASN.1 basic encoding rules. |
| decodeLength (encStr, pos) |
Decodes length part of encoded value according to ASN.1 basic encoding rules. |
| decodeOID (self, encStr, len, pos) |
Decodes an OID from a sequence of bytes. |
| decodeSeq (self, encStr, len, pos) |
Decodes a sequence according to ASN.1 basic encoding rules. |
| encode (self, val) |
Encodes a given value according to ASN.1 basic encoding rules for SNMP packet creation. |
| encodeInt (val) |
Encodes an Integer according to ASN.1 basic encoding rules. |
| encodeLength (len) |
Encodes the length part of a ASN.1 encoding triplet using the "primitive, definite-length" method. |
| encodeSeq (self, seqData) |
Encodes an ASN1 sequence, the value of 30 below breaks down as 0x30 = 00110000 = 00 1 10000 hex binary Universal Constructed value Data Type = SEQUENCE (16) |
| intToBER (i) |
Converts an integer to a BER encoded type table |
| registerBaseDecoders (self) |
Registers the base simple type decoders |
| registerTagDecoders (self, tagDecoders) |
Allows for registration of additional tag decoders |
| registerTagEncoders (self, tagEncoders) |
Allows for registration of additional tag encoders |
| setStopOnError (self, val) |
Tells the decoder to stop if it detects an error while decoding this should probably be the default, but some scripts depend on being able to decode stuff while lacking proper ASN1 decoding functions. |
Functions
- BERtoInt (class, constructed, number)
-
Converts a BER encoded type to a numeric value This allows it to be used in the encoding function
Parameters
- class: number - see <code>BERCLASS<code>
- constructed: boolean (true if constructed, false if primitive)
- number: numeric
Return value:
number to be used withencode - dec (self, encStr, pos)
-
Decodes an SNMP packet or a part of it according to ASN.1 basic encoding rules.
Parameters
- self:
- encStr: Encoded string.
- pos: Current position in the string.
Return value:
The decoded value(s). - decode (self, encStr, pos)
-
Decodes the ASN.1's built-in simple types
Parameters
- self:
- encStr: Encoded string.
- pos: Current position in the string.
Return values:
- The position after decoding
- The decoded value(s).
- decodeInt (encStr, len, pos)
-
Decodes an Integer according to ASN.1 basic encoding rules.
Parameters
- encStr: Encoded string.
- len: Length of integer in bytes.
- pos: Current position in the string.
Return values:
- The position after decoding.
- The decoded integer.
- decodeLength (encStr, pos)
-
Decodes length part of encoded value according to ASN.1 basic encoding rules.
Parameters
- encStr: Encoded string.
- pos: Current position in the string.
Return values:
- The position after decoding.
- The length of the following value.
- decodeLength (encStr, pos)
-
Decodes length part of encoded value according to ASN.1 basic encoding rules.
Parameters
- encStr: Encoded string.
- pos: Current position in the string.
Return values:
- The position after decoding.
- The length of the following value.
- decodeOID (self, encStr, len, pos)
-
Decodes an OID from a sequence of bytes.
Parameters
- self:
- encStr: Encoded string.
- len: Length of sequence in bytes.
- pos: Current position in the string.
Return values:
- The position after decoding.
- The OID as an array.
- decodeSeq (self, encStr, len, pos)
-
Decodes a sequence according to ASN.1 basic encoding rules.
Parameters
- self:
- encStr: Encoded string.
- len: Length of sequence in bytes.
- pos: Current position in the string.
Return values:
- The position after decoding.
- The decoded sequence as a table.
- encode (self, val)
-
Encodes a given value according to ASN.1 basic encoding rules for SNMP packet creation.
Parameters
- self:
- val: Value to be encoded.
Return value:
Encoded value. - encodeInt (val)
-
Encodes an Integer according to ASN.1 basic encoding rules.
Parameters
- val: Value to be encoded.
Return value:
Encoded integer. - encodeLength (len)
-
Encodes the length part of a ASN.1 encoding triplet using the "primitive, definite-length" method.
Parameters
- len: Length to be encoded.
Return value:
Encoded length value. - encodeSeq (self, seqData)
-
Encodes an ASN1 sequence, the value of 30 below breaks down as 0x30 = 00110000 = 00 1 10000 hex binary Universal Constructed value Data Type = SEQUENCE (16)
Parameters
- self:
- seqData:
- intToBER (i)
-
Converts an integer to a BER encoded type table
Parameters
- i: number containing the value to decode
Return value:
table with the following entriesclass,constructed,primitiveandnumber - registerBaseDecoders (self)
-
Registers the base simple type decoders
Parameters
- self:
- registerTagDecoders (self, tagDecoders)
-
Allows for registration of additional tag decoders
Parameters
- self:
- tagDecoders: table containing decoding functions @see tagDecoders
- registerTagEncoders (self, tagEncoders)
-
Allows for registration of additional tag encoders
Parameters
- self:
- tagEncoders: table containing encoding functions @see tagEncoders
- setStopOnError (self, val)
-
Tells the decoder to stop if it detects an error while decoding this should probably be the default, but some scripts depend on being able to decode stuff while lacking proper ASN1 decoding functions.
Parameters
- self:
- val: boolean, true if decoding should stop on error, otherwise false (default)


