1
我目前正在使用基于表达式(if语句)返回True
或False
的验证函数。头是base64解码,然后json.loads
用于将其转换为字典。这里是方法:函数返回True时返回false。编码问题?
@staticmethod
def verify(rel):
if not('hello' in rel and rel['hello'] is 'blah' and 'alg' in rel and rel['alg'] is 'HS256'):
return False
return True
如果参数是基地64解码并转换为字典,检查只会失败。为什么?任何帮助,将不胜感激。
编辑:根据要求,这里是我怎么称呼该方法。 Python的3.5.2
p = {'hello': 'blah', 'alg': 'HS256'}
f = urlsafe_b64encode(json.dumps(p).encode('utf-8'))
h = json.loads(str(urlsafe_b64decode(f))[2:-1], 'utf-8')
print(verify(h))
我认为我们需要更多的上下文。这个函数的调用是什么样的?数据被传递给它? – sdsmith