implementation of key_reset_commands_to_PER() sync
authorVolker Birk <vb@pep-project.org>
Wed, 11 Dec 2019 19:13:05 +0100
branchsync
changeset 42617836981785d3
parent 4260 a5d462cd4724
child 4262 8c0781e8dd04
implementation of key_reset_commands_to_PER()
src/key_reset.c
src/key_reset.h
     1.1 --- a/src/key_reset.c	Wed Dec 11 17:31:50 2019 +0100
     1.2 +++ b/src/key_reset.c	Wed Dec 11 19:13:05 2019 +0100
     1.3 @@ -709,7 +709,7 @@
     1.4      return PEP_STATUS_OK;
     1.5  }
     1.6  
     1.7 -PEP_STATUS key_reset_commands_to_PER(const keyreset_command_list *command_list, char **cmds)
     1.8 +PEP_STATUS key_reset_commands_to_PER(const keyreset_command_list *command_list, char **cmds, size_t *size)
     1.9  {
    1.10      PEP_STATUS status = PEP_STATUS_OK;
    1.11  
    1.12 @@ -717,6 +717,19 @@
    1.13      if (!(command_list && cmds))
    1.14          return PEP_ILLEGAL_VALUE;
    1.15  
    1.16 +    *cmds = NULL;
    1.17 +    *size = 0;
    1.18 +
    1.19 +    Distribution_t *dist = (Distribution_t *) calloc(1, sizeof(Distribution_t));
    1.20 +    assert(dist);
    1.21 +    if (!dist)
    1.22 +        goto enomem;
    1.23 +
    1.24 +    dist->present = Distribution_PR_keyreset;
    1.25 +    dist->choice.keyreset.present = KeyReset_PR_commands;
    1.26 +
    1.27 +    // convert to ASN.1 struct
    1.28 +
    1.29      for (const keyreset_command_list *cl = command_list; cl && cl->command; cl = cl->next) {
    1.30          Command_t *c = (Command_t *) calloc(1, sizeof(Command_t));
    1.31          assert(c);
    1.32 @@ -729,20 +742,39 @@
    1.33          }
    1.34  
    1.35          if (OCTET_STRING_fromString(&c->newkey, cl->command->new_key)) {
    1.36 -            ASN_STRUCT_FREE(asn_DEF_Identity, &c->ident);
    1.37 -            free(c);
    1.38 +            ASN_STRUCT_FREE(asn_DEF_Command, c);
    1.39              goto enomem;
    1.40          }
    1.41 +
    1.42 +        if (ASN_SEQUENCE_ADD(&dist->choice.keyreset.choice.commands.commandlist, c)) {
    1.43 +            ASN_STRUCT_FREE(asn_DEF_Command, c);
    1.44 +            goto enomem;
    1.45 +        }
    1.46 +
    1.47 +        ASN_STRUCT_FREE(asn_DEF_Command, c);
    1.48      }
    1.49  
    1.50 +    // encode
    1.51 +
    1.52 +    char *_cmds;
    1.53 +    size_t _size;
    1.54 +    status = encode_Distribution_message(dist, &_cmds, &_size);
    1.55 +    if (status)
    1.56 +        goto the_end;
    1.57 +
    1.58 +    *cmds = _cmds;
    1.59 +    *size = _size;
    1.60 +    goto the_end;
    1.61 +
    1.62  enomem:
    1.63      status = PEP_OUT_OF_MEMORY;
    1.64  
    1.65  the_end:
    1.66 +    ASN_STRUCT_FREE(asn_DEF_Distribution, dist);
    1.67      return status;
    1.68  }
    1.69  
    1.70 -PEP_STATUS PER_to_key_reset_commands(const char **cmds, keyreset_command_list **command_list)
    1.71 +PEP_STATUS PER_to_key_reset_commands(const char *cmds, size_t size, keyreset_command_list **command_list)
    1.72  {
    1.73      assert(command_list && cmds);
    1.74      if (!(command_list && cmds))
     2.1 --- a/src/key_reset.h	Wed Dec 11 17:31:50 2019 +0100
     2.2 +++ b/src/key_reset.h	Wed Dec 11 19:13:05 2019 +0100
     2.3 @@ -165,8 +165,8 @@
     2.4                                       const char* old_fpr, 
     2.5                                       const char* new_fpr);
     2.6   
     2.7 -PEP_STATUS key_reset_commands_to_PER(const keyreset_command_list *command_list, char **cmds);
     2.8 -PEP_STATUS PER_to_key_reset_commands(const char **cmds, keyreset_command_list **command_list);
     2.9 +PEP_STATUS key_reset_commands_to_PER(const keyreset_command_list *command_list, char **cmds, size_t *size);
    2.10 +PEP_STATUS PER_to_key_reset_commands(const char *cmds, size_t size, keyreset_command_list **command_list);
    2.11  
    2.12  #ifdef __cplusplus
    2.13  }