Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_acctinputoctets(self):
try:return tools.DecodeInteger(self.get(42)[0])
except:return None
def _DecodeValue(self, attr, value):
if attr.values.HasBackward(value):
return attr.values.GetBackward(value)
else:
return tools.DecodeAttr(attr.type, value)
def get_macaddr(self):
try:return tools.DecodeString(self.get(31)[0]).replace("-",":")
except:return None
def CreateReply(self, msg=None,**attributes):
reply = AuthPacket2(AccessAccept, self.id,
self.secret, self.authenticator, dict=self.dict,
**attributes)
if msg:
reply.set_reply_msg(tools.EncodeString(msg))
return reply
def get_chappwd(self):
try:return tools.DecodeOctets(self.get(3)[0])
except:return None
def get_eventtimestamp(self,timetype=0):
try:
_time = tools.DecodeDate(self.get(55)[0])
if timetype == 0:
return datetime.datetime.fromtimestamp(_time).strptime("%Y-%m-%d %H:%M:%S")
else:
return datetime.datetime.fromtimestamp(_time-(8*3600)).strptime("%Y-%m-%d %H:%M:%S")
except:
return None
def get_nasaddr(self):
try:return tools.DecodeAddress(self.get(4)[0])
except:return None
def _EncodeValue(self, attr, value):
result = ''
if attr.values.HasForward(value):
result = attr.values.GetForward(value)
else:
result = tools.EncodeAttr(attr.type, value)
if attr.encrypt == 2:
# salt encrypt attribute
result = self.SaltCrypt(result)
return result
(attr, key, value) = tokens[1:]
try:
adef = self.attributes[attr]
except KeyError:
if defer:
self.defer_parse.append((copy(state), copy(tokens)))
return
raise ParseError('Value defined for unknown attribute ' + attr,
file=state['file'],
line=state['line'])
if adef.type in ['integer', 'signed', 'short', 'byte', 'integer64']:
value = int(value, 0)
value = tools.EncodeAttr(adef.type, value)
self.attributes[attr].values.Add(key, value)