Module asn1

asn1 module to generate or parse ASN.1 data.

Provide asn1_object, asn1_string, asn1_object as lua object.

Usage:

    asn1 = require('openssl').asn1
    

Functions

new_type () create asn1_type object
get_object (der[, start=1[, stop=-i]]) parse der encoded string
put_object (tag, class[, length=nil[, constructed=nil]]) do der encode and return encoded string partly head or full
tostring (clsortag, range) make tag, class number to string
new_string (data[, type]) create asn1_string object
new_integer (integer) create asn1_integer object
new_generalizedtime (time) create asn1_time object
new_utctime (time) create asn1_time object
txt2nid (txt) get nid for txt, which can be short name, long name, or numerical oid
new_object (name_or_oid[, no_name]) create asn1_object object
new_object (nid) create asn1_object object
new_object (options) create asn1_object object
asn1type_di2 (der) convert der encoded asn1type string to object

Class asn1_object

asn1_object:nid () get nid of asn1_object.
asn1_object:name () get name of asn1_object.
asn1_object:ln () get long name of asn1_object.
asn1_object:sn () get short name of asn1_object.
asn1_object:txt ([no_name]) get text of asn1_object.
asn1_object:equals (another) compare two asn1_objects, if equals return true
asn1_object:data () get data of asn1_object
asn1_object:dup () make a clone of asn1_object
asn1_object:d2i () read der in to asn1_object
asn1_object:i2d () get der encoded of asn1_object

Class asn1_string

asn1_string:set ()
asn1_string:get ()
asn1_string:i2d ()
asn1_string:d2i ()
asn1_string:type () get type of asn1_string
asn1_string:length () get length two asn1_string
asn1_string:data () get data of asn1_string
asn1_string:data (data) set data of asn1_string
asn1_string:equals (another) compare two asn1_string, if equals return true
asn1_string:__tostring () convert asn1_string to lua string
asn1_string:toprint () get data as printable encode string
asn1_string:toutf8 () get data as utf8 encode string
asn1_string:dup () duplicate a new asn1_string


Functions

new_type ()
create asn1_type object
get_object (der[, start=1[, stop=-i]])
parse der encoded string

Parameters:

  • der string string
  • start number offset to parse (default 1)
  • stop number offset to parse this like string.sub() (default -i)

Returns:

  1. number tag
  2. number class
  3. number parsed data start offset
  4. number parsed data stop offset
  5. boolean true for constructed data

Or

  1. nil for fail
  2. string error msg
  3. number inner error code
put_object (tag, class[, length=nil[, constructed=nil]])
do der encode and return encoded string partly head or full

Parameters:

  • tag number
  • class number
  • length number or string or date to encode, defualt will make indefinite length constructed (default nil)
  • constructed boolean or not (default nil)

Returns:

    string der encoded string or head when not give data
tostring (clsortag, range)
make tag, class number to string

Parameters:

  • clsortag number which to string
  • range string only accept ‘class’ or ‘tag’
new_string (data[, type])
create asn1_string object

asn1_string object support types: “integer”, “enumerated”, “bit”, “octet”, “utf8”, “numeric”, “printable”, “t61”, “teletex”, “videotex”, “ia5”, “graphics”, “iso64”, “visible”, “general”, “unversal”, “bmp”, “utctime”

Parameters:

  • data string to create new asn1_string
  • type string asn1 string type, defult with ‘utf8’ (optional)

Returns:

    asn1_string

See also:

new_integer (integer)
create asn1_integer object

Parameters:

  • integer number or bn to create new asn1_integer

Returns:

    asn1_integer

See also:

new_generalizedtime (time)
create asn1_time object

Parameters:

Returns:

    asn1_time
new_utctime (time)
create asn1_time object

Parameters:

Returns:

    asn1_time
txt2nid (txt)
get nid for txt, which can be short name, long name, or numerical oid

Parameters:

Returns:

    integer nid or nil on fail
new_object (name_or_oid[, no_name])
create asn1_object object

Parameters:

  • name_or_oid string short name,long name or oid string
  • no_name boolean true for only oid string, default is false (optional)

Returns:

    asn1_object mapping to ASN1_OBJECT in openssl

See also:

new_object (nid)
create asn1_object object

Parameters:

  • nid integer ident to asn1_object

Returns:

    asn1_object mapping to ASN1_OBJECT in openssl

See also:

new_object (options)
create asn1_object object

Parameters:

  • options table have sn, ln, oid keys to create asn1_object

Returns:

    asn1_object mapping to ASN1_OBJECT in openssl

See also:

asn1type_di2 (der)
convert der encoded asn1type string to object

Parameters:

Returns:

    asn1type object for success, and nil for fail

Class asn1_object

openssl.asn1_object object
asn1_object:nid ()
get nid of asn1_object.

Returns:

    integer nid of asn1_object
asn1_object:name ()
get name of asn1_object.

Returns:

    string short name and followed by long name of asn1_object
asn1_object:ln ()
get long name of asn1_object.

Returns:

    string long name of asn1_object
asn1_object:sn ()
get short name of asn1_object.

Returns:

    string short name of asn1_object
asn1_object:txt ([no_name])
get text of asn1_object.

Parameters:

  • no_name boolean true for only oid or name, default with false (optional)

Returns:

    string long or short name, even oid of asn1_object
asn1_object:equals (another)
compare two asn1_objects, if equals return true

Parameters:

  • another asn1_object to compre

Returns:

    boolean true if equals
asn1_object:data ()
get data of asn1_object

Returns:

    string asn1_object data
asn1_object:dup ()
make a clone of asn1_object

Returns:

    asn1_object clone for self
asn1_object:d2i ()
read der in to asn1_object

Returns:

    boolean
asn1_object:i2d ()
get der encoded of asn1_object

Returns:

    string

Class asn1_string

openssl.asn1_string object
asn1_string:set ()
asn1_string:get ()
asn1_string:i2d ()
asn1_string:d2i ()
asn1_string:type ()
get type of asn1_string

Returns:

    string type of asn1_string

See also:

asn1_string:length ()
get length two asn1_string

Returns:

    integer length of asn1_string

Usage:

    local astr = asn1.new_string('ABCD')
    print('length:',#astr)
    print('length:',astr:length())
    assert(#astr==astr:length,"must equals")
asn1_string:data ()
get data of asn1_string

Returns:

    string raw data of asn1_string
asn1_string:data (data)
set data of asn1_string

Parameters:

  • data string set to asn1_string

Returns:

  1. boolean success if value set true, or follow by errmsg
  2. string fail error message
asn1_string:equals (another)
compare two asn1_string, if equals return true

Parameters:

  • another asn1_string to compre

Returns:

    boolean true if equals

Usage:

    local obj = astr:dup()
    assert(obj==astr, "must equals")
asn1_string:__tostring ()
convert asn1_string to lua string

Returns:

    string result format match with type:data
asn1_string:toprint ()
get data as printable encode string

Returns:

    string printable encoded string
asn1_string:toutf8 ()
get data as utf8 encode string

Returns:

    string utf8 encoded string
asn1_string:dup ()
duplicate a new asn1_string

Returns:

    asn1_string clone for self
generated by LDoc 1.5.0 Last updated 2024-01-20 16:21:56