Commit e7b73c40 authored by Lev Walkin's avatar Lev Walkin

oer support code

parent cc159474
......@@ -33,6 +33,7 @@ libasn1cskeletons_la_SOURCES = \
GraphicString.c GraphicString.h \
IA5String.c IA5String.h \
INTEGER.c INTEGER.h \
INTEGER_oer.c INTEGER_oer.h \
ISO646String.c ISO646String.h \
NULL.c NULL.h \
NativeEnumerated.c NativeEnumerated.h \
......@@ -68,6 +69,9 @@ libasn1cskeletons_la_SOURCES = \
constr_TYPE.c constr_TYPE.h \
constraints.c constraints.h \
der_encoder.c der_encoder.h \
oer_decoder.c oer_decoder.h \
oer_encoder.c oer_encoder.h \
oer_support.c oer_support.h \
per_decoder.c per_decoder.h \
per_encoder.c per_encoder.h \
per_opentype.c per_opentype.h \
......
/*
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
/*
* The OER decoder of any type.
*/
asn_dec_rval_t
oer_decode(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *type_descriptor,
void **struct_ptr, const void *ptr, size_t size) {
asn_codec_ctx_t s_codec_ctx;
/*
* Stack checker requires that the codec context
* must be allocated on the stack.
*/
if(opt_codec_ctx) {
if(opt_codec_ctx->max_stack_size) {
s_codec_ctx = *opt_codec_ctx;
opt_codec_ctx = &s_codec_ctx;
}
} else {
/* If context is not given, be security-conscious anyway */
memset(&s_codec_ctx, 0, sizeof(s_codec_ctx));
s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX;
opt_codec_ctx = &s_codec_ctx;
}
/*
* Invoke type-specific decoder.
*/
return type_descriptor->oer_decoder(opt_codec_ctx, type_descriptor, 0,
struct_ptr, /* Pointer to the destination structure */
ptr, size /* Buffer and its size */
);
}
......@@ -6,6 +6,7 @@
#define _OER_DECODER_H_
#include <asn_application.h>
#include <oer_support.h>
#ifdef __cplusplus
extern "C" {
......@@ -28,11 +29,13 @@ asn_dec_rval_t oer_decode(struct asn_codec_ctx_s *opt_codec_ctx,
/*
* Type of generic function which decodes the byte stream into the structure.
*/
typedef asn_dec_rval_t (oer_type_decoder_f)(
struct asn_codec_ctx_s *opt_codec_ctx,
struct asn_TYPE_descriptor_s *type_descriptor,
void **struct_ptr, const void *buf_ptr, size_t size,
int tag_mode);
typedef asn_dec_rval_t(oer_type_decoder_f)(
struct asn_codec_ctx_s *opt_codec_ctx,
struct asn_TYPE_descriptor_s *type_descriptor,
asn_oer_constraint_t *constraints,
void **struct_ptr,
const void *buf_ptr,
size_t size);
#ifdef __cplusplus
}
......
/*
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are oermitted subject to BSD license.
*/
#ifndef _OER_SUPPORT_H_
#define _OER_SUPPORT_H_
#include <asn_system.h> /* Platform-specific types */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Pre-computed OER constraints.
*/
typedef const struct asn_oer_constraint_s {
enum asn_oer_constraint_flags {
AOC_HAS_LOWER_BOUND = 0x01,
AOC_HAS_UPPER_BOUND = 0x02
} flags;
intmax_t lower_bound;
intmax_t upoer_bound;
} asn_oer_constraint_t;
typedef const struct asn_oer_constraints_s {
struct asn_oer_constraint_s value;
struct asn_oer_constraint_s size;
} asn_oer_constraints_t;
#ifdef __cplusplus
}
#endif
#endif /* _OER_SUPPORT_H_ */
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