Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
51f9e6ea
Commit
51f9e6ea
authored
Apr 23, 2015
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more zero-length BER encodings, plus unit tests.
parent
6117cf14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
14 deletions
+36
-14
coro/asn1/ber.pyx
coro/asn1/ber.pyx
+17
-14
coro/asn1/test/t0.py
coro/asn1/test/t0.py
+19
-0
No files found.
coro/asn1/ber.pyx
View file @
51f9e6ea
...
@@ -561,25 +561,28 @@ cdef object decode_structured (unsigned char * s, long * pos, long length):
...
@@ -561,25 +561,28 @@ cdef object decode_structured (unsigned char * s, long * pos, long length):
cdef
object
decode_objid
(
unsigned
char
*
s
,
long
*
pos
,
long
length
):
cdef
object
decode_objid
(
unsigned
char
*
s
,
long
*
pos
,
long
length
):
cdef
long
i
,
m
,
n
,
hi
,
lo
cdef
long
i
,
m
,
n
,
hi
,
lo
cdef
list
r
cdef
list
r
m
=
s
[
pos
[
0
]]
if
length
==
0
:
# first * 40 + second
raise
InsufficientData
(
pos
[
0
])
r
=
[
m
//
40
,
m
%
40
]
else
:
n
=
0
pos
[
0
]
=
pos
[
0
]
+
1
for
i
from
1
<=
i
<
length
:
m
=
s
[
pos
[
0
]]
m
=
s
[
pos
[
0
]]
hi
=
m
&
0x80
# first * 40 + second
lo
=
m
&
0x7f
r
=
[
m
//
40
,
m
%
40
]
n
=
(
n
<<
7
)
|
lo
n
=
0
if
not
hi
:
r
.
append
(
n
)
n
=
0
pos
[
0
]
=
pos
[
0
]
+
1
pos
[
0
]
=
pos
[
0
]
+
1
return
r
for
i
from
1
<=
i
<
length
:
m
=
s
[
pos
[
0
]]
hi
=
m
&
0x80
lo
=
m
&
0x7f
n
=
(
n
<<
7
)
|
lo
if
not
hi
:
r
.
append
(
n
)
n
=
0
pos
[
0
]
=
pos
[
0
]
+
1
return
r
cdef
object
decode_boolean
(
unsigned
char
*
s
,
long
*
pos
,
long
length
):
cdef
object
decode_boolean
(
unsigned
char
*
s
,
long
*
pos
,
long
length
):
if
length
==
0
:
if
length
==
0
:
return
False
:
return
False
else
:
else
:
pos
[
0
]
+=
1
pos
[
0
]
+=
1
if
s
[
pos
[
0
]
-
1
]
==
0xff
:
if
s
[
pos
[
0
]
-
1
]
==
0xff
:
...
...
coro/asn1/test/t0.py
View file @
51f9e6ea
...
@@ -137,6 +137,24 @@ class bignum_test_3 (ber_test_case):
...
@@ -137,6 +137,24 @@ class bignum_test_3 (ber_test_case):
print
n
print
n
self
.
assertEquals
(
decode
(
INTEGER
(
n
))[
0
],
n
)
self
.
assertEquals
(
decode
(
INTEGER
(
n
))[
0
],
n
)
class
zero_length_tests
(
ber_test_case
):
# tests for Issue #71.
def
runTest
(
self
):
self
.
assertEquals
(
# zero-length boolean
decode
(
SEQUENCE
(
'
\
x01
\
x00
'
,
INTEGER
(
3141
))),
([
False
,
3141
],
8
)
)
self
.
assertEquals
(
# zero-length bitstring
decode
(
SEQUENCE
(
'
\
x03
\
x00
'
,
INTEGER
(
3141
))),
([(
'bitstring'
,
(
0
,
''
)),
3141
],
8
)
)
# zero-length OBJID
with
self
.
assertRaises
(
InsufficientData
):
decode
(
'
\
x06
\
x00
'
)
def
suite
():
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
simple_test
())
suite
.
addTest
(
simple_test
())
...
@@ -144,6 +162,7 @@ def suite():
...
@@ -144,6 +162,7 @@ def suite():
suite
.
addTest
(
bignum_test
())
suite
.
addTest
(
bignum_test
())
suite
.
addTest
(
bignum_test_2
())
suite
.
addTest
(
bignum_test_2
())
suite
.
addTest
(
bignum_test_3
())
suite
.
addTest
(
bignum_test_3
())
suite
.
addTest
(
zero_length_tests
())
return
suite
return
suite
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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