blob: b21b0c57af6a0af3bd38116e88c1fdc7e2f85e32 [file] [log] [blame]
Lev Walkinaf4dfaa2017-07-25 06:39:43 -07001/*
2 * Verify OER with constrained and unconstrained strings.
3 */
4#undef NDEBUG
5#include <stdio.h>
6#include <stdlib.h>
7#include <sys/types.h>
8#include <string.h>
9#include <assert.h>
10#include <ctype.h>
11#include <errno.h>
12
13#include <T.h>
14
15int main() {
16 uint8_t tmpbuf[128];
Lev Walkin7eac0df2017-07-25 09:32:01 -070017 T_t source;
18 T_t *decoded = 0; /* "= 0" is important */
Lev Walkinaf4dfaa2017-07-25 06:39:43 -070019
20 memset(&source, 0, sizeof(source));
21
Lev Walkin69353a32017-07-25 08:10:46 -070022 OCTET_STRING_fromBuf(&source.unconstrained.unc_ia5, "foo", 3);
23 OCTET_STRING_fromBuf(&source.unconstrained.unc_utf8, "bar-whatever", 12);
24 OCTET_STRING_fromBuf(&source.unconstrained.unc_universal,
Lev Walkinaf4dfaa2017-07-25 06:39:43 -070025 "\0\0\0b\0\0\0a\0\0\0z", 12);
26
Lev Walkin69353a32017-07-25 08:10:46 -070027 OCTET_STRING_fromBuf(&source.constrained.con_ia5, "ab", 2);
28 OCTET_STRING_fromBuf(&source.constrained.con_utf8, "cd-whatever", 11);
29 OCTET_STRING_fromBuf(&source.constrained.con_universal, "\0\0\0e\0\0\0f",
30 8);
Lev Walkinaf4dfaa2017-07-25 06:39:43 -070031
32 asn_enc_rval_t er =
33 oer_encode_to_buffer(&asn_DEF_T, 0, &source, tmpbuf, sizeof(tmpbuf));
34 assert(er.encoded != -1);
35
36 asn_dec_rval_t dr =
37 oer_decode(0, &asn_DEF_T, (void **)&decoded, tmpbuf, er.encoded);
38
39 assert(dr.code == RC_OK);
40 if(dr.consumed != er.encoded) {
41 ASN_DEBUG("Consumed %zu, expected %zu", dr.consumed, er.encoded);
42 assert(dr.consumed == er.encoded);
43 }
44
Lev Walkin7eac0df2017-07-25 09:32:01 -070045 if(XEQ_SUCCESS != xer_equivalent(&asn_DEF_T, &source, decoded, stderr)) {
46 return 1;
47 }
Lev Walkinaf4dfaa2017-07-25 06:39:43 -070048
49 return 0;
50}
51