From c918d3ed076a799e8e5bced6f48dce8f1de5d5e2 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 28 Dec 2020 14:26:44 +0200 Subject: [PATCH] Add base64 utils. --- etebase_fastapi/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/etebase_fastapi/utils.py b/etebase_fastapi/utils.py index 3473fa0..5e45db7 100644 --- a/etebase_fastapi/utils.py +++ b/etebase_fastapi/utils.py @@ -1,6 +1,7 @@ import dataclasses import typing as t import msgpack +import base64 from fastapi import status, Query, Depends from pydantic import BaseModel as PyBaseModel @@ -53,6 +54,15 @@ def msgpack_decode(content): return msgpack.unpackb(content, raw=False) +def b64encode(value): + return base64.urlsafe_b64encode(value).decode("ascii").strip("=") + + +def b64decode(data): + data += "=" * ((4 - len(data) % 4) % 4) + return base64.urlsafe_b64decode(data) + + PERMISSIONS_READ = [Depends(x) for x in app_settings.API_PERMISSIONS_READ] PERMISSIONS_READWRITE = PERMISSIONS_READ + [Depends(x) for x in app_settings.API_PERMISSIONS_WRITE]