Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: third_party/google-endpoints/pyasn1/codec/cer/decoder.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # CER decoder
2 from pyasn1.type import univ
3 from pyasn1.codec.ber import decoder
4 from pyasn1.compat.octets import oct2int
5 from pyasn1 import error
6
7 class BooleanDecoder(decoder.AbstractSimpleDecoder):
8 protoComponent = univ.Boolean(0)
9 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
10 state, decodeFun, substrateFun):
11 head, tail = substrate[:length], substrate[length:]
12 if not head or length != 1:
13 raise error.PyAsn1Error('Not single-octet Boolean payload')
14 byte = oct2int(head[0])
15 # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while
16 # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1
17 # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
18 if byte == 0xff:
19 value = 1
20 elif byte == 0x00:
21 value = 0
22 else:
23 raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte)
24 return self._createComponent(asn1Spec, tagSet, value), tail
25
26 tagMap = decoder.tagMap.copy()
27 tagMap.update({
28 univ.Boolean.tagSet: BooleanDecoder()
29 })
30
31 typeMap = decoder.typeMap
32
33 class Decoder(decoder.Decoder): pass
34
35 decode = Decoder(tagMap, decoder.typeMap)
OLDNEW
« no previous file with comments | « third_party/google-endpoints/pyasn1/codec/cer/__init__.py ('k') | third_party/google-endpoints/pyasn1/codec/cer/encoder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698