src/map_asn1.c
author Volker Birk <vb@pep-project.org>
Tue, 17 May 2016 09:07:50 +0200
changeset 639 0a2411d3d55a
child 640 65840a4ac45a
permissions -rw-r--r--
mapping internal to ASN.1 types
vb@639
     1
#include "pEp_internal.h"
vb@639
     2
#include "map_asn1.h"
vb@639
     3
vb@639
     4
Identity_t *Identity_from_Struct(const pEp_identity *ident)
vb@639
     5
{
vb@639
     6
    Identity_t *result = (Identity_t *) calloc(1, sizeof(Identity_t));
vb@639
     7
    assert(result);
vb@639
     8
    if (!result)
vb@639
     9
        return NULL;
vb@639
    10
vb@639
    11
    if (ident->address) {
vb@639
    12
        result->address = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
vb@639
    13
                ident->address, -1);
vb@639
    14
        if (ident->address && !result->address)
vb@639
    15
            goto enomem;
vb@639
    16
    }
vb@639
    17
vb@639
    18
    if (ident->fpr) {
vb@639
    19
        if (OCTET_STRING_fromString(&result->fpr, ident->fpr))
vb@639
    20
            goto enomem;
vb@639
    21
    }
vb@639
    22
vb@639
    23
    if (ident->user_id) {
vb@639
    24
        result->user_id = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
vb@639
    25
                ident->user_id, -1);
vb@639
    26
        if (ident->user_id && !result->user_id)
vb@639
    27
            goto enomem;
vb@639
    28
    }
vb@639
    29
vb@639
    30
    if (ident->username) {
vb@639
    31
        result->username = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
vb@639
    32
                ident->username, -1);
vb@639
    33
        if (ident->username && !result->username)
vb@639
    34
            goto enomem;
vb@639
    35
    }
vb@639
    36
vb@639
    37
    if (ident->comm_type != PEP_ct_unknown) {
vb@639
    38
        result->comm_type = malloc(sizeof(long));
vb@639
    39
        assert(result->comm_type);
vb@639
    40
        if (!result->comm_type)
vb@639
    41
            goto enomem;
vb@639
    42
        *result->comm_type = ident->comm_type;
vb@639
    43
    }
vb@639
    44
vb@639
    45
    if (ident->lang[0]) {
vb@639
    46
        result->lang = OCTET_STRING_new_fromBuf(&asn_DEF_ISO936_1,
vb@639
    47
                ident->lang, 2);
vb@639
    48
        if (!result->lang)
vb@639
    49
            goto enomem;
vb@639
    50
    }
vb@639
    51
    
vb@639
    52
    return result;
vb@639
    53
vb@639
    54
enomem:
vb@639
    55
    asn_DEF_UTF8String.free_struct(&asn_DEF_UTF8String, result, 0);
vb@639
    56
    return NULL;
vb@639
    57
}
vb@639
    58
vb@639
    59
pEp_identity *Identity_to_Struct(Identity_t *ident)
vb@639
    60
{
vb@639
    61
    pEp_identity *result = new_identity(NULL, NULL, NULL, NULL);
vb@639
    62
    if (!result)
vb@639
    63
        return NULL;
vb@639
    64
vb@639
    65
    return result;
vb@639
    66
}
vb@639
    67