Files
RekomenciBackend/src/template_project/web_api/ioc/cryptographer.py
T
ivankirpichnikov 652da07d12 fast init
2025-10-16 23:03:50 +03:00

26 lines
920 B
Python

import argon2
from cryptography.fernet import Fernet
from dishka import Provider, Scope, WithParents, provide, provide_all
from template_project.adapters.access_token.cryptographer import FernetAccessTokenCryptographer
from template_project.adapters.password_utils import ArgonPasswordHasher, ArgonPasswordVerifying
from template_project.web_api.configuration import AccessTokenConfiguration
class CryptographerProvider(Provider):
scope = Scope.APP
@provide
def argon_password_hasher(self) -> argon2.PasswordHasher:
return argon2.PasswordHasher()
@provide
def fernet(self, configuration: AccessTokenConfiguration) -> Fernet:
return Fernet(configuration.crypto_key)
access_token_cryptographer = provide(WithParents[FernetAccessTokenCryptographer])
password_utils = provide_all(
WithParents[ArgonPasswordHasher],
WithParents[ArgonPasswordVerifying],
)