Commit af4dfaa1 authored by Lev Walkin's avatar Lev Walkin

OER string test

parent 2d10756d
/*
* Verify OER with constrained and unconstrained strings.
*/
#undef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <T.h>
int main() {
uint8_t tmpbuf[128];
T_t source;
T_t *decoded = 0; /* "= 0" is important */
memset(&source, 0, sizeof(source));
OCTET_STRING_fromBuf(&source.unconstrained.ia5, "foo", 3);
OCTET_STRING_fromBuf(&source.unconstrained.utf8, "bar", 3);
OCTET_STRING_fromBuf(&source.unconstrained.universal,
"\0\0\0b\0\0\0a\0\0\0z", 12);
OCTET_STRING_fromBuf(&source.constrained.ia5, "ab", 2);
OCTET_STRING_fromBuf(&source.constrained.utf8, "cd", 2);
OCTET_STRING_fromBuf(&source.unconstrained.universal, "\0\0\0e\0\0\0f", 8);
asn_enc_rval_t er =
oer_encode_to_buffer(&asn_DEF_T, 0, &source, tmpbuf, sizeof(tmpbuf));
assert(er.encoded != -1);
asn_dec_rval_t dr =
oer_decode(0, &asn_DEF_T, (void **)&decoded, tmpbuf, er.encoded);
assert(dr.code == RC_OK);
if(dr.consumed != er.encoded) {
ASN_DEBUG("Consumed %zu, expected %zu", dr.consumed, er.encoded);
assert(dr.consumed == er.encoded);
}
fprintf(stderr, "Original:\n");
xer_fprint(stderr, &asn_DEF_T, &source);
fprintf(stderr, "Decoded:\n");
xer_fprint(stderr, &asn_DEF_T, decoded);
return 0;
}
-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .137
ModuleOERString
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 137 }
DEFINITIONS IMPLICIT TAGS ::=
BEGIN
T ::= SEQUENCE {
unconstrained SEQUENCE {
ia5 IA5String,
utf8 UTF8String,
universal UniversalString
},
constrained SEQUENCE {
ia5 IA5String (SIZE(2..2)),
utf8 UTF8String (SIZE(2)),
universal UniversalString (SIZE(2 | 2))
}
}
END
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment