src/map_asn1.c
changeset 639 0a2411d3d55a
child 640 65840a4ac45a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/map_asn1.c	Tue May 17 09:07:50 2016 +0200
     1.3 @@ -0,0 +1,67 @@
     1.4 +#include "pEp_internal.h"
     1.5 +#include "map_asn1.h"
     1.6 +
     1.7 +Identity_t *Identity_from_Struct(const pEp_identity *ident)
     1.8 +{
     1.9 +    Identity_t *result = (Identity_t *) calloc(1, sizeof(Identity_t));
    1.10 +    assert(result);
    1.11 +    if (!result)
    1.12 +        return NULL;
    1.13 +
    1.14 +    if (ident->address) {
    1.15 +        result->address = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
    1.16 +                ident->address, -1);
    1.17 +        if (ident->address && !result->address)
    1.18 +            goto enomem;
    1.19 +    }
    1.20 +
    1.21 +    if (ident->fpr) {
    1.22 +        if (OCTET_STRING_fromString(&result->fpr, ident->fpr))
    1.23 +            goto enomem;
    1.24 +    }
    1.25 +
    1.26 +    if (ident->user_id) {
    1.27 +        result->user_id = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
    1.28 +                ident->user_id, -1);
    1.29 +        if (ident->user_id && !result->user_id)
    1.30 +            goto enomem;
    1.31 +    }
    1.32 +
    1.33 +    if (ident->username) {
    1.34 +        result->username = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
    1.35 +                ident->username, -1);
    1.36 +        if (ident->username && !result->username)
    1.37 +            goto enomem;
    1.38 +    }
    1.39 +
    1.40 +    if (ident->comm_type != PEP_ct_unknown) {
    1.41 +        result->comm_type = malloc(sizeof(long));
    1.42 +        assert(result->comm_type);
    1.43 +        if (!result->comm_type)
    1.44 +            goto enomem;
    1.45 +        *result->comm_type = ident->comm_type;
    1.46 +    }
    1.47 +
    1.48 +    if (ident->lang[0]) {
    1.49 +        result->lang = OCTET_STRING_new_fromBuf(&asn_DEF_ISO936_1,
    1.50 +                ident->lang, 2);
    1.51 +        if (!result->lang)
    1.52 +            goto enomem;
    1.53 +    }
    1.54 +    
    1.55 +    return result;
    1.56 +
    1.57 +enomem:
    1.58 +    asn_DEF_UTF8String.free_struct(&asn_DEF_UTF8String, result, 0);
    1.59 +    return NULL;
    1.60 +}
    1.61 +
    1.62 +pEp_identity *Identity_to_Struct(Identity_t *ident)
    1.63 +{
    1.64 +    pEp_identity *result = new_identity(NULL, NULL, NULL, NULL);
    1.65 +    if (!result)
    1.66 +        return NULL;
    1.67 +
    1.68 +    return result;
    1.69 +}
    1.70 +