예제 #1
0
파일: feed.py 프로젝트: cn-uofbasel/BACnet
 def load_keyfile(fn):
     with open(fn, 'r') as f:
         key = eval(f.read())
     if key['type'] == 'ed25519':
         fid = bytes.fromhex(key['public'])
         signer = crypto.ED25519(bytes.fromhex(key['private']))
     elif key['type'] == 'hmac_sha256':
         fid = bytes.fromhex(key['feed_id'])
         signer = crypto.HMAC256(bytes.fromhex(key['private']))
     return fid, signer
예제 #2
0
 def load_keyfile(fn):
     with open(fn, 'r') as f:
         key = eval(f.read())
     if key['type'] == 'ed25519':
         fid = bytes.fromhex(key['public'])
         signer = crypto.ED25519(bytes.fromhex(key['private']))
         digestmod = 'sha256'
     elif key['type'] in ['hmac_sha256', 'hmac_sha1', 'hmac_md5']:
         fid = bytes.fromhex(key['feed_id'])
         digestmod = key['type'][5:]
         signer = crypto.HMAC(digestmod, bytes.fromhex(key['private']))
     return fid, signer, digestmod
예제 #3
0
파일: user.py 프로젝트: Kyrus1999/BACnet
 def get_signer(self) -> crypto.ED25519:
     """
     This function identifies the signer of the user
     Parameters
     ----------
     self : USER
         The alias name of the user
     Returns
     -------
     crypto.ED25519
         Signer of the user
     """
     return crypto.ED25519(bytes.fromhex(self.sk))
예제 #4
0
파일: user.py 프로젝트: Kyrus1999/BACnet
 def new() -> USER:
     """
     This function creates a new user.
     Returns
     -------
     USER
         new created user
     """
     key_pair = crypto.ED25519()
     key_pair.create()
     u = USER(fid=key_pair.get_public_key().hex(),
              sk=key_pair.get_private_key().hex(),
              follows=[],
              channels=[])
     if u.save():
         return u
     return None