(keyfile)
This method creates a key from a keyfile.
This method creates a key from a keyfile.
This method creates a key from a keyfile .
def get_filekey(keyfile):
    """This method creates a key from a keyfile."""

    try:
        handler = open(keyfile, 'rb')
        buf = handler.read()
    except:
        raise OSError('Could not open or read file.')
    else:
        handler.close()
    sha = SHA256.new()
    if len(buf) == 33:
        sha.update(buf)
        return sha.digest()
    elif len(buf) == 65:
        sha.update(struct.unpack('<65s', buf)[0].decode())
        return sha.digest()
    else:
        while buf:
            if len(buf) <= 2049:
                sha.update(buf)
                buf = []
            else:
                sha.update(buf[:2048])
                buf = buf[2048:]
        return sha.digest()
def get_filekey ( keyfile ) : try : handler = open ( keyfile , 'rb' ) buf = handler . read ( ) except : raise OSError ( 'Could not open or read file.' ) else : handler . close ( ) sha = SHA256 . new ( ) if len ( buf ) == 33 : sha . update ( buf ) return sha . digest ( ) elif len ( buf ) == 65 : sha . update ( struct . unpack ( '<65s' , buf ) [ 0 ] . decode ( ) ) return sha . digest ( ) else : while buf : if len ( buf ) <= 2049 : sha . update ( buf ) buf = [ ] else : sha . update ( buf [ : 2048 ] ) buf = buf [ 2048 : ] return sha . digest ( )