asn.1工具的使用
来源:互联网 发布:nba历届总决赛数据 编辑:程序博客网 时间:2024/06/10 08:44
在http://lionet.info/asn1c/download.html下载asn1c-0.9.24.tar.gz
解压: tar -zxvf asn1c-0.9.24.tar.gz
进入: cd asn1c........
配置: ./configure
编译:make
安装:sudo make install
然后编写两个文件:
ubuntu:~/asn1ctemp/test$ vim rectangle.asn1
rectangle.asn1:
RectangleModule1DEFINITIONS ::=BEGINRectangle ::=SEQUENCE { height INTEGER, width INTEGER}END
执行命令
asn1c -fnative-types rectangle.asn1
可能没有 -fnative-types 这个参数,直接执行 asn1c rectangle.asn1
生成一堆编码用的.c,.h
我在当前路径下写代码:
gedit main.c
#include <stdio.h>#include <sys/types.h>#include <Rectangle.h> /* Rectangle ASN.1 type *//* Write the encoded output into some FILE stream. */static int write_out(const void *buffer, size_t size, void *app_key) {FILE *out_fp = app_key;size_t wrote = fwrite(buffer, 1, size, out_fp);return (wrote == size) ? 0 : -1;}int main(int ac, char **av) {Rectangle_t *rectangle; /* Type to encode */asn_enc_rval_t ec; /* Encoder return value *//* Allocate the Rectangle_t */rectangle = calloc(1, sizeof(Rectangle_t)); /* not malloc! */if(!rectangle) {perror("calloc() failed ");exit(1);}/* Initialize the Rectangle members */rectangle->height = 42; /* any random value */rectangle->width = 23; /* any random value *//* BER encode the data if filename is given */if(ac < 2) {fprintf(stderr," specify filename for BER output\n");} else {const char *filename = av[1];FILE *fp = fopen(filename, "wb"); /* for BER output */if(!fp) {perror(filename);exit(1);}/* Encode the Rectangle type as BER (DER) */ec = der_encode(&asn_DEF_Rectangle, rectangle, write_out, fp);fclose(fp);if(ec.encoded == -1) {fprintf(stderr, "”Could not encode Rectangle (at %s)\n”",ec.failed_type ? ec.failed_type->name : "unknown");exit(1);} else {fprintf(stderr, "”Created %s with BER encoded Rectangle\n”", filename);}}/* Also print the constructed Rectangle XER encoded (XML) */xer_fprint(stdout, &asn_DEF_Rectangle, rectangle);return 0; /* Encoding finished successfully */}
然后编译:gcc -I. *.c
注意这里必须是*.c ,要把所有的.c都编译
如果出错提示有未定义的函数,你把converter-sample.c 删掉,或者移到其他路径或名字,
因为这个文件文件也是一个例子,主函数
mv converter-sample.c converter-sample.c-
我是直接改了后缀名,然后再 gcc -I. *.c 就会生成a.out
运行./a.out
阅读全文
0 0
- asn.1工具的使用
- openssl asn.1使用
- asn.1的理解
- JAVA中使用ASN.1
- ASN.1
- ASN.1
- ASN.1
- asn.1
- ASN.1
- 一个开源的ASN.1编译器
- BouncyCastle的ASN.1编码功能探究
- MEye工具可以用于调试分析ASN.1编码
- ASN.1简介(1)
- Asn.1 resource
- ASN.1 encoding rules
- ASN.1 - dumper
- asn.1 reference
- ASN.1相关知识
- linux 增加虚拟内存
- git使用:虚拟机gitlab安装,即项目创建上传下载
- 移动web开发经验总结
- Java作业UDP
- nginx日志切割
- asn.1工具的使用
- iOS afnetworking 后台下载
- PHP array key会自动强制转换
- var和let区别
- spring mvc 5.0 @RequestMapping详解 03
- Ubuntu14.04登录界面无限死循环的解决方法
- 快速多尺度人脸检测--Multi-Scale Fully Convolutional Network for Fast Face Detection
- java1.8 -ConcurrentHashMap
- leetcode 611. Valid Triangle Number