2024-04-17 11:25:26 -06:00
|
|
|
from sanic import response, Blueprint
|
2021-11-01 16:42:52 -06:00
|
|
|
from sanic.request import Request
|
2022-01-13 09:29:58 -07:00
|
|
|
from sanic_ext import validate
|
|
|
|
|
from sanic_ext.extensions.openapi import openapi
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-02-03 12:39:14 -07:00
|
|
|
from . import lib, schema
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
otp_bp = Blueprint('OTP', '/api/otp')
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
@otp_bp.post('/encrypt_otp')
|
2022-02-03 11:36:26 -07:00
|
|
|
@openapi.definition(
|
|
|
|
|
summary='Encrypt a message with OTP.',
|
2022-02-03 12:39:14 -07:00
|
|
|
body=schema.EncryptOTPRequest,
|
2022-02-03 11:36:26 -07:00
|
|
|
)
|
2022-02-03 12:39:14 -07:00
|
|
|
@validate(schema.EncryptOTPRequest)
|
2022-02-16 21:57:27 -07:00
|
|
|
async def post_encrypt_otp(_: Request, body: schema.EncryptOTPRequest):
|
|
|
|
|
data = lib.encrypt_otp(body.otp, body.plaintext)
|
2021-11-01 16:42:52 -06:00
|
|
|
return response.json(data)
|
|
|
|
|
|
|
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
@otp_bp.post('/decrypt_otp')
|
2022-02-03 11:36:26 -07:00
|
|
|
@openapi.definition(
|
|
|
|
|
summary='Decrypt a message with OTP.',
|
2022-02-03 12:39:14 -07:00
|
|
|
body=schema.DecryptOTPRequest,
|
2022-02-03 11:36:26 -07:00
|
|
|
)
|
2022-02-03 12:39:14 -07:00
|
|
|
@validate(schema.DecryptOTPRequest)
|
2022-02-16 21:57:27 -07:00
|
|
|
async def post_decrypt_otp(_: Request, body: schema.DecryptOTPRequest):
|
|
|
|
|
data = lib.decrypt_otp(body.otp, body.ciphertext)
|
2021-11-01 16:42:52 -06:00
|
|
|
return response.json(data)
|
|
|
|
|
|
|
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
@otp_bp.get('/html')
|
2022-06-26 16:27:56 -06:00
|
|
|
async def get_new_otp_html(_: Request):
|
|
|
|
|
body = lib.generate_html()
|
|
|
|
|
return response.html(body)
|