adding PER_to_key_reset_commands() sync
authorVolker Birk <vb@pep-project.org>
Thu, 12 Dec 2019 06:21:11 +0100
branchsync
changeset 42628c0781e8dd04
parent 4261 7836981785d3
child 4263 a054945daada
adding PER_to_key_reset_commands()
src/key_reset.c
     1.1 --- a/src/key_reset.c	Wed Dec 11 19:13:05 2019 +0100
     1.2 +++ b/src/key_reset.c	Thu Dec 12 06:21:11 2019 +0100
     1.3 @@ -750,8 +750,6 @@
     1.4              ASN_STRUCT_FREE(asn_DEF_Command, c);
     1.5              goto enomem;
     1.6          }
     1.7 -
     1.8 -        ASN_STRUCT_FREE(asn_DEF_Command, c);
     1.9      }
    1.10  
    1.11      // encode
    1.12 @@ -780,6 +778,52 @@
    1.13      if (!(command_list && cmds))
    1.14          return PEP_ILLEGAL_VALUE;
    1.15  
    1.16 -    return PEP_STATUS_OK;
    1.17 +    *command_list = NULL;
    1.18 +    keyreset_command_list *result = NULL;
    1.19 +
    1.20 +    Distribution_t *dist = NULL;
    1.21 +    PEP_STATUS status = decode_Distribution_message(cmds, size, &dist);
    1.22 +    if (status)
    1.23 +        goto the_end;
    1.24 +
    1.25 +    if (!(dist && dist->present == Distribution_PR_keyreset
    1.26 +            && dist->choice.keyreset.present == KeyReset_PR_commands)) {
    1.27 +        status = PEP_DISTRIBUTION_ILLEGAL_MESSAGE;
    1.28 +        goto the_end;
    1.29 +    }
    1.30 +
    1.31 +    result = new_keyreset_command_list(NULL);
    1.32 +    if (!result)
    1.33 +        goto enomem;
    1.34 +
    1.35 +    struct Commands__commandlist *cl = &dist->choice.keyreset.choice.commands.commandlist;
    1.36 +    keyreset_command_list *_result = result;
    1.37 +    for (int i=0; i<cl->list.count; i++) {
    1.38 +        pEp_identity *ident = Identity_to_Struct(&cl->list.array[i]->ident, NULL);
    1.39 +        if (!ident)
    1.40 +            goto enomem;
    1.41 +
    1.42 +        const char *new_key = (const char *) cl->list.array[i]->newkey.buf;
    1.43 +        keyreset_command *command = new_keyreset_command(ident, new_key);
    1.44 +        if (!command) {
    1.45 +            free_identity(ident);
    1.46 +            goto enomem;
    1.47 +        }
    1.48 +
    1.49 +        _result = keyreset_command_list_add(_result, command);
    1.50 +        free_identity(ident);
    1.51 +        if (!_result)
    1.52 +            goto enomem;
    1.53 +    }
    1.54 +
    1.55 +    goto the_end;
    1.56 +
    1.57 +enomem:
    1.58 +    status = PEP_OUT_OF_MEMORY;
    1.59 +
    1.60 +the_end:
    1.61 +    ASN_STRUCT_FREE(asn_DEF_Distribution, dist);
    1.62 +    free_keyreset_command_list(result);
    1.63 +    return status;
    1.64  }
    1.65