Skip to content

Commit 0c75418

Browse files
authored
Merge pull request #733 from ably/feature/export-crypto-helpers
Export generate_random_key and get_default_params from ably.pubsub.server
2 parents 4a869cf + d23c98c commit 0c75418

5 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎UPDATING.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ Where 3.x left you reaching into submodules such as `ably.types.message` or
4949
the whole public API, and `ably.pubsub.server.sync` is its synchronous
5050
counterpart. The packages beneath them are internal and free to move.
5151

52+
For example, the encryption helpers move from `ably.util.crypto`:
53+
54+
Example 3.x code:
55+
```python
56+
from ably.util.crypto import generate_random_key, get_default_params
57+
```
58+
59+
Example 4.0.0 code:
60+
```python
61+
from ably.pubsub.server import generate_random_key, get_default_params
62+
```
63+
5264
### Clients are built by factories
5365

5466
`AblyRest` and `AblyRealtime` are internal in 4.0.0 and raise `TypeError` if

‎ably/pubsub/server/__init__.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from ably.pubsub.types.options import Options, VCDiffDecoder
3939
from ably.pubsub.types.tokendetails import TokenDetails
4040
from ably.pubsub.util.construction import factory_construction
41-
from ably.pubsub.util.crypto import CipherParams
41+
from ably.pubsub.util.crypto import CipherParams, generate_random_key, get_default_params
4242
from ably.pubsub.util.exceptions import AblyAuthException, AblyException, IncompatibleClientIdException
4343
from ably.pubsub.vcdiff.defaultvcdiffdecoder import AblyVCDiffDecoder
4444
from ably.pubsub.version import api_version, lib_version
@@ -275,5 +275,7 @@ def create_realtime_client(**kwargs) -> PubSubRealtimeClient:
275275
'api_version',
276276
'create_http_client',
277277
'create_realtime_client',
278+
'generate_random_key',
279+
'get_default_params',
278280
'lib_version',
279281
]

‎ably/pubsub/server/sync.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ably.pubsub.sync.types.options import Options, VCDiffDecoder
2525
from ably.pubsub.sync.types.tokendetails import TokenDetails
2626
from ably.pubsub.sync.util.construction import factory_construction
27-
from ably.pubsub.sync.util.crypto import CipherParams
27+
from ably.pubsub.sync.util.crypto import CipherParams, generate_random_key, get_default_params
2828
from ably.pubsub.sync.util.exceptions import AblyAuthException, AblyException, IncompatibleClientIdException
2929
from ably.pubsub.sync.vcdiff.defaultvcdiffdecoder import AblyVCDiffDecoder
3030
from ably.pubsub.version import api_version, lib_version
@@ -84,5 +84,7 @@ def create_http_client(**kwargs) -> PubSubHttpClient:
8484
'VCDiffDecoder',
8585
'api_version',
8686
'create_http_client',
87+
'generate_random_key',
88+
'get_default_params',
8789
'lib_version',
8890
]

‎ably/pubsub/util/nocrypto.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class InstallPycrypto:
33
def __getattr__(self, name):
44
raise ImportError(
5-
"This requires to install ably with crypto support: pip install 'ably[crypto]'"
5+
"This requires ably-pubsub-server with crypto support: pip install 'ably-pubsub-server[crypto]'"
66
)
77

88

‎test/unit/pubsub_server_test.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,9 @@ class TestPublicTypes:
161161
def test_message_is_exported(self):
162162
assert 'Message' in server.__all__
163163
assert 'Message' in server_sync.__all__
164+
165+
# RSE2: channel encryption needs a public way to generate a key and build cipher params
166+
@pytest.mark.parametrize('name', ['generate_random_key', 'get_default_params'])
167+
def test_crypto_helpers_are_exported(self, name):
168+
assert name in server.__all__
169+
assert name in server_sync.__all__

0 commit comments

Comments
 (0)