converting KeyList
authorVolker Birk <vb@pep-project.org>
Tue, 17 May 2016 20:56:41 +0200
changeset 6450bb373719dce
parent 640 65840a4ac45a
child 646 926cb97b8256
converting KeyList
src/map_asn1.c
src/map_asn1.h
test/Makefile
     1.1 --- a/src/map_asn1.c	Tue May 17 12:55:55 2016 +0200
     1.2 +++ b/src/map_asn1.c	Tue May 17 20:56:41 2016 +0200
     1.3 @@ -3,6 +3,10 @@
     1.4  
     1.5  Identity_t *Identity_from_Struct(const pEp_identity *ident)
     1.6  {
     1.7 +    assert(ident);
     1.8 +    if (!ident)
     1.9 +        return NULL;
    1.10 +
    1.11      Identity_t *result = (Identity_t *) calloc(1, sizeof(Identity_t));
    1.12      assert(result);
    1.13      if (!result)
    1.14 @@ -52,12 +56,16 @@
    1.15      return result;
    1.16  
    1.17  enomem:
    1.18 -    asn_DEF_UTF8String.free_struct(&asn_DEF_UTF8String, result, 0);
    1.19 +    ASN_STRUCT_FREE(asn_DEF_Identity, result);
    1.20      return NULL;
    1.21  }
    1.22  
    1.23  pEp_identity *Identity_to_Struct(Identity_t *ident)
    1.24  {
    1.25 +    assert(ident);
    1.26 +    if (!ident)
    1.27 +        return NULL;
    1.28 +    
    1.29      pEp_identity *result = new_identity(NULL, NULL, NULL, NULL);
    1.30      if (!result)
    1.31          return NULL;
    1.32 @@ -75,8 +83,6 @@
    1.33      if (!result->fpr)
    1.34          goto enomem;
    1.35  
    1.36 -    return result;
    1.37 -
    1.38      if (ident->user_id) {
    1.39          result->user_id = strndup((char *) ident->user_id->buf,
    1.40                  ident->user_id->size);
    1.41 @@ -108,3 +114,63 @@
    1.42      return NULL;
    1.43  }
    1.44  
    1.45 +KeyList_t *KeyList_from_stringlist(const stringlist_t *list)
    1.46 +{
    1.47 +    assert(list);
    1.48 +    if (!list)
    1.49 +        return NULL;
    1.50 +
    1.51 +    KeyList_t *result = (KeyList_t *) calloc(1, sizeof(KeyList_t));
    1.52 +    assert(result);
    1.53 +    if (!result)
    1.54 +        return NULL;
    1.55 +
    1.56 +    for (const stringlist_t *l = list; l && l->value; l=l->next) {
    1.57 +        Hash_t key;
    1.58 +        memset(&key, 0, sizeof(Hash_t));
    1.59 +        if (OCTET_STRING_fromBuf(&key, l->value, -1))
    1.60 +            goto enomem;
    1.61 +
    1.62 +        int r = ASN_SEQUENCE_ADD(&result->list, &key);
    1.63 +        ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_Hash, &key);
    1.64 +        if (r)
    1.65 +            goto enomem;
    1.66 +    }
    1.67 +
    1.68 +    return result;
    1.69 +
    1.70 +enomem:
    1.71 +    ASN_STRUCT_FREE(asn_DEF_KeyList, result);
    1.72 +    return NULL;
    1.73 +}
    1.74 +
    1.75 +stringlist_t *KeyList_to_stringlist(KeyList_t *list)
    1.76 +{
    1.77 +    assert(list);
    1.78 +    if (!list)
    1.79 +        return NULL;
    1.80 +
    1.81 +    stringlist_t *result = new_stringlist(NULL);
    1.82 +    if (!result)
    1.83 +        return NULL;
    1.84 +
    1.85 +    stringlist_t *r = result;
    1.86 +    for (int i=0; i<list->list.count; i++) {
    1.87 +        char *str = strndup((char *) list->list.array[i]->buf,
    1.88 +                list->list.array[i]->size);
    1.89 +        assert(str);
    1.90 +        if (!str)
    1.91 +            goto enomem;
    1.92 +        r = stringlist_add(r, str);
    1.93 +        free(str);
    1.94 +        if (!r)
    1.95 +            goto enomem;
    1.96 +    }
    1.97 +
    1.98 +    return result;
    1.99 +
   1.100 +enomem:
   1.101 +    free_stringlist(result);
   1.102 +    return NULL;
   1.103 +}
   1.104 +
     2.1 --- a/src/map_asn1.h	Tue May 17 12:55:55 2016 +0200
     2.2 +++ b/src/map_asn1.h	Tue May 17 20:56:41 2016 +0200
     2.3 @@ -3,6 +3,18 @@
     2.4  #include "pEpEngine.h"
     2.5  #include "stringlist.h"
     2.6  #include "../asn.1/Identity.h"
     2.7 +#include "../asn.1/KeyList.h"
     2.8 +
     2.9 +#ifdef __cplusplus
    2.10 +extern "C" {
    2.11 +#endif
    2.12  
    2.13  Identity_t *Identity_from_Struct(const pEp_identity *ident);
    2.14  pEp_identity *Identity_to_Struct(Identity_t *ident);
    2.15 +KeyList_t *KeyList_from_stringlist(const stringlist_t *list);
    2.16 +stringlist_t *KeyList_to_stringlist(KeyList_t *list);
    2.17 +
    2.18 +#ifdef __cplusplus
    2.19 +}
    2.20 +#endif
    2.21 +
     3.1 --- a/test/Makefile	Tue May 17 12:55:55 2016 +0200
     3.2 +++ b/test/Makefile	Tue May 17 20:56:41 2016 +0200
     3.3 @@ -4,8 +4,8 @@
     3.4  CXX?=g++ -std=gnu++11 -pthread
     3.5  LD?=$(CXX)
     3.6  LDFLAGS?=-L$(HOME)/lib
     3.7 -LDLIBS?=-letpan -lpEpEngine -lstdc++
     3.8 -CXXFLAGS?=-g -O0 -I../src
     3.9 +LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
    3.10 +CXXFLAGS?=-g -O0 -I../src -I../asn.1
    3.11  # CXXFLAGS=-O3 -DNDEBUG
    3.12  
    3.13  ifeq ("$(OPENPGP)","NETPGP")