Skip to content

Commit 7e253d5

Browse files
authored
docstring cleanup and class reference simplification (#52)
1 parent 5f9ea84 commit 7e253d5

File tree

30 files changed

+248
-279
lines changed

30 files changed

+248
-279
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_version():
6464
htmlhelp_basename = '%sdoc' % project
6565

6666
# Example configuration for intersphinx: refer to the Python standard library.
67-
intersphinx_mapping = {'http://docs.python.org/': None}
67+
intersphinx_mapping = {'python': ('http://docs.python.org/', None)}
6868

6969
# autosummary
7070
autosummary_generate = True

doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Modules
1212
dynamodb_encryption_sdk.exceptions
1313
dynamodb_encryption_sdk.identifiers
1414
dynamodb_encryption_sdk.structures
15+
dynamodb_encryption_sdk.transform
1516
dynamodb_encryption_sdk.delegated_keys
1617
dynamodb_encryption_sdk.delegated_keys.jce
1718
dynamodb_encryption_sdk.encrypted
@@ -44,7 +45,6 @@ Modules
4445
dynamodb_encryption_sdk.internal.crypto.jce_bridge.primitives
4546
dynamodb_encryption_sdk.internal.formatting
4647
dynamodb_encryption_sdk.internal.formatting.material_description
47-
dynamodb_encryption_sdk.internal.formatting.transform
4848
dynamodb_encryption_sdk.internal.formatting.deserialize
4949
dynamodb_encryption_sdk.internal.formatting.deserialize.attribute
5050
dynamodb_encryption_sdk.internal.formatting.serialize

src/dynamodb_encryption_sdk/delegated_keys/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
def _raise_not_implemented(method_name):
29-
"""Raises a standardized ``NotImplementedError`` to report that the specified method
29+
"""Raises a standardized :class:`NotImplementedError` to report that the specified method
3030
is not supported.
3131
3232
:raises NotImplementedError: when called
@@ -40,7 +40,7 @@ class DelegatedKey(object):
4040
and unwrap keys. Not all delegated keys implement all methods.
4141
4242
Unless overridden by a subclass, any method that a delegated key does not implement raises
43-
a ``NotImplementedError`` detailing this.
43+
a :class:`NotImplementedError` detailing this.
4444
"""
4545

4646
@abc.abstractproperty
@@ -51,7 +51,8 @@ def algorithm(self):
5151
@property
5252
def allowed_for_raw_materials(self):
5353
# type: () -> bool
54-
"""Most delegated keys should not be used with RawCryptographicMaterials.
54+
"""Most delegated keys should not be used with :class:`RawDecryptionMaterials` or
55+
:class:`RawEncryptionMaterials`.
5556
5657
:returns: False
5758
:rtype: bool
@@ -62,12 +63,12 @@ def allowed_for_raw_materials(self):
6263
def generate(cls, algorithm, key_length): # type: ignore
6364
# type: (Text, int) -> DelegatedKey
6465
# pylint: disable=unused-argument,no-self-use
65-
"""Generate an instance of this DelegatedKey using the specified algorithm and key length.
66+
"""Generate an instance of this :class:`DelegatedKey` using the specified algorithm and key length.
6667
6768
:param str algorithm: Text description of algorithm to be used
6869
:param int key_length: Size of key to generate
6970
:returns: Generated delegated key
70-
:rtype: dynamodb_encryption_sdk.delegated_keys.DelegatedKey
71+
:rtype: DelegatedKey
7172
"""
7273
_raise_not_implemented('generate')
7374

@@ -130,12 +131,11 @@ def unwrap( # type: ignore
130131
:param str algorithm: Text description of algorithm to use to unwrap key
131132
:param bytes content_key: Raw content key to wrap
132133
:param str wrapped_key_algorithm: Text description of algorithm for unwrapped key to use
133-
:param wrapped_key_type: Type of key to treat key as once unwrapped
134-
:type wrapped_key_type: dynamodb_encryption_sdk.identifiers.EncryptionKeyType
134+
:param EncryptionKeyType wrapped_key_type: Type of key to treat key as once unwrapped
135135
:param dict additional_associated_data: Not used by all delegated keys, but if it
136136
is, then if it is provided on wrap it must be required on unwrap.
137137
:returns: Delegated key using unwrapped key
138-
:rtype: dynamodb_encryption_sdk.delegated_keys.DelegatedKey
138+
:rtype: DelegatedKey
139139
"""
140140
_raise_not_implemented('unwrap')
141141

@@ -166,9 +166,9 @@ def signing_algorithm(self): # type: ignore
166166
# type: () -> Text
167167
# pylint: disable=no-self-use
168168
"""Provide a description that can inform an appropriate cryptographic materials
169-
provider about how to build a DelegatedKey for signature verification. If implemented,
170-
the return value of this method is included in the material description written to
171-
the encrypted item.
169+
provider about how to build a :class:`DelegatedKey` for signature verification.
170+
If implemented, the return value of this method is included in the material description
171+
written to the encrypted item.
172172
173173
:returns: Signing algorithm identifier
174174
:rtype: str

src/dynamodb_encryption_sdk/delegated_keys/jce.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _generate_symmetric_key(key_length):
4242
4343
:param int key_length: Required key length in bits
4444
:returns: raw key, symmetric key identifier, and RAW encoding identifier
45-
:rtype: tuple of bytes, EncryptionKeyType, and KeyEncodingType
45+
:rtype: tuple(bytes, :class:`EncryptionKeyType`, :class:`KeyEncodingType`)
4646
"""
4747
return os.urandom(key_length // 8), EncryptionKeyType.SYMMETRIC, KeyEncodingType.RAW
4848

@@ -52,7 +52,7 @@ def _generate_rsa_key(key_length):
5252
5353
:param int key_length: Required key length in bits
5454
:returns: DER-encoded private key, private key identifier, and DER encoding identifier
55-
:rtype: tuple of bytes, EncryptionKeyType, and KeyEncodingType
55+
:rtype: tuple(bytes, :class:`EncryptionKeyType`, :class:`KeyEncodingType`)
5656
"""
5757
private_key = rsa.generate_private_key(
5858
public_exponent=65537,
@@ -109,10 +109,8 @@ class JceNameLocalDelegatedKey(DelegatedKey):
109109
110110
:param bytes key: Raw key bytes
111111
:param str algorithm: JCE Standard Algorithm Name
112-
:param key_type: Identifies what type of key is being provided
113-
:type key_type: dynamodb_encryption_sdk.identifiers.EncryptionKeyType
114-
:param key_encoding: Identifies how the provided key is encoded
115-
:type key_encoding: dynamodb_encryption_sdk.identifiers.KeyEncodingTypes
112+
:param EncryptionKeyType key_type: Identifies what type of key is being provided
113+
:param KeyEncodingType key_encoding: Identifies how the provided key is encoded
116114
"""
117115

118116
key = attr.ib(validator=attr.validators.instance_of(bytes), repr=False)
@@ -204,12 +202,13 @@ def __attrs_post_init__(self):
204202
@classmethod
205203
def generate(cls, algorithm, key_length=None):
206204
# type: (Text, Optional[int]) -> JceNameLocalDelegatedKey
207-
"""Generate an instance of this DelegatedKey using the specified algorithm and key length.
205+
"""Generate an instance of this :class:`DelegatedKey` using the specified algorithm
206+
and key length.
208207
209208
:param str algorithm: Text description of algorithm to be used
210209
:param int key_length: Size in bits of key to generate
211210
:returns: Generated delegated key
212-
:rtype: dynamodb_encryption_sdk.delegated_keys.DelegatedKey
211+
:rtype: DelegatedKey
213212
"""
214213
# Normalize to allow generating both encryption and signing keys
215214
algorithm_lookup = algorithm.upper()
@@ -229,8 +228,8 @@ def generate(cls, algorithm, key_length=None):
229228
@property
230229
def allowed_for_raw_materials(self):
231230
# type: () -> bool
232-
"""Only ``JceNameLocalDelegatedKey`` backed by AES keys are allowed to be used with
233-
``RawCryptographicMaterials``.
231+
"""Only :class:`JceNameLocalDelegatedKey` backed by AES keys are allowed to be used
232+
with :class:`RawDecryptionMaterials` or :class:`RawEncryptionMaterials`.
234233
235234
:returns: decision
236235
:rtype: bool
@@ -264,7 +263,7 @@ def _decrypt(self, algorithm, name, ciphertext, additional_associated_data=None)
264263
https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html
265264
:param str name: Name associated with ciphertext data
266265
:param bytes ciphertext: Ciphertext data to decrypt
267-
:param dict additional_associated_data: Not used by ``JceNameLocalDelegatedKey``
266+
:param dict additional_associated_data: Not used by :class:`JceNameLocalDelegatedKey`
268267
:returns: Decrypted plaintext
269268
:rtype: bytes
270269
"""
@@ -278,7 +277,7 @@ def _wrap(self, algorithm, content_key, additional_associated_data=None):
278277
279278
:param str algorithm: Text description of algorithm to use to wrap key
280279
:param bytes content_key: Raw content key to wrap
281-
:param dict additional_associated_data: Not used by ``JceNameLocalDelegatedKey``
280+
:param dict additional_associated_data: Not used by :class:`JceNameLocalDelegatedKey`
282281
:returns: Wrapped key
283282
:rtype: bytes
284283
"""
@@ -296,11 +295,10 @@ def _unwrap(self, algorithm, wrapped_key, wrapped_key_algorithm, wrapped_key_typ
296295
:param str algorithm: Text description of algorithm to use to unwrap key
297296
:param bytes content_key: Raw content key to wrap
298297
:param str wrapped_key_algorithm: Text description of algorithm for unwrapped key to use
299-
:param wrapped_key_type: Type of key to treat key as once unwrapped
300-
:type wrapped_key_type: dynamodb_encryption_sdk.identifiers.EncryptionKeyType
301-
:param dict additional_associated_data: Not used by ``JceNameLocalDelegatedKey``
298+
:param EncryptionKeyType wrapped_key_type: Type of key to treat key as once unwrapped
299+
:param dict additional_associated_data: Not used by :class:`JceNameLocalDelegatedKey`
302300
:returns: Delegated key using unwrapped key
303-
:rtype: dynamodb_encryption_sdk.delegated_keys.DelegatedKey
301+
:rtype: DelegatedKey
304302
"""
305303
if wrapped_key_type is not EncryptionKeyType.SYMMETRIC:
306304
raise UnwrappingError('Unsupported wrapped key type: "{}"'.format(wrapped_key_type))

src/dynamodb_encryption_sdk/encrypted/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from dynamodb_encryption_sdk.exceptions import InvalidArgumentError
2525
from dynamodb_encryption_sdk.identifiers import CryptoAction
2626
from dynamodb_encryption_sdk.material_providers import CryptographicMaterialsProvider
27-
from dynamodb_encryption_sdk.materials import DecryptionMaterials, EncryptionMaterials # noqa pylint: disable=unused-import
27+
from dynamodb_encryption_sdk.materials import CryptographicMaterials # noqa pylint: disable=unused-import
2828
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext
2929

3030
__all__ = ('CryptoConfig',)
@@ -34,12 +34,12 @@
3434
class CryptoConfig(object):
3535
"""Container for all configuration needed to encrypt or decrypt an item.
3636
37-
:param materials_provider: Cryptographic materials provider to use
38-
:type materials_provider: dynamodb_encryption_sdk.material_providers.CryptographicMaterialsProvider
39-
:param encryption_context: Context data describing what is being encrypted or decrypted.
40-
:type encryption_context: dynamodb_encryption_sdk.structures.EncryptionContext
41-
:param attribute_actions: Description of what action should be taken for each attribute
42-
:type attribute_actions: dynamodb_encryption_sdk.structures.AttributeActions
37+
:param CryptographicMaterialsProvider materials_provider: Cryptographic materials provider
38+
to use
39+
:param EncryptionContext encryption_context: Context data describing what is being encrypted
40+
or decrypted
41+
:param AttributeActions attribute_actions: Description of what action should be taken
42+
for each attribute
4343
"""
4444

4545
materials_provider = attr.ib(validator=attr.validators.instance_of(CryptographicMaterialsProvider))
@@ -75,28 +75,28 @@ def __attrs_post_init__(self):
7575
raise InvalidArgumentError('Cannot encrypt sort key')
7676

7777
def decryption_materials(self):
78-
# type: () -> DecryptionMaterials
78+
# type: () -> CryptographicMaterials
7979
"""Load decryption materials from instance resources.
8080
8181
:returns: Decryption materials
82-
:rtype: dynamodb_encryption_sdk.materials.DecryptionMaterials
82+
:rtype: CryptographicMaterials
8383
"""
8484
return self.materials_provider.decryption_materials(self.encryption_context)
8585

8686
def encryption_materials(self):
87-
# type: () -> EncryptionMaterials
87+
# type: () -> CryptographicMaterials
8888
"""Load encryption materials from instance resources.
8989
9090
:returns: Encryption materials
91-
:rtype: dynamodb_encryption_sdk.materials.EncryptionMaterials
91+
:rtype: CryptographicMaterials
9292
"""
9393
return self.materials_provider.encryption_materials(self.encryption_context)
9494

9595
def copy(self):
9696
# type: () -> CryptoConfig
9797
"""Return a copy of this instance with a copied instance of its encryption context.
9898
99-
:returns: New CryptoConfig identical to this one
99+
:returns: New :class:`CryptoConfig` identical to this one
100100
:rtype: CryptoConfig
101101
"""
102102
return CryptoConfig(

src/dynamodb_encryption_sdk/encrypted/client.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from dynamodb_encryption_sdk.structures import AttributeActions
3434
from .item import decrypt_dynamodb_item, decrypt_python_item, encrypt_dynamodb_item, encrypt_python_item
3535

36-
__all__ = ('EncryptedClient',)
36+
__all__ = ('EncryptedClient', 'EncryptedPaginator')
3737

3838

3939
@attr.s(init=False)
@@ -42,8 +42,8 @@ class EncryptedPaginator(object):
4242
4343
:param paginator: Pre-configured boto3 DynamoDB paginator object
4444
:type paginator: botocore.paginate.Paginator
45-
:param decrypt_method: Item decryptor method from ``dynamodb_encryption_sdk.encrypted.item``
46-
:param callable crypto_config_method: Callable that returns a crypto config
45+
:param decrypt_method: Item decryptor method from :mod:`dynamodb_encryption_sdk.encrypted.item`
46+
:param callable crypto_config_method: Callable that returns a :class:`CryptoConfig`
4747
"""
4848

4949
_paginator = attr.ib(validator=attr.validators.instance_of(botocore.paginate.Paginator))
@@ -130,7 +130,7 @@ class EncryptedClient(object):
130130
131131
If you want to provide per-request cryptographic details, the ``put_item``, ``get_item``,
132132
``query``, ``scan``, ``batch_write_item``, and ``batch_get_item`` methods will also
133-
accept a ``crypto_config`` parameter, defining a custom ``CryptoConfig`` instance
133+
accept a ``crypto_config`` parameter, defining a custom :class:`CryptoConfig` instance
134134
for this request.
135135
136136
.. warning::
@@ -139,10 +139,10 @@ class EncryptedClient(object):
139139
140140
:param table: Pre-configured boto3 DynamoDB client object
141141
:type table: boto3.resources.base.BaseClient
142-
:param materials_provider: Cryptographic materials provider to use
143-
:type materials_provider: dynamodb_encryption_sdk.material_providers.CryptographicMaterialsProvider
144-
:param attribute_actions: Table-level configuration of how to encrypt/sign attributes
145-
:type attribute_actions: dynamodb_encryption_sdk.structures.AttributeActions
142+
:param CryptographicMaterialsProvider materials_provider: Cryptographic materials provider
143+
to use
144+
:param AttributeActions attribute_actions: Table-level configuration of how to encrypt/sign
145+
attributes
146146
:param bool auto_refresh_table_indexes: Should we attempt to refresh information about table indexes?
147147
Requires ``dynamodb:DescribeTable`` permissions on each table. (default: True)
148148
:param bool expect_standard_dictionaries: Should we expect items to be standard Python
@@ -259,7 +259,10 @@ def __getattr__(self, name):
259259
return getattr(self._client, name)
260260

261261
def update_item(self, **kwargs):
262-
"""Update item is not yet supported."""
262+
"""Update item is not yet supported.
263+
264+
:raises NotImplementedError: if called
265+
"""
263266
raise NotImplementedError('"update_item" is not yet implemented')
264267

265268
def get_paginator(self, operation_name):
@@ -268,7 +271,7 @@ def get_paginator(self, operation_name):
268271
269272
:param str operation_name: Name of operation for which to get paginator
270273
:returns: Paginator for name
271-
:rtype: Paginator or EncryptedPaginator
274+
:rtype: :class:`botocore.paginate.Paginator` or :class:`EncryptedPaginator`
272275
"""
273276
paginator = self._client.get_paginator(operation_name)
274277

src/dynamodb_encryption_sdk/encrypted/item.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def encrypt_dynamodb_item(item, crypto_config):
4242
This handles DynamoDB-formatted items and is for use with the boto3 DynamoDB client.
4343
4444
:param dict item: Plaintext DynamoDB item
45-
:param crypto_config: Cryptographic configuration
46-
:type crypto_config: dynamodb_encryption_sdk.encrypted.CryptoConfig
45+
:param CryptoConfig crypto_config: Cryptographic configuration
4746
:returns: Encrypted and signed DynamoDB item
4847
:rtype: dict
4948
"""
@@ -118,8 +117,7 @@ def encrypt_python_item(item, crypto_config):
118117
This handles human-friendly dictionaries and is for use with the boto3 DynamoDB service or table resource.
119118
120119
:param dict item: Plaintext dictionary
121-
:param crypto_config: Cryptographic configuration
122-
:type crypto_config: dynamodb_encryption_sdk.encrypted.CryptoConfig
120+
:param CryptoConfig crypto_config: Cryptographic configuration
123121
:returns: Encrypted and signed dictionary
124122
:rtype: dict
125123
"""
@@ -137,8 +135,7 @@ def decrypt_dynamodb_item(item, crypto_config):
137135
This handles DynamoDB-formatted items and is for use with the boto3 DynamoDB client.
138136
139137
:param dict item: Encrypted and signed DynamoDB item
140-
:param crypto_config: Cryptographic configuration
141-
:type crypto_config: dynamodb_encryption_sdk.encrypted.CryptoConfig
138+
:param CryptoConfig crypto_config: Cryptographic configuration
142139
:returns: Plaintext DynamoDB item
143140
:rtype: dict
144141
"""
@@ -212,8 +209,7 @@ def decrypt_python_item(item, crypto_config):
212209
This handles human-friendly dictionaries and is for use with the boto3 DynamoDB service or table resource.
213210
214211
:param dict item: Encrypted and signed dictionary
215-
:param crypto_config: Cryptographic configuration
216-
:type crypto_config: dynamodb_encryption_sdk.encrypted.CryptoConfig
212+
:param CryptoConfig crypto_config: Cryptographic configuration
217213
:returns: Plaintext dictionary
218214
:rtype: dict
219215
"""

0 commit comments

Comments
 (0)