Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asn1c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
qwebaby3
asn1c
Commits
619b6aae
Commit
619b6aae
authored
20 years ago
by
Lev Walkin
Browse files
Options
Downloads
Patches
Plain Diff
better algorithms
parent
2d3f7339
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
skeletons/ber_tlv_length.c
+17
-20
17 additions, 20 deletions
skeletons/ber_tlv_length.c
with
17 additions
and
20 deletions
skeletons/ber_tlv_length.c
+
17
−
20
View file @
619b6aae
...
...
@@ -20,7 +20,7 @@ ber_fetch_length(int _is_constructed, void *bufptr, size_t size,
/*
* Short definite length.
*/
*
len_r
=
(
oct
&
0x7F
);
*
len_r
=
oct
;
/*
& 0x7F
*/
return
1
;
}
else
{
ber_tlv_len_t
len
;
...
...
@@ -38,7 +38,7 @@ ber_fetch_length(int _is_constructed, void *bufptr, size_t size,
oct
&=
0x7F
;
/* Leave only the 7 LS bits */
for
(
len
=
0
,
buf
++
,
skipped
=
1
;
oct
&&
(
++
skipped
<
size
);
buf
++
,
oct
--
)
{
oct
&&
(
++
skipped
<
=
size
);
buf
++
,
oct
--
)
{
len
=
(
len
<<
8
)
|
*
buf
;
if
(
len
<
0
...
...
@@ -118,10 +118,10 @@ ber_skip_length(int _is_constructed, void *ptr, size_t size) {
ssize_t
der_tlv_length_serialize
(
ber_tlv_len_t
len
,
void
*
bufp
,
size_t
size
)
{
size_t
comput
ed_size
;
/* Size of len encoding */
size_t
requir
ed_size
;
/* Size of len encoding */
uint8_t
*
buf
=
(
uint8_t
*
)
bufp
;
uint8_t
*
end
;
in
t
i
;
size_
t
i
;
if
(
len
<=
127
)
{
/* Encoded in 1 octet */
...
...
@@ -132,28 +132,25 @@ der_tlv_length_serialize(ber_tlv_len_t len, void *bufp, size_t size) {
/*
* Compute the size of the subsequent bytes.
*/
computed_size
=
sizeof
(
len
);
/* assert(sizeof(len)<128), n.p. */
for
(
i
=
(
8
*
(
sizeof
(
len
)
-
1
));
i
>
0
;
i
-=
8
)
{
if
((
len
>>
i
)
&
0xFF
)
break
;
computed_size
--
;
for
(
required_size
=
1
,
i
=
8
;
i
<
8
*
sizeof
(
len
);
i
+=
8
)
{
if
(
len
>>
i
)
required_size
++
;
else
break
;
}
if
(
size
)
{
*
buf
++
=
0x80
|
computed_size
;
/* Length of the encoding */
size
--
;
}
if
(
size
<
required_size
)
return
required_size
+
1
;
*
buf
++
=
0x80
|
required_size
;
/* Length of the encoding */
/*
* Produce the len encoding, space permitting.
*/
if
(
size
>
computed_size
)
end
=
buf
+
computed_size
;
else
end
=
buf
+
size
;
for
((
void
)
i
/* Reuse bits count */
;
buf
<
end
;
i
-=
8
,
buf
++
)
{
*
buf
=
(
len
>>
i
)
&
0xFF
;
}
end
=
buf
+
required_size
;
for
(
i
-=
8
;
buf
<
end
;
i
-=
8
,
buf
++
)
*
buf
=
(
len
>>
i
);
return
comput
ed_size
+
1
;
return
requir
ed_size
+
1
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment