Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asn1: Regenerate ASN.1 code using newer version of asn1c #7066

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
511 changes: 487 additions & 24 deletions asn1/asn1c/BIT_STRING.c

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions asn1/asn1c/BIT_STRING.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef _BIT_STRING_H_
Expand All @@ -13,18 +13,31 @@ extern "C" {

typedef struct BIT_STRING_s {
uint8_t *buf; /* BIT STRING body */
int size; /* Size of the above buffer */
size_t size; /* Size of the above buffer */

int bits_unused;/* Unused trailing bits in the last octet (0..7) */

asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
} BIT_STRING_t;

extern asn_TYPE_descriptor_t asn_DEF_BIT_STRING;
extern asn_TYPE_operation_t asn_OP_BIT_STRING;
extern asn_OCTET_STRING_specifics_t asn_SPC_BIT_STRING_specs;

asn_struct_print_f BIT_STRING_print; /* Human-readable output */
asn_struct_compare_f BIT_STRING_compare;
asn_constr_check_f BIT_STRING_constraint;
xer_type_encoder_f BIT_STRING_encode_xer;
oer_type_decoder_f BIT_STRING_decode_oer;
oer_type_encoder_f BIT_STRING_encode_oer;
per_type_decoder_f BIT_STRING_decode_uper;
per_type_encoder_f BIT_STRING_encode_uper;
asn_random_fill_f BIT_STRING_random_fill;

#define BIT_STRING_free OCTET_STRING_free
#define BIT_STRING_decode_ber OCTET_STRING_decode_ber
#define BIT_STRING_encode_der OCTET_STRING_encode_der
#define BIT_STRING_decode_xer OCTET_STRING_decode_xer_binary

#ifdef __cplusplus
}
Expand Down
174 changes: 174 additions & 0 deletions asn1/asn1c/BIT_STRING_oer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef ASN_DISABLE_OER_SUPPORT

#include <asn_internal.h>
#include <BIT_STRING.h>
#include <errno.h>

asn_dec_rval_t
BIT_STRING_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
const asn_TYPE_descriptor_t *td,
const asn_oer_constraints_t *constraints, void **sptr,
const void *ptr, size_t size) {
BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
const asn_oer_constraints_t *cts =
constraints ? constraints : td->encoding_constraints.oer_constraints;
ssize_t ct_size = cts ? cts->size : -1;
asn_dec_rval_t rval = {RC_OK, 0};
size_t expected_length = 0;

(void)opt_codec_ctx;

if(!st) {
st = (BIT_STRING_t *)(*sptr = CALLOC(1, sizeof(*st)));
if(!st) ASN__DECODE_FAILED;
}

if(ct_size >= 0) {
expected_length = (ct_size + 7) >> 3;
st->bits_unused = (8 - (ct_size & 7)) & 7;
} else {
/*
* X.696 (08/2015) #13.3.1
* Encode length determinant as _number of octets_, but only
* if upper bound is not equal to lower bound.
*/
ssize_t len_len = oer_fetch_length(ptr, size, &expected_length);
if(len_len > 0) {
ptr = (const char *)ptr + len_len;
size -= len_len;
} else if(len_len == 0) {
ASN__DECODE_STARVED;
} else if(len_len < 0) {
ASN__DECODE_FAILED;
}

if(expected_length < 1) {
ASN__DECODE_FAILED;
} else if(expected_length > size) {
ASN__DECODE_STARVED;
}

st->bits_unused = ((const uint8_t *)ptr)[0];
if(st->bits_unused & ~7) {
ASN_DEBUG("%s: unused bits outside of 0..7 range", td->name);
ASN__DECODE_FAILED;
}
ptr = (const char *)ptr + 1;
size--;
expected_length--;
rval.consumed = len_len + 1;
}

if(size < expected_length) {
ASN__DECODE_STARVED;
} else {
uint8_t *buf = MALLOC(expected_length + 1);
if(buf == NULL) {
ASN__DECODE_FAILED;
} else {
memcpy(buf, ptr, expected_length);
buf[expected_length] = '\0';
}
FREEMEM(st->buf);
st->buf = buf;
st->size = expected_length;
if(expected_length > 0) {
buf[expected_length - 1] &= (0xff << st->bits_unused);
}

rval.consumed += expected_length;
return rval;
}
}

/*
* Encode as Canonical OER.
*/
asn_enc_rval_t
BIT_STRING_encode_oer(const asn_TYPE_descriptor_t *td,
const asn_oer_constraints_t *constraints,
const void *sptr, asn_app_consume_bytes_f *cb,
void *app_key) {
const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
asn_enc_rval_t erval = {0, 0, 0};
const asn_oer_constraints_t *cts =
constraints ? constraints : td->encoding_constraints.oer_constraints;
ssize_t ct_size = cts ? cts->size : -1;
size_t trailing_zeros = 0;
int fix_last_byte = 0;

if(!st) ASN__ENCODE_FAILED;

if(st->bits_unused & ~7) {
ASN_DEBUG("BIT STRING unused bits %d out of 0..7 range",
st->bits_unused);
ASN__ENCODE_FAILED;
}
if(st->bits_unused && !(st->size && st->buf)) {
ASN_DEBUG("BIT STRING %s size 0 can't support unused bits %d", td->name,
st->bits_unused);
ASN__ENCODE_FAILED;
}

if(ct_size >= 0) {
size_t ct_bytes = (ct_size + 7) >> 3;
if(st->size > ct_bytes) {
ASN_DEBUG("More bits in BIT STRING %s (%" ASN_PRI_SSIZE ") than constrained %" ASN_PRI_SSIZE "",
td->name, 8 * st->size - st->bits_unused, ct_size);
ASN__ENCODE_FAILED;
}
trailing_zeros = ct_bytes - st->size; /* Allow larger constraint */
} else {
uint8_t ub = st->bits_unused & 7;
ssize_t len_len = oer_serialize_length(1 + st->size, cb, app_key);
if(len_len < 0) ASN__ENCODE_FAILED;
if(cb(&ub, 1, app_key) < 0) {
ASN__ENCODE_FAILED;
}
erval.encoded += len_len + 1;
}

if(st->bits_unused) {
if(st->buf[st->size - 1] & (0xff << st->bits_unused)) {
fix_last_byte = 1;
}
}

if(cb(st->buf, st->size - fix_last_byte, app_key) < 0) {
ASN__ENCODE_FAILED;
}

if(fix_last_byte) {
uint8_t b = st->buf[st->size - 1] & (0xff << st->bits_unused);
if(cb(&b, 1, app_key) < 0) {
ASN__ENCODE_FAILED;
}
}

erval.encoded += st->size;

if(trailing_zeros) {
static uint8_t zeros[16];
while(trailing_zeros > 0) {
int ret;
if(trailing_zeros < sizeof(zeros)) {
ret = cb(zeros, trailing_zeros, app_key);
erval.encoded += trailing_zeros;
} else {
ret = cb(zeros, sizeof(zeros), app_key);
erval.encoded += sizeof(zeros);
}
if(ret < 0) ASN__ENCODE_FAILED;
}
}

return erval;
}


#endif /* ASN_DISABLE_OER_SUPPORT */
27 changes: 9 additions & 18 deletions asn1/asn1c/GKCurrentKeys.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
* From ASN.1 module "KeytabModule"
* found in "ipa.asn1"
* `asn1c -fskeletons-copy -fnative-types`
* `asn1c -fskeletons-copy -fnative-types -S /home/abokovoy/src/upstream/asn1c/skeletons`
*/

#include "GKCurrentKeys.h"

static asn_TYPE_member_t asn_MBR_GKCurrentKeys_1[] = {
asn_TYPE_member_t asn_MBR_GKCurrentKeys_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct GKCurrentKeys, serviceIdentity),
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
+1, /* EXPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
{ 0, 0, 0 },
0, 0, /* No default value */
"serviceIdentity"
},
};
Expand All @@ -24,34 +24,25 @@ static const ber_tlv_tag_t asn_DEF_GKCurrentKeys_tags_1[] = {
static const asn_TYPE_tag2member_t asn_MAP_GKCurrentKeys_tag2el_1[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* serviceIdentity */
};
static asn_SEQUENCE_specifics_t asn_SPC_GKCurrentKeys_specs_1 = {
asn_SEQUENCE_specifics_t asn_SPC_GKCurrentKeys_specs_1 = {
sizeof(struct GKCurrentKeys),
offsetof(struct GKCurrentKeys, _asn_ctx),
asn_MAP_GKCurrentKeys_tag2el_1,
1, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
-1, /* First extension addition */
};
asn_TYPE_descriptor_t asn_DEF_GKCurrentKeys = {
"GKCurrentKeys",
"GKCurrentKeys",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
&asn_OP_SEQUENCE,
asn_DEF_GKCurrentKeys_tags_1,
sizeof(asn_DEF_GKCurrentKeys_tags_1)
/sizeof(asn_DEF_GKCurrentKeys_tags_1[0]), /* 1 */
asn_DEF_GKCurrentKeys_tags_1, /* Same as above */
sizeof(asn_DEF_GKCurrentKeys_tags_1)
/sizeof(asn_DEF_GKCurrentKeys_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
{ 0, 0, SEQUENCE_constraint },
asn_MBR_GKCurrentKeys_1,
1, /* Elements count */
&asn_SPC_GKCurrentKeys_specs_1 /* Additional specs */
Expand Down
6 changes: 4 additions & 2 deletions asn1/asn1c/GKCurrentKeys.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
* From ASN.1 module "KeytabModule"
* found in "ipa.asn1"
* `asn1c -fskeletons-copy -fnative-types`
* `asn1c -fskeletons-copy -fnative-types -S /home/abokovoy/src/upstream/asn1c/skeletons`
*/

#ifndef _GKCurrentKeys_H_
Expand All @@ -29,6 +29,8 @@ typedef struct GKCurrentKeys {

/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_GKCurrentKeys;
extern asn_SEQUENCE_specifics_t asn_SPC_GKCurrentKeys_specs_1;
extern asn_TYPE_member_t asn_MBR_GKCurrentKeys_1[1];

#ifdef __cplusplus
}
Expand Down