Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomognosis committed Jun 3, 2024
1 parent 8de38cf commit 0071352
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/api/services/csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def generate_token(self, timestamp=None):
data_to_encrypt = '%s%s%f' % (request_id, self._salt, timestamp)

cipher_rsa = PKCS1_OAEP.new(self._pubkey)
# Data_to_encrypt can be of variable length, but not longer than
# the RSA modulus (in bytes) minus 2, minus twice the hash output size.
# For instance, if you use RSA 2048 and SHA-256, the longest
# message you can encrypt is 190 byte long.
token = cipher_rsa.encrypt(data_to_encrypt.encode())

return CSRFTokenItem(request_id, token.hex(), timestamp)
Expand Down

0 comments on commit 0071352

Please sign in to comment.