ASN1::encode

Description

This command is used to encode ASN.1 records. encodingType specifies the encoding type (BER|DER). Data is provided via the listed values and formatted according to formatString. Returns a byte array containing the encoded data.

Syntax

ASN1::encode encodingType formatString ?value value ...?
ASN1::encode insert element offset formatString ?value value ...?
ASN1::encode replace element offset formatString ?value value ...?

formatString can have the following characters:
  • a - Octet String
  • B - Bit String
  • b - Boolean
  • e - Enum
  • i - Integer
  • t - Tag of next element
  • ? - Don’t output the component if the corresponding value is empty
  • ?hex-tag - Denotes that the specifier which follows is for an optional component. This is used for encoding or decoding an ASN.1 Set or Sequence which contains nested OPTIONAL or DEFAULT components. hex-tag, is a two-character hex byte of the expected tag. When used with the decode command, if the component corresponding to the optional specifier is not found, the corresponding tcl variable will be unset. This allows the iRule to use the Tcl info exists command to test the variable to determine if the component was found. See the following section for more details and examples.
  • ( - Begin Sequence. No corresponding parameter is specified. The initial sequence tag and length are skipped.
  • ) - End Sequence. No corresponding parameter is specified.
  • < - Begin Set. No corresponding parameter is specified. The initial sequence tag and length are skipped.
  • > - End Set. No corresponding parameter is specified.

ASN1::encode encodingType formatString ?value value …?

  • Used to encode ASN.1 records. encodingType specifies the encoding type (BER|DER). Data is provided via the listed values and formatted according to formatString. Returns a byte array containing the encoded data.

ASN1::encode insert element offset formatString ?value value …?

  • Same as above except that the encoded data is inserted at the location specified by element and offset. and made ready for egress. Prependding can be accomplished by specifying an offset of 0

ASN1::encode replace element offset formatString ?value value …?

  • Same as above except that the encoded data replaces the existing data at the location specified by element and offset. and made ready for egress.

Examples

if { $dnAttrs == 0 } {
  # dnAttrs is 0 (False) which is the ASN.1 defined default, so set it to "" so it won't be encoded
  set dnAttrs ""
}
ASN1::encode "?a?aa?b" ruleId type matchValue dnAttrs