Rate This Document
Findability
Accuracy
Completeness
Readability

Interface Parameters

In the interface definition of KSL_ASN1 library functions, encoding and decoding interfaces for specific data types are provided for various formats, among which DER and BER share the same set of interfaces and use the method field in AsnCtx for distinguishing.

Interface names are in the AsnBerEncodexx or AsnBerDecodexx format. (xx indicates the data type). The return value of each interface is void. Interface parameters are described as follows:

  • desc: descriptor structure (input)
  • stru: user structure (input for encoding interfaces and output for decoding interfaces)
  • ctx: context structure (input/output)

KSL_ASN1 provides unified encoding and decoding interfaces AsnEncode and AsnDecode. The interfaces determine the encoding format through ctx.method. The interface definition is as follows:

/**
 * @brief Encoding interface
 * @attention Clear variables of the ctx parameter, and then assign values to its buf and method fields.
 * @param desc [IN] Descriptor structure
 * @param stru [IN] User structure
 * @param ctx  [IN/OUT] Context structure
 * @return ≥ 0 Encoding success. The length of the encoded data is returned. (The unit is bit for PER and byte for other formats.)
 * @return < 0 Encoding failure. The absolute value of the return is the error code, and the error information can be found in asn_codec_errors.h.
 */
ssize_t AsnEncode(const AsnDesc *desc, const void *stru, AsnCtx *ctx);

/**
 * @brief Decoding interface
 * @attention Clear variables of the ctx parameter, and then assign values to its buf and method fields.
 * @param desc [IN] Descriptor structure
 * @param stru [OUT] User structure
 * @param ctx  [IN/OUT] Context structure
 * @return ≥ 0 Decoding success. The length of the decoded data is returned. (The unit is bit for PER and byte for other formats.)
 * @return < 0 Decoding failure. The absolute value of the return is the error code, and the error information can be found in asn_codec_errors.h.
 */
ssize_t AsnDecode(const AsnDesc *desc, void *stru, AsnCtx *ctx);