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
b2ce577f
Commit
b2ce577f
authored
Aug 18, 2004
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proper computations
parent
40c3b442
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
17 deletions
+14
-17
skeletons/ber_tlv_tag.c
skeletons/ber_tlv_tag.c
+14
-17
No files found.
skeletons/ber_tlv_tag.c
View file @
b2ce577f
...
...
@@ -104,7 +104,7 @@ der_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufp, size_t size) {
ber_tlv_tag_t
tval
=
BER_TAG_VALUE
(
tag
);
uint8_t
*
buf
=
(
uint8_t
*
)
bufp
;
uint8_t
*
end
;
size_t
comput
ed_size
;
size_t
requir
ed_size
;
int
i
;
if
(
tval
<=
30
)
{
...
...
@@ -118,29 +118,26 @@ der_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufp, size_t size) {
/*
* Compute the size of the subsequent bytes.
* The routine is written so every floating-point
* operation is done at compile time.
* Note, there is a subtle problem lurking here,
* could you guess where it is? :)
* Hint: what happens when ((8*sizeof(tag))%7) == 0?
*/
computed_size
=
1
+
8
*
sizeof
(
tag
)
/
7
;
for
(
i
=
(
8
*
sizeof
(
tag
))
-
((
8
*
sizeof
(
tag
))
%
7
);
i
>=
7
;
i
-=
7
)
{
if
((
tval
>>
i
)
&
0x7F
)
break
;
computed_size
--
;
for
(
required_size
=
1
,
i
=
7
;
i
<
8
*
sizeof
(
tag
);
i
+=
7
)
{
if
(
tag
>>
i
)
required_size
++
;
else
break
;
}
if
(
size
<
required_size
)
return
required_size
+
1
;
/*
* Fill in the buffer, space permitting.
*/
if
(
size
>
computed_size
)
end
=
buf
+
computed_size
;
else
end
=
buf
+
size
;
for
((
void
)
i
;
buf
<
end
;
i
-=
7
,
buf
++
)
{
*
buf
=
0x80
|
((
tval
>>
i
)
&
0x7F
);
end
=
buf
+
required_size
-
1
;
for
(
i
-=
7
;
buf
<=
end
;
i
-=
7
,
buf
++
)
{
*
buf
=
0x80
|
((
tval
>>
i
)
&
0x7F
);
}
*
end
&=
0x7F
;
/* Clear the last high bit */
return
comput
ed_size
+
1
;
return
requir
ed_size
+
1
;
}
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