test
authorVolker Birk <vb@pep-project.org>
Tue, 17 May 2016 21:18:45 +0200
changeset 647e4cfa409ceef
parent 646 926cb97b8256
child 648 1f83d8ad4f55
test
asn.1/pEp.asn1
src/map_asn1.c
test/map_asn1_test.cc
     1.1 --- a/asn.1/pEp.asn1	Tue May 17 20:59:37 2016 +0200
     1.2 +++ b/asn.1/pEp.asn1	Tue May 17 21:18:45 2016 +0200
     1.3 @@ -11,7 +11,7 @@
     1.4  
     1.5  ISO936-1 ::= PrintableString(FROM ("a".."z")) (SIZE(2))
     1.6  Hex ::= PrintableString(FROM ("A".."F") | FROM ("0".."9"))
     1.7 -Hash ::= Hex(SIZE(50..128)) -- SHA1 to SHA512 in hex
     1.8 +Hash ::= Hex(SIZE(1..128)) -- SHA1 to SHA512 in hex
     1.9  
    1.10  Identity ::= SEQUENCE {
    1.11      address     UTF8String  (SIZE(1..1024)) OPTIONAL,
     2.1 --- a/src/map_asn1.c	Tue May 17 20:59:37 2016 +0200
     2.2 +++ b/src/map_asn1.c	Tue May 17 21:18:45 2016 +0200
     2.3 @@ -126,15 +126,14 @@
     2.4          return NULL;
     2.5  
     2.6      for (const stringlist_t *l = list; l && l->value; l=l->next) {
     2.7 -        Hash_t key;
     2.8 -        memset(&key, 0, sizeof(Hash_t));
     2.9 -        if (OCTET_STRING_fromBuf(&key, l->value, -1))
    2.10 +        Hash_t *key = OCTET_STRING_new_fromBuf(&asn_DEF_Hash, l->value, -1);
    2.11 +        if (!key)
    2.12              goto enomem;
    2.13  
    2.14 -        int r = ASN_SEQUENCE_ADD(&result->list, &key);
    2.15 -        ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_Hash, &key);
    2.16 -        if (r)
    2.17 +        if (ASN_SEQUENCE_ADD(&result->list, key)) {
    2.18 +            ASN_STRUCT_FREE(asn_DEF_Hash, key);
    2.19              goto enomem;
    2.20 +        }
    2.21      }
    2.22  
    2.23      return result;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/map_asn1_test.cc	Tue May 17 21:18:45 2016 +0200
     3.3 @@ -0,0 +1,75 @@
     3.4 +#include <iostream>
     3.5 +#include <string>
     3.6 +#include <cstring>
     3.7 +#include <assert.h>
     3.8 +#include "map_asn1.h"
     3.9 +
    3.10 +using namespace std;
    3.11 +
    3.12 +int main() {
    3.13 +    cout << "\n*** map_asn1_test ***\n\n";
    3.14 +
    3.15 +    cout << "creating new identity...\n";
    3.16 +
    3.17 +    pEp_identity *ident1 = new_identity("vb@dingens.org",
    3.18 +            "DB4713183660A12ABAFA7714EBE90D44146F62F4", "42", "Volker Birk");
    3.19 +    assert(ident1);
    3.20 +    ident1->lang[0] = 'd';
    3.21 +    ident1->lang[1] = 'e';
    3.22 +    ident1->comm_type = PEP_ct_pEp;
    3.23 +
    3.24 +    cout << "converting identity to ASN.1...\n";
    3.25 +
    3.26 +    Identity_t *ident_asn1 = Identity_from_Struct(ident1);
    3.27 +    assert(ident_asn1);
    3.28 +
    3.29 +    cout << "converting identity from ASN.1...\n";
    3.30 +
    3.31 +    pEp_identity *ident2 = Identity_to_Struct(ident_asn1);
    3.32 +    assert(ident2);
    3.33 +
    3.34 +    assert(strcmp(ident1->address, ident2->address) == 0);
    3.35 +    assert(strcmp(ident1->fpr, ident2->fpr) == 0);
    3.36 +    assert(strcmp(ident1->user_id, ident2->user_id) == 0);
    3.37 +    assert(strcmp(ident1->username, ident2->username) == 0);
    3.38 +    assert(ident2->comm_type == PEP_ct_pEp);
    3.39 +    assert(strcmp(ident2->lang, "de") == 0);
    3.40 +
    3.41 +    cout << "freeing identities...\n";
    3.42 +
    3.43 +    asn_DEF_Identity.free_struct(&asn_DEF_Identity, ident_asn1, 0);
    3.44 +    free_identity(ident1);
    3.45 +    free_identity(ident2);
    3.46 +
    3.47 +    cout << "creating new stringlist...\n";
    3.48 +
    3.49 +    stringlist_t *sl = new_stringlist("23");
    3.50 +    assert(sl);
    3.51 +    stringlist_t *_sl = stringlist_add(sl, "42");
    3.52 +    assert(_sl);
    3.53 +
    3.54 +    cout << "converting stringlist to keylist...\n";
    3.55 +
    3.56 +    KeyList_t *kl = KeyList_from_stringlist(sl);
    3.57 +    assert(kl);
    3.58 +
    3.59 +    cout << "converting keylist to stringlist...\n";
    3.60 +
    3.61 +    stringlist_t *sl2 = KeyList_to_stringlist(kl);
    3.62 +    assert(sl2);
    3.63 +
    3.64 +    stringlist_t *_sl2;
    3.65 +    for (_sl = sl, _sl2 = sl2; _sl && _sl->value; _sl = _sl->next, _sl2 = _sl2->next) {
    3.66 +        assert(_sl2);
    3.67 +        assert(_sl2->value);
    3.68 +        assert(strcmp(_sl->value, _sl2->value) == 0);
    3.69 +        assert(!_sl->next == !_sl2->next);
    3.70 +    }
    3.71 +
    3.72 +    cout << "freeing keylist...\n";
    3.73 +
    3.74 +    free_stringlist(sl);
    3.75 +
    3.76 +    return 0;
    3.77 +}
    3.78 +