|
Revision 305
(checked in by ben, 7 years ago)
|
Detached signatures still not working right.
|
| Line | |
|---|
| 1 |
#include "common.h" |
|---|
| 2 |
#include <openpgpsdk/util.h> |
|---|
| 3 |
#include <memory.h> |
|---|
| 4 |
#include <fcntl.h> |
|---|
| 5 |
#include <assert.h> |
|---|
| 6 |
|
|---|
| 7 |
static ops_parse_callback_return_t |
|---|
| 8 |
callback(const ops_parser_content_t *content,void *arg_) |
|---|
| 9 |
{ |
|---|
| 10 |
ops_secret_key_t **skey=arg_; |
|---|
| 11 |
|
|---|
| 12 |
if(content->tag == OPS_PTAG_CT_SECRET_KEY) |
|---|
| 13 |
{ |
|---|
| 14 |
*skey=malloc(sizeof **skey); |
|---|
| 15 |
memcpy(*skey,&content->content.secret_key,sizeof **skey); |
|---|
| 16 |
return OPS_KEEP_MEMORY; |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
return OPS_RELEASE_MEMORY; |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
ops_secret_key_t *get_secret_key(const char *keyfile) |
|---|
| 23 |
{ |
|---|
| 24 |
ops_reader_fd_arg_t arg; |
|---|
| 25 |
ops_parse_info_t parse_info; |
|---|
| 26 |
ops_secret_key_t *skey; |
|---|
| 27 |
|
|---|
| 28 |
ops_parse_info_init(&parse_info); |
|---|
| 29 |
parse_info.cb=callback; |
|---|
| 30 |
|
|---|
| 31 |
arg.fd=open(keyfile,O_RDONLY); |
|---|
| 32 |
assert(arg.fd >= 0); |
|---|
| 33 |
parse_info.reader_arg=&arg; |
|---|
| 34 |
parse_info.reader=ops_reader_fd; |
|---|
| 35 |
|
|---|
| 36 |
skey=NULL; |
|---|
| 37 |
parse_info.cb_arg=&skey; |
|---|
| 38 |
|
|---|
| 39 |
ops_parse(&parse_info); |
|---|
| 40 |
|
|---|
| 41 |
return skey; |
|---|
| 42 |
} |
|---|