def save_token(provider, user_id, token_data): publickey = yield get_user_publickey(user_id) token_data_enc = cryptohelper.encrypt_blob(publickey, token_data) conn = yield connection() data = {"id": user_id, provider: token_data_enc} result = yield r.table("auth").insert(data, conflict="update").run(conn) return result
def save_token(provider, user_id, token_data): publickey = yield get_user_publickey(user_id) token_data_enc = cryptohelper.encrypt_blob(publickey, token_data) conn = yield connection() data = { "id": user_id, provider: token_data_enc, } result = yield r.table('auth').insert(data, conflict='update').run(conn) return result
def create_user_keys(userid, showid): conn = yield connection() public_key, private_key = cryptohelper.create_keypair() show_publickey = yield get_show_publickey(showid) enc_priv_key = cryptohelper.encrypt_blob(show_publickey, private_key) data = { 'public_key': public_key, 'enc_private_key': enc_priv_key, 'showid': showid, 'id': userid } result = yield r.table('encryption_user').insert(data).run(conn) return result
def encrypt_blob(self, data): return cryptohelper.encrypt_blob(self.publickey, data)