Browse Source

adding distribution_codec

add_key_notification
Volker Birk 3 years ago
parent
commit
0fa20d9951
4 changed files with 252 additions and 10 deletions
  1. +134
    -0
      src/distribution_codec.c
  2. +82
    -0
      src/distribution_codec.h
  3. +34
    -8
      src/key_reset.c
  4. +2
    -2
      src/key_reset.h

+ 134
- 0
src/distribution_codec.c View File

@ -0,0 +1,134 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "platform.h"
#include "distribution_codec.h"
#include "../asn.1/Distribution.h"
#include "pEp_internal.h"
#include "growing_buf.h"
DYNAMIC_API PEP_STATUS decode_Distribution_message(
const char *data,
size_t size,
Distribution_t **msg
)
{
assert(data && msg);
if (!(data && msg))
return PEP_ILLEGAL_VALUE;
*msg = NULL;
Distribution_t *_msg = NULL;
uper_decode_complete(NULL, &asn_DEF_Distribution, (void **) &_msg, data, size);
if (!_msg)
return PEP_DISTRIBUTION_ILLEGAL_MESSAGE;
*msg = _msg;
return PEP_STATUS_OK;
}
PEP_STATUS encode_Distribution_message(
Distribution_t *msg,
char **data,
size_t *size
)
{
assert(data && msg);
if (!(data && msg))
return PEP_ILLEGAL_VALUE;
*data = NULL;
*size = 0;
char *_data = NULL;
ssize_t _size = uper_encode_to_new_buffer(&asn_DEF_Distribution, NULL, msg,
(void **) &_data);
if (_size == -1)
return PEP_CANNOT_ENCODE;
*data = _data;
*size = (size_t) _size;
return PEP_STATUS_OK;
}
PEP_STATUS PER_to_XER_Distribution_msg(
const char *data,
size_t size,
char **text
)
{
PEP_STATUS status = PEP_STATUS_OK;
growing_buf_t *dst = NULL;
assert(data && text);
if (!(data && text))
return PEP_ILLEGAL_VALUE;
*text = NULL;
Distribution_t *msg = NULL;
status = decode_Distribution_message(data, size, &msg);
if (status)
goto the_end;
dst = new_growing_buf();
if (!dst) {
status = PEP_OUT_OF_MEMORY;
goto the_end;
}
asn_enc_rval_t er = xer_encode(&asn_DEF_Distribution, msg, XER_F_BASIC,
(asn_app_consume_bytes_f *) growing_buf_consume, (void *) dst);
if (er.encoded == -1) {
status = PEP_CANNOT_ENCODE;
goto the_end;
}
*text = dst->data;
dst->data = NULL;
the_end:
free_growing_buf(dst);
ASN_STRUCT_FREE(asn_DEF_Distribution, msg);
return status;
}
PEP_STATUS XER_to_PER_Distribution_msg(
const char *text,
char **data,
size_t *size
)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(text && data && size);
if (!(text && data && size))
return PEP_ILLEGAL_VALUE;
*data = NULL;
*size = 0;
Distribution_t *msg = NULL;
asn_dec_rval_t dr = xer_decode(NULL, &asn_DEF_Distribution, (void **) &msg,
(const void *) text, strlen(text));
if (dr.code != RC_OK) {
status = PEP_DISTRIBUTION_ILLEGAL_MESSAGE;
goto the_end;
}
char *_data = NULL;
size_t _size = 0;
status = encode_Distribution_message(msg, &_data, &_size);
if (status)
goto the_end;
*data = _data;
*size = (size_t) _size;
the_end:
ASN_STRUCT_FREE(asn_DEF_Distribution, msg);
return status;
}

+ 82
- 0
src/distribution_codec.h View File

@ -0,0 +1,82 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#include "pEpEngine.h"
#ifdef __cplusplus
extern "C" {
#endif
struct Distribution;
// decode_Distribution_message() - decode PER encoded Distribution message
//
// parameters:
// data (in) PER encoded data
// size (in) size of PER encoded data
// msg (out) Distribution message
//
// caveat:
// msg goes into the ownership of the caller
DYNAMIC_API PEP_STATUS decode_Distribution_message(
const char *data,
size_t size,
struct Distribution **msg
);
// encode_Distribution_message() - encode Distribution message into PER encoded data
//
// parameters:
// msg (in) Distribution message
// data (out) PER encoded data
// size (out) size of PER encoded data
//
// caveat:
// data goes to the ownership of the caller
DYNAMIC_API PEP_STATUS encode_Distribution_message(
struct Distribution *msg,
char **data,
size_t *size
);
// PER_to_XER_Distribution_msg() - decode Distribution message from PER into XER
//
// parameters:
// data (in) PER encoded data
// size (in) size of PER encoded data
// text (out) XER text of the same Distribution message
DYNAMIC_API PEP_STATUS PER_to_XER_Distribution_msg(
const char *data,
size_t size,
char **text
);
// XER_to_PER_Distribution_msg() - encode Distribution message from XER into PER
//
// parameters:
// text (in) string with XER text of the Distribution message
// data (out) PER encoded data
// size (out) size of PER encoded data
DYNAMIC_API PEP_STATUS XER_to_PER_Distribution_msg(
const char *text,
char **data,
size_t *size
);
#ifdef __cplusplus
}
#endif

+ 34
- 8
src/key_reset.c View File

@ -5,7 +5,9 @@
#include "dynamic_api.h"
#include "message_api.h"
#include "key_reset.h"
#include "distribution_codec.h"
#include "map_asn1.h"
#include "../asn.1/Distribution.h"
#include <string.h>
#include <stdlib.h>
@ -707,19 +709,43 @@ PEP_STATUS key_reset_own_and_deliver_revocations(PEP_SESSION session,
return PEP_STATUS_OK;
}
PEP_STATUS key_reset_commands_to_binary(const keyreset_command_list *kcl, char **cmds)
PEP_STATUS key_reset_commands_to_PER(const keyreset_command_list *command_list, char **cmds)
{
assert(kcl && cmds);
if (!(kcl && cmds))
PEP_STATUS status = PEP_STATUS_OK;
assert(command_list && cmds);
if (!(command_list && cmds))
return PEP_ILLEGAL_VALUE;
return PEP_STATUS_OK;
for (const keyreset_command_list *cl = command_list; cl && cl->command; cl = cl->next) {
Commands_t *c = calloc(1, sizeof(Commands_t));
assert(c);
if (!c)
goto enomem;
if (!Identity_from_Struct(cl->command->ident, &c->ident)) {
free(c);
goto enomem;
}
if (OCTET_STRING_fromString(&c->newkey, cl->command->new_key)) {
ASN_STRUCT_FREE(asn_DEF_Identity, &c->ident);
free(c);
goto enomem;
}
}
enomem:
status = PEP_OUT_OF_MEMORY;
the_end:
return status;
}
PEP_STATUS binary_to_key_reset_commands(const char **cmds, keyreset_command_list **kcl)
PEP_STATUS PER_to_key_reset_commands(const char **cmds, keyreset_command_list **command_list)
{
assert(kcl && cmds);
if (!(kcl && cmds))
assert(command_list && cmds);
if (!(command_list && cmds))
return PEP_ILLEGAL_VALUE;
return PEP_STATUS_OK;


+ 2
- 2
src/key_reset.h View File

@ -165,8 +165,8 @@ PEP_STATUS send_key_reset_to_recents(PEP_SESSION session,
const char* old_fpr,
const char* new_fpr);
PEP_STATUS key_reset_commands_to_binary(const keyreset_command_list *kcl, char **cmds);
PEP_STATUS binary_to_key_reset_commands(const char **cmds, keyreset_command_list **kcl);
PEP_STATUS key_reset_commands_to_PER(const keyreset_command_list *command_list, char **cmds);
PEP_STATUS PER_to_key_reset_commands(const char **cmds, keyreset_command_list **command_list);
#ifdef __cplusplus
}


Loading…
Cancel
Save