本文整理汇总了Python中sleekxmpp.util.bytes函数的典型用法代码示例。如果您正苦于以下问题:Python bytes函数的具体用法?Python bytes怎么用?Python bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: set_value
def set_value(self, values):
if not self['mechanism'] in self.plain_mechs:
if values:
self.xml.text = bytes(base64.b64encode(values)).decode('utf-8')
else:
self.xml.text = '='
else:
self.xml.text = bytes(values).decode('utf-8')
开发者ID:AmiZya,项目名称:emesene,代码行数:8,代码来源:auth.py
示例2: response
def response(self, prefix=b""):
nc = bytes("%08x" % self.nonce_count)
a1 = bytes(self.hash(self.A1()).hexdigest().lower())
a2 = bytes(self.hash(self.A2(prefix)).hexdigest().lower())
s = self.nonce + b":" + nc + b":" + self.cnonce + b":" + self.qop + b":" + a2
return bytes(self.hash(a1 + b":" + s).hexdigest().lower())
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:8,代码来源:mechanisms.py
示例3: response
def response(self, prefix=b''):
nc = bytes('%08x' % self.nonce_count)
a1 = bytes(self.hash(self.A1()).hexdigest().lower())
a2 = bytes(self.hash(self.A2(prefix)).hexdigest().lower())
s = self.nonce + b':' + nc + b':' + self.cnonce + \
b':' + self.qop + b':' + a2
return bytes(self.hash(a1 + b':' + s).hexdigest().lower())
开发者ID:RedbackThomson,项目名称:LoLShadow,代码行数:9,代码来源:mechanisms.py
示例4: saslname
def saslname(self, value):
escaped = b''
for char in bytes(value):
if char == b',':
escaped += b'=2C'
elif char == b'=':
escaped += b'=3D'
else:
if isinstance(char, int):
char = chr(char)
escaped += bytes(char)
return escaped
开发者ID:RedbackThomson,项目名称:LoLShadow,代码行数:12,代码来源:mechanisms.py
示例5: saslname
def saslname(self, value):
escaped = b""
for char in bytes(value):
if char == b",":
escaped += b"=2C"
elif char == b"=":
escaped += b"=3D"
else:
if isinstance(char, int):
char = chr(char)
escaped += bytes(char)
return escaped
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:12,代码来源:mechanisms.py
示例6: process_1
def process_1(self, challenge):
self.step = 1
data = {}
self.cnonce = bytes(('%s' % random.random())[2:])
gs2_cbind_flag = b'n'
if self.credentials['channel_binding']:
if self.use_channel_binding:
gs2_cbind_flag = b'p=tls-unique'
else:
gs2_cbind_flag = b'y'
authzid = b''
if self.credentials['authzid']:
authzid = b'a=' + self.saslname(self.credentials['authzid'])
self.gs2_header = gs2_cbind_flag + b',' + authzid + b','
nonce = b'r=' + self.cnonce
username = b'n=' + self.saslname(self.credentials['username'])
self.client_first_message_bare = username + b',' + nonce
self.client_first_message = self.gs2_header + \
self.client_first_message_bare
return self.client_first_message
开发者ID:RedbackThomson,项目名称:LoLShadow,代码行数:27,代码来源:mechanisms.py
示例7: set_binval
def set_binval(self, value):
self.del_binval()
parent = self.parent()
if value:
xml = ET.Element('{%s}BINVAL' % self.namespace)
xml.text = bytes(base64.b64encode(value)).decode('utf-8')
parent.append(xml)
开发者ID:2M1R,项目名称:SleekXMPP,代码行数:7,代码来源:stanza.py
示例8: process_1
def process_1(self, challenge):
self.step = 1
data = {}
self.cnonce = bytes(("%s" % random.random())[2:])
gs2_cbind_flag = b"n"
if self.credentials["channel_binding"]:
if self.use_channel_binding:
gs2_cbind_flag = b"p=tls-unique"
else:
gs2_cbind_flag = b"y"
authzid = b""
if self.credentials["authzid"]:
authzid = b"a=" + self.saslname(self.credentials["authzid"])
self.gs2_header = gs2_cbind_flag + b"," + authzid + b","
nonce = b"r=" + self.cnonce
username = b"n=" + self.saslname(self.credentials["username"])
self.client_first_message_bare = username + b"," + nonce
self.client_first_message = self.gs2_header + self.client_first_message_bare
return self.client_first_message
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:26,代码来源:mechanisms.py
示例9: choose
def choose(mech_list, credentials, security_settings, limit=None, min_mech=None):
available_mechs = set(MECHANISMS.keys())
if limit is None:
limit = set(mech_list)
if not isinstance(limit, set):
limit = set(limit)
if not isinstance(mech_list, set):
mech_list = set(mech_list)
mech_list = mech_list.intersection(limit)
available_mechs = available_mechs.intersection(mech_list)
best_score = MECH_SEC_SCORES.get(min_mech, -1)
best_mech = None
for name in available_mechs:
if name in MECH_SEC_SCORES:
if MECH_SEC_SCORES[name] > best_score:
best_score = MECH_SEC_SCORES[name]
best_mech = name
if best_mech is None:
raise SASLNoAppropriateMechanism()
mech_class = MECHANISMS[best_mech]
try:
creds = credentials(mech_class.required_credentials,
mech_class.optional_credentials)
for req in mech_class.required_credentials:
if req not in creds:
raise SASLCancelled('Missing credential: %s' % req)
for opt in mech_class.optional_credentials:
if opt not in creds:
creds[opt] = b''
for cred in creds:
if cred in ('username', 'password', 'authzid'):
creds[cred] = bytes(saslprep(creds[cred]))
else:
creds[cred] = bytes(creds[cred])
security_opts = security_settings(mech_class.security)
return mech_class(best_mech, creds, security_opts)
except SASLCancelled as e:
log.info('SASL: %s: %s', best_mech, e.message)
mech_list.remove(best_mech)
return choose(mech_list, credentials, security_settings,
limit=limit,
min_mech=min_mech)
开发者ID:AmiZya,项目名称:emesene,代码行数:47,代码来源:client.py
示例10: Hi
def Hi(self, text, salt, iterations):
text = bytes(text)
ui1 = self.HMAC(text, salt + b"\0\0\0\01")
ui = ui1
for i in range(iterations - 1):
ui1 = self.HMAC(text, ui1)
ui = XOR(ui, ui1)
return ui
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:8,代码来源:mechanisms.py
示例11: respond
def respond(self):
data = {
'username': quote(self.credentials['username']),
'authzid': quote(self.credentials['authzid']),
'realm': quote(self.credentials['realm']),
'nonce': quote(self.nonce),
'cnonce': quote(self.cnonce),
'nc': bytes('%08x' % self.nonce_count),
'qop': self.qop,
'digest-uri': quote(self.digest_uri()),
'response': self.response(b'AUTHENTICATE'),
'maxbuf': self.maxbuf
}
resp = b''
for key, value in data.items():
if value and value != b'""':
resp += b',' + bytes(key) + b'=' + bytes(value)
return resp[1:]
开发者ID:RealDoll,项目名称:emesene,代码行数:18,代码来源:mechanisms.py
示例12: parse
def parse(self, challenge=b''):
data = {}
var_name = b''
var_value = b''
# States: var, new_var, end, quote, escaped_quote
state = 'var'
for char in challenge:
if sys.version_info >= (3, 0):
char = bytes([char])
if state == 'var':
if char.isspace():
continue
if char == b'=':
state = 'value'
else:
var_name += char
elif state == 'value':
if char == b'"':
state = 'quote'
elif char == b',':
if var_name:
data[var_name.decode('utf-8')] = var_value
var_name = b''
var_value = b''
state = 'var'
else:
var_value += char
elif state == 'escaped':
var_value += char
elif state == 'quote':
if char == b'\\':
state = 'escaped'
elif char == b'"':
state = 'end'
else:
var_value += char
else:
if char == b',':
if var_name:
data[var_name.decode('utf-8')] = var_value
var_name = b''
var_value = b''
state = 'var'
else:
var_value += char
if var_name:
data[var_name.decode('utf-8')] = var_value
var_name = b''
var_value = b''
state = 'var'
return data
开发者ID:RedbackThomson,项目名称:LoLShadow,代码行数:56,代码来源:mechanisms.py
示例13: respond
def respond(self):
data = {
"username": quote(self.credentials["username"]),
"authzid": quote(self.credentials["authzid"]),
"realm": quote(self.credentials["realm"]),
"nonce": quote(self.nonce),
"cnonce": quote(self.cnonce),
"nc": bytes("%08x" % self.nonce_count),
"qop": self.qop,
"digest-uri": quote(self.digest_uri()),
"response": self.response(b"AUTHENTICATE"),
"maxbuf": self.maxbuf,
"charset": "utf-8",
}
resp = b""
for key, value in data.items():
if value and value != b'""':
resp += b"," + bytes(key) + b"=" + bytes(value)
return resp[1:]
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:19,代码来源:mechanisms.py
示例14: parse
def parse(self, challenge=b""):
data = {}
var_name = b""
var_value = b""
# States: var, new_var, end, quote, escaped_quote
state = "var"
for char in challenge:
if sys.version_info >= (3, 0):
char = bytes([char])
if state == "var":
if char.isspace():
continue
if char == b"=":
state = "value"
else:
var_name += char
elif state == "value":
if char == b'"':
state = "quote"
elif char == b",":
if var_name:
data[var_name.decode("utf-8")] = var_value
var_name = b""
var_value = b""
state = "var"
else:
var_value += char
elif state == "escaped":
var_value += char
elif state == "quote":
if char == b"\\":
state = "escaped"
elif char == b'"':
state = "end"
else:
var_value += char
else:
if char == b",":
if var_name:
data[var_name.decode("utf-8")] = var_value
var_name = b""
var_value = b""
state = "var"
else:
var_value += char
if var_name:
data[var_name.decode("utf-8")] = var_value
var_name = b""
var_value = b""
state = "var"
return data
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:55,代码来源:mechanisms.py
示例15: process
def process(self, challenge=b""):
if not challenge:
return None
username = self.credentials["username"]
password = self.credentials["password"]
mac = hmac.HMAC(key=password, digestmod=self.hash)
mac.update(challenge)
return username + b" " + bytes(mac.hexdigest())
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:11,代码来源:mechanisms.py
示例16: process
def process(self, challenge=b''):
if not challenge:
return None
username = self.credentials['username']
password = self.credentials['password']
mac = hmac.HMAC(key=password, digestmod=self.hash)
mac.update(challenge)
return username + b' ' + bytes(mac.hexdigest())
开发者ID:RedbackThomson,项目名称:LoLShadow,代码行数:11,代码来源:mechanisms.py
示例17: A1
def A1(self):
username = self.credentials["username"]
password = self.credentials["password"]
authzid = self.credentials["authzid"]
realm = self.credentials["realm"]
a1 = self.hash()
a1.update(username + b":" + realm + b":" + password)
a1 = a1.digest()
a1 += b":" + self.nonce + b":" + self.cnonce
if authzid:
a1 += b":" + authzid
return bytes(a1)
开发者ID:EnerNOC,项目名称:SleekXMPP,代码行数:14,代码来源:mechanisms.py
示例18: set_value
def set_value(self, values):
if values:
self.xml.text = bytes(base64.b64encode(values)).decode('utf-8')
else:
self.xml.text = '='
开发者ID:2M1R,项目名称:SleekXMPP,代码行数:5,代码来源:response.py
示例19: get_value
def get_value(self):
return base64.b64decode(bytes(self.xml.text))
开发者ID:2M1R,项目名称:SleekXMPP,代码行数:2,代码来源:response.py
示例20: get_value
def get_value(self):
if not self['mechanism'] in self.plain_mechs:
return base64.b64decode(bytes(self.xml.text))
else:
return self.xml.text
开发者ID:AmiZya,项目名称:emesene,代码行数:5,代码来源:auth.py
注:本文中的sleekxmpp.util.bytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论