Commit 20ea8521 authored by Lev Walkin's avatar Lev Walkin

add OER open type decoder

parent 39837e6c
......@@ -37,3 +37,58 @@ oer_decode(asn_codec_ctx_t *opt_codec_ctx,
ptr, size /* Buffer and its size */
);
}
/*
* Open Type is encoded as a length (#8.6) followed by that number of bytes.
* Since we're just skipping, reading the length would be enough.
*/
ssize_t
oer_open_type_skip(const void *bufptr, size_t size) {
size_t len = 0;
return oer_fetch_length(bufptr, size, &len);
}
/*
* Read the Open Type (X.696 (08/2015), #30).
* RETURN VALUES:
* 0: More data expected than bufptr contains.
* -1: Fatal error deciphering length.
* >0: Number of bytes used from bufptr.
*/
ssize_t
oer_open_type_get(asn_codec_ctx_t *opt_codec_ctx,
struct asn_TYPE_descriptor_s *td,
asn_oer_constraints_t *constraints, void **struct_ptr,
const void *bufptr, size_t size) {
asn_dec_rval_t dr;
size_t container_len = 0;
ssize_t len_len;
/* Get the size of a length determinant */
len_len = oer_fetch_length(bufptr, size, &container_len);
if(len_len <= 0) {
return len_len; /* Error or more data expected */
}
/*
* len_len can't be bigger than size, but size without len_len
* should be bigger or equal to container length
*/
if(size - len_len < container_len) {
/* More data is expected */
return 0;
}
dr = td->oer_decoder(opt_codec_ctx, td, constraints, struct_ptr,
(const uint8_t *)bufptr + len_len, container_len);
if(dr.code == RC_OK) {
return len_len + container_len;
} else {
/* Even if RC_WMORE, we can't get more data into a closed container. */
ASN_STRUCT_FREE(*td, *struct_ptr);
*struct_ptr = 0;
return -1;
}
}
......@@ -44,7 +44,7 @@ typedef asn_dec_rval_t(oer_type_decoder_f)(
* -1: Fatal error deciphering length.
* >0: Number of bytes used from bufptr.
*/
ssize_t oer_open_type_slurp(const void *bufptr, size_t size);
ssize_t oer_open_type_skip(const void *bufptr, size_t size);
/*
* Read the Open Type (X.696 (08/2015), #30).
......
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