Browse Source

none -> null.. remove prints, add test cases..

[git-p4: depot-paths = "//depot/python/pypasn1/main/": change = 1818]
python2
John-Mark Gurney 9 years ago
parent
commit
9a5c72e6c9
1 changed files with 14 additions and 8 deletions
  1. +14
    -8
      pasn1.py

+ 14
- 8
pasn1.py View File

@@ -90,19 +90,20 @@ class ASN1Coder(object):
long: 'int',
set: 'set',
str: 'bytes',
type(None): 'none',
type(None): 'null',
unicode: 'unicode',
}
_tagmap = {
'\x01': 'bool',
'\x02': 'int',
'\x04': 'bytes',
'\x05': 'none',
'\x05': 'null',
'\x09': 'float',
'\x0c': 'unicode',
'\x30': 'list',
'\x31': 'set',
'\xc0': 'dict',
#'xxx': 'datetime',
}

_typetag = dict((v, k) for k, v in _tagmap.iteritems())
@@ -144,11 +145,11 @@ class ASN1Coder(object):
return bool(self.dec_int(d, pos, end)[0]), end

@staticmethod
def enc_none(obj):
def enc_null(obj):
return '\x00'

@staticmethod
def dec_none(d, pos, end):
def dec_null(d, pos, end):
return None, end

def enc_dict(self, obj):
@@ -257,8 +258,6 @@ class ASN1Coder(object):
#elif v & 0b11000000 == 0b01000000:
# raise ValueError('invalid encoding')

print 'df:', `d, pos, end`

raise NotImplementedError

def dumps(self, obj):
@@ -270,7 +269,6 @@ class ASN1Coder(object):
tag = data[pos]
l, b = _decodelen(data, pos + 1)
if len(data) < pos + 1 + b + l:
print `data, pos, end, l, b`
raise ValueError('string not long enough')

# XXX - enforce that len(data) == end?
@@ -320,6 +318,15 @@ class TestCode(unittest.TestCase):
v = loads(s)
self.assertTrue(math.isnan(v))

def test_cryptoutilasn1(self):
'''Test DER sequences generated by Crypto.Util.asn1.'''

for s, v in [ ('\x02\x03$\x8a\xf9', 2394873),
('\x05\x00', None),
('\x02\x03\x00\x96I', 38473),
]:
self.assertEqual(loads(s), v)

def test_dumps(self):
for i in [ None,
True, False,
@@ -333,7 +340,6 @@ class TestCode(unittest.TestCase):
o = loads(s)
self.assertEqual(i, o)

print 'done'
tobj = { 1: 'dflkj', 5: u'sdlkfj', 'float': 1, 'largeint': 1<<342, 'list': [ 1, 2, u'str', 'str' ] }

out = dumps(tobj)


Loading…
Cancel
Save