Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "chat-sdk"
version = "0.0.1a1"
version = "0.0.1a2"
description = "Multi-platform async chat SDK for Python — port of Vercel Chat"
readme = "README.md"
license = {text = "MIT"}
Expand Down
6 changes: 4 additions & 2 deletions src/chat_sdk/adapters/slack/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from dataclasses import dataclass
from typing import Any

from cryptography.hazmat.primitives.ciphers.aead import AESGCM

ALGORITHM = "aes-256-gcm"
IV_LENGTH = 12
AUTH_TAG_LENGTH = 16
Expand Down Expand Up @@ -39,6 +37,8 @@ def encrypt_token(plaintext: str, key: bytes) -> EncryptedTokenData:
"""
import base64

from cryptography.hazmat.primitives.ciphers.aead import AESGCM
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When handling optional dependencies like cryptography, it is a best practice to provide a descriptive error message that guides the user on how to resolve the missing dependency (e.g., by installing the crypto extra).

Suggested change
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
try:
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
except ImportError:
raise ImportError(
"The 'cryptography' package is required for Slack token encryption. "
"Install it with 'pip install chat-sdk[crypto]'."
) from None


iv = os.urandom(IV_LENGTH)
aesgcm = AESGCM(key)
# AESGCM.encrypt returns ciphertext + tag concatenated
Expand Down Expand Up @@ -66,6 +66,8 @@ def decrypt_token(encrypted: EncryptedTokenData, key: bytes) -> str:
"""
import base64

from cryptography.hazmat.primitives.ciphers.aead import AESGCM
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Providing a clear error message here, similar to encrypt_token, ensures that users are informed about the missing optional dependency when attempting to decrypt tokens.

Suggested change
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
try:
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
except ImportError:
raise ImportError(
"The 'cryptography' package is required for Slack token decryption. "
"Install it with 'pip install chat-sdk[crypto]'."
) from None


iv = base64.b64decode(encrypted.iv)
ciphertext = base64.b64decode(encrypted.data)
tag = base64.b64decode(encrypted.tag)
Expand Down
Loading