Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
d563d397
Commit
d563d397
authored
Sep 13, 2004
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added type2any and any2type conversion routines
parent
9b48a05d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
2 deletions
+120
-2
skeletons/ANY.c
skeletons/ANY.c
+113
-2
skeletons/ANY.h
skeletons/ANY.h
+7
-0
No files found.
skeletons/ANY.c
View file @
d563d397
...
@@ -14,9 +14,120 @@ asn1_TYPE_descriptor_t asn1_DEF_ANY = {
...
@@ -14,9 +14,120 @@ asn1_TYPE_descriptor_t asn1_DEF_ANY = {
OCTET_STRING_print
,
OCTET_STRING_print
,
OCTET_STRING_free
,
OCTET_STRING_free
,
0
,
/* Use generic outmost tag fetcher */
0
,
/* Use generic outmost tag fetcher */
0
,
0
,
0
,
0
,
0
,
0
,
/* No tags may be overridden */
-
1
,
/* Both ways are fine (primitive and constructed) */
-
1
,
/* Both ways are fine (primitive and constructed) */
0
,
0
,
/* No members */
0
,
0
,
/* No members */
(
void
*
)
1
/* Special indicator that this is an ANY type */
(
void
*
)
1
/* Special indicator that this is an ANY type */
};
};
struct
_callback_arg
{
uint8_t
*
buffer
;
size_t
offset
;
size_t
size
;
};
static
int
ANY__consume_bytes
(
const
void
*
buffer
,
size_t
size
,
void
*
key
);
int
ANY_fromType
(
ANY_t
*
st
,
asn1_TYPE_descriptor_t
*
td
,
void
*
sptr
)
{
struct
_callback_arg
arg
;
der_enc_rval_t
erval
;
if
(
!
st
||
!
td
)
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
!
sptr
)
{
if
(
st
->
buf
)
FREEMEM
(
st
->
buf
);
st
->
size
=
0
;
return
0
;
}
arg
.
offset
=
arg
.
size
=
0
;
arg
.
buffer
=
0
;
erval
=
der_encode
(
td
,
sptr
,
ANY__consume_bytes
,
&
arg
);
if
(
erval
.
encoded
==
-
1
)
{
if
(
arg
.
buffer
)
FREEMEM
(
arg
.
buffer
);
return
-
1
;
}
assert
(
erval
.
encoded
==
arg
.
offset
);
if
(
st
->
buf
)
FREEMEM
(
st
->
buf
);
st
->
buf
=
arg
.
buffer
;
st
->
size
=
arg
.
offset
;
return
0
;
}
ANY_t
*
ANY_new_fromType
(
asn1_TYPE_descriptor_t
*
td
,
void
*
sptr
)
{
ANY_t
tmp
;
ANY_t
*
st
;
if
(
!
td
||
!
sptr
)
{
errno
=
EINVAL
;
return
0
;
}
memset
(
&
tmp
,
0
,
sizeof
(
tmp
));
if
(
ANY_fromType
(
&
tmp
,
td
,
sptr
))
return
0
;
st
=
(
ANY_t
*
)
MALLOC
(
sizeof
(
*
st
));
if
(
st
)
{
*
st
=
tmp
;
return
st
;
}
else
{
FREEMEM
(
tmp
.
buf
);
return
0
;
}
}
int
ANY_to_type
(
ANY_t
*
st
,
asn1_TYPE_descriptor_t
*
td
,
void
**
struct_ptr
)
{
ber_dec_rval_t
rval
;
void
*
newst
=
0
;
if
(
!
st
||
!
td
||
!
struct_ptr
)
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
st
->
buf
==
0
)
{
/* Nothing to convert, make it empty. */
*
struct_ptr
=
(
void
*
)
0
;
return
0
;
}
rval
=
ber_decode
(
td
,
(
void
**
)
&
newst
,
st
->
buf
,
st
->
size
);
if
(
rval
.
code
==
RC_OK
)
{
*
struct_ptr
=
newst
;
return
0
;
}
else
{
/* Remove possibly partially decoded data. */
td
->
free_struct
(
td
,
newst
,
0
);
return
-
1
;
}
}
static
int
ANY__consume_bytes
(
const
void
*
buffer
,
size_t
size
,
void
*
key
)
{
struct
_callback_arg
*
arg
=
(
struct
_callback_arg
*
)
key
;
if
((
arg
->
offset
+
size
)
>=
arg
->
size
)
{
size_t
nsize
=
(
arg
->
size
?
arg
->
size
<<
2
:
16
)
+
size
;
void
*
p
=
REALLOC
(
arg
->
buffer
,
nsize
);
if
(
!
p
)
return
-
1
;
(
void
*
)
arg
->
buffer
=
p
;
arg
->
size
=
nsize
;
}
memcpy
(
arg
->
buffer
+
arg
->
offset
,
buffer
,
size
);
arg
->
offset
+=
size
;
assert
(
arg
->
offset
<
arg
->
size
);
return
0
;
}
skeletons/ANY.h
View file @
d563d397
...
@@ -26,6 +26,13 @@ asn_struct_free_f ANY_free;
...
@@ -26,6 +26,13 @@ asn_struct_free_f ANY_free;
* Handy conversion routines. *
* Handy conversion routines. *
******************************/
******************************/
/* Convert another ASN.1 type into the ANY. This implies DER encoding. */
int
ANY_fromType
(
ANY_t
*
,
asn1_TYPE_descriptor_t
*
td
,
void
*
struct_ptr
);
ANY_t
*
ANY_new_fromType
(
asn1_TYPE_descriptor_t
*
td
,
void
*
struct_ptr
);
/* Convert the contents of the ANY type into the specified type. */
int
ANY_to_type
(
ANY_t
*
,
asn1_TYPE_descriptor_t
*
td
,
void
**
struct_ptr
);
#define ANY_fromBuf(s, buf, size) OCTET_STRING_fromBuf((s), (buf), (size))
#define ANY_fromBuf(s, buf, size) OCTET_STRING_fromBuf((s), (buf), (size))
#define ANY_new_fromBuf(buf, size) OCTET_STRING_new_fromBuf((buf), (size))
#define ANY_new_fromBuf(buf, size) OCTET_STRING_new_fromBuf((buf), (size))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment