Revision d0c8c01d lib/serializer.py
b/lib/serializer.py | ||
---|---|---|
38 | 38 |
|
39 | 39 |
_JSON_INDENT = 2 |
40 | 40 |
|
41 |
_RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)
|
|
41 |
_RE_EOLSP = re.compile("[ \t]+$", re.MULTILINE)
|
|
42 | 42 |
|
43 | 43 |
|
44 | 44 |
def _GetJsonDumpers(_encoder_class=simplejson.JSONEncoder): |
... | ... | |
79 | 79 |
fn = _DumpJson |
80 | 80 |
|
81 | 81 |
txt = _RE_EOLSP.sub("", fn(data)) |
82 |
if not txt.endswith('\n'):
|
|
83 |
txt += '\n'
|
|
82 |
if not txt.endswith("\n"):
|
|
83 |
txt += "\n"
|
|
84 | 84 |
|
85 | 85 |
return txt |
86 | 86 |
|
... | ... | |
108 | 108 |
""" |
109 | 109 |
txt = DumpJson(data, indent=False) |
110 | 110 |
if salt is None: |
111 |
salt = ''
|
|
111 |
salt = ""
|
|
112 | 112 |
signed_dict = { |
113 |
'msg': txt,
|
|
114 |
'salt': salt,
|
|
113 |
"msg": txt,
|
|
114 |
"salt": salt,
|
|
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
if key_selector: |
... | ... | |
138 | 138 |
""" |
139 | 139 |
signed_dict = LoadJson(txt) |
140 | 140 |
if not isinstance(signed_dict, dict): |
141 |
raise errors.SignatureError('Invalid external message')
|
|
141 |
raise errors.SignatureError("Invalid external message")
|
|
142 | 142 |
try: |
143 |
msg = signed_dict['msg']
|
|
144 |
salt = signed_dict['salt']
|
|
145 |
hmac_sign = signed_dict['hmac']
|
|
143 |
msg = signed_dict["msg"]
|
|
144 |
salt = signed_dict["salt"]
|
|
145 |
hmac_sign = signed_dict["hmac"]
|
|
146 | 146 |
except KeyError: |
147 |
raise errors.SignatureError('Invalid external message')
|
|
147 |
raise errors.SignatureError("Invalid external message")
|
|
148 | 148 |
|
149 | 149 |
if callable(key): |
150 | 150 |
# pylint: disable-msg=E1103 |
... | ... | |
159 | 159 |
|
160 | 160 |
if not utils.VerifySha1Hmac(hmac_key, msg, hmac_sign, |
161 | 161 |
salt=salt + key_selector): |
162 |
raise errors.SignatureError('Invalid Signature')
|
|
162 |
raise errors.SignatureError("Invalid Signature")
|
|
163 | 163 |
|
164 | 164 |
return LoadJson(msg), salt |
165 | 165 |
|
Also available in: Unified diff