Lev Walkin | af4dfaa | 2017-07-25 06:39:43 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | int main() { |
| 16 | uint8_t tmpbuf[128]; |
Lev Walkin | 7eac0df | 2017-07-25 09:32:01 -0700 | [diff] [blame] | 17 | T_t source; |
| 18 | T_t *decoded = 0; /* "= 0" is important */ |
Lev Walkin | af4dfaa | 2017-07-25 06:39:43 -0700 | [diff] [blame] | 19 | |
| 20 | memset(&source, 0, sizeof(source)); |
| 21 | |
Lev Walkin | 69353a3 | 2017-07-25 08:10:46 -0700 | [diff] [blame] | 22 | 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 Walkin | af4dfaa | 2017-07-25 06:39:43 -0700 | [diff] [blame] | 25 | "\0\0\0b\0\0\0a\0\0\0z", 12); |
| 26 | |
Lev Walkin | 69353a3 | 2017-07-25 08:10:46 -0700 | [diff] [blame] | 27 | 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 Walkin | af4dfaa | 2017-07-25 06:39:43 -0700 | [diff] [blame] | 31 | |
| 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 Walkin | 7eac0df | 2017-07-25 09:32:01 -0700 | [diff] [blame] | 45 | if(XEQ_SUCCESS != xer_equivalent(&asn_DEF_T, &source, decoded, stderr)) { |
| 46 | return 1; |
| 47 | } |
Lev Walkin | af4dfaa | 2017-07-25 06:39:43 -0700 | [diff] [blame] | 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |